7 class ClockClassOffsetTestCase(unittest
.TestCase
):
8 def test_create_default(self
):
9 cco
= bt2
.ClockClassOffset()
10 self
.assertEqual(cco
.seconds
, 0)
11 self
.assertEqual(cco
.cycles
, 0)
13 def test_create(self
):
14 cco
= bt2
.ClockClassOffset(23, 4871232)
15 self
.assertEqual(cco
.seconds
, 23)
16 self
.assertEqual(cco
.cycles
, 4871232)
18 def test_create_kwargs(self
):
19 cco
= bt2
.ClockClassOffset(seconds
=23, cycles
=4871232)
20 self
.assertEqual(cco
.seconds
, 23)
21 self
.assertEqual(cco
.cycles
, 4871232)
23 def test_create_invalid_seconds(self
):
24 with self
.assertRaises(TypeError):
25 bt2
.ClockClassOffset('hello', 4871232)
27 def test_create_invalid_cycles(self
):
28 with self
.assertRaises(TypeError):
29 bt2
.ClockClassOffset(23, 'hello')
32 cco1
= bt2
.ClockClassOffset(23, 42)
33 cco2
= bt2
.ClockClassOffset(23, 42)
34 self
.assertEqual(cco1
, cco2
)
36 def test_ne_seconds(self
):
37 cco1
= bt2
.ClockClassOffset(23, 42)
38 cco2
= bt2
.ClockClassOffset(24, 42)
39 self
.assertNotEqual(cco1
, cco2
)
41 def test_ne_cycles(self
):
42 cco1
= bt2
.ClockClassOffset(23, 42)
43 cco2
= bt2
.ClockClassOffset(23, 43)
44 self
.assertNotEqual(cco1
, cco2
)
46 def test_eq_invalid(self
):
47 self
.assertFalse(bt2
.ClockClassOffset() == 23)
50 class ClockClassTestCase(unittest
.TestCase
):
52 self
._cc
= bt2
.ClockClass('salut')
54 def test_create_default(self
):
55 self
.assertEqual(self
._cc
.name
, 'salut')
57 def test_create_invalid_no_name(self
):
58 with self
.assertRaises(TypeError):
61 def test_create_full(self
):
62 my_uuid
= uuid
.uuid1()
63 cc
= bt2
.ClockClass(name
='name', description
='some description',
64 frequency
=1001, precision
=176,
65 offset
=bt2
.ClockClassOffset(45, 3003),
66 is_absolute
=True, uuid
=my_uuid
)
67 self
.assertEqual(cc
.name
, 'name')
68 self
.assertEqual(cc
.description
, 'some description')
69 self
.assertEqual(cc
.frequency
, 1001)
70 self
.assertEqual(cc
.precision
, 176)
71 self
.assertEqual(cc
.offset
, bt2
.ClockClassOffset(45, 3003))
72 self
.assertEqual(cc
.is_absolute
, True)
73 self
.assertEqual(cc
.uuid
, copy
.deepcopy(my_uuid
))
75 def test_assign_name(self
):
76 self
._cc
.name
= 'the_clock'
77 self
.assertEqual(self
._cc
.name
, 'the_clock')
79 def test_assign_invalid_name(self
):
80 with self
.assertRaises(TypeError):
83 def test_assign_description(self
):
84 self
._cc
.description
= 'hi people'
85 self
.assertEqual(self
._cc
.description
, 'hi people')
87 def test_assign_invalid_description(self
):
88 with self
.assertRaises(TypeError):
89 self
._cc
.description
= 23
91 def test_assign_frequency(self
):
92 self
._cc
.frequency
= 987654321
93 self
.assertEqual(self
._cc
.frequency
, 987654321)
95 def test_assign_invalid_frequency(self
):
96 with self
.assertRaises(TypeError):
97 self
._cc
.frequency
= 'lel'
99 def test_assign_precision(self
):
100 self
._cc
.precision
= 12
101 self
.assertEqual(self
._cc
.precision
, 12)
103 def test_assign_invalid_precision(self
):
104 with self
.assertRaises(TypeError):
105 self
._cc
.precision
= 'lel'
107 def test_assign_offset(self
):
108 self
._cc
.offset
= bt2
.ClockClassOffset(12, 56)
109 self
.assertEqual(self
._cc
.offset
, bt2
.ClockClassOffset(12, 56))
111 def test_assign_invalid_offset(self
):
112 with self
.assertRaises(TypeError):
113 self
._cc
.offset
= object()
115 def test_assign_absolute(self
):
116 self
._cc
.is_absolute
= True
117 self
.assertTrue(self
._cc
.is_absolute
)
119 def test_assign_invalid_absolute(self
):
120 with self
.assertRaises(TypeError):
121 self
._cc
.is_absolute
= 23
123 def test_assign_uuid(self
):
124 the_uuid
= uuid
.uuid1()
125 self
._cc
.uuid
= the_uuid
126 self
.assertEqual(self
._cc
.uuid
, the_uuid
)
128 def test_assign_invalid_uuid(self
):
129 with self
.assertRaises(TypeError):
130 self
._cc
.uuid
= object()
132 def test_create_clock_value(self
):
133 cv
= self
._cc
.create_clock_value(756)
134 self
.assertEqual(cv
.clock_class
.addr
, self
._cc
.addr
)
136 def _test_copy(self
, cpy
):
137 self
.assertIsNot(cpy
, self
._cc
)
138 self
.assertNotEqual(cpy
.addr
, self
._cc
.addr
)
139 self
.assertEqual(cpy
, self
._cc
)
142 cpy
= copy
.copy(self
._cc
)
145 def test_deepcopy(self
):
146 cpy
= copy
.deepcopy(self
._cc
)
150 my_uuid
= uuid
.uuid1()
151 cc1
= bt2
.ClockClass(name
='name', description
='some description',
152 frequency
=1001, precision
=176,
153 offset
=bt2
.ClockClassOffset(45, 3003),
154 is_absolute
=True, uuid
=my_uuid
)
155 cc2
= bt2
.ClockClass(name
='name', description
='some description',
156 frequency
=1001, precision
=176,
157 offset
=bt2
.ClockClassOffset(45, 3003),
158 is_absolute
=True, uuid
=my_uuid
)
159 self
.assertEqual(cc1
, cc2
)
161 def test_ne_name(self
):
162 my_uuid
= uuid
.uuid1()
163 cc1
= bt2
.ClockClass(name
='mane', description
='some description',
164 frequency
=1001, precision
=176,
165 offset
=bt2
.ClockClassOffset(45, 3003),
166 is_absolute
=True, uuid
=my_uuid
)
167 cc2
= bt2
.ClockClass(name
='name', description
='some description',
168 frequency
=1001, precision
=176,
169 offset
=bt2
.ClockClassOffset(45, 3003),
170 is_absolute
=True, uuid
=my_uuid
)
171 self
.assertNotEqual(cc1
, cc2
)
173 def test_ne_description(self
):
174 my_uuid
= uuid
.uuid1()
175 cc1
= bt2
.ClockClass(name
='name', description
='some descripti2',
176 frequency
=1001, precision
=176,
177 offset
=bt2
.ClockClassOffset(45, 3003),
178 is_absolute
=True, uuid
=my_uuid
)
179 cc2
= bt2
.ClockClass(name
='name', description
='some description',
180 frequency
=1001, precision
=176,
181 offset
=bt2
.ClockClassOffset(45, 3003),
182 is_absolute
=True, uuid
=my_uuid
)
183 self
.assertNotEqual(cc1
, cc2
)
185 def test_ne_frequency(self
):
186 my_uuid
= uuid
.uuid1()
187 cc1
= bt2
.ClockClass(name
='name', description
='some description',
188 frequency
=1003, precision
=176,
189 offset
=bt2
.ClockClassOffset(45, 3003),
190 is_absolute
=True, uuid
=my_uuid
)
191 cc2
= bt2
.ClockClass(name
='name', description
='some description',
192 frequency
=1001, precision
=176,
193 offset
=bt2
.ClockClassOffset(45, 3003),
194 is_absolute
=True, uuid
=my_uuid
)
195 self
.assertNotEqual(cc1
, cc2
)
197 def test_ne_precision(self
):
198 my_uuid
= uuid
.uuid1()
199 cc1
= bt2
.ClockClass(name
='name', description
='some description',
200 frequency
=1001, precision
=171,
201 offset
=bt2
.ClockClassOffset(45, 3003),
202 is_absolute
=True, uuid
=my_uuid
)
203 cc2
= bt2
.ClockClass(name
='name', description
='some description',
204 frequency
=1001, precision
=176,
205 offset
=bt2
.ClockClassOffset(45, 3003),
206 is_absolute
=True, uuid
=my_uuid
)
207 self
.assertNotEqual(cc1
, cc2
)
209 def test_ne_offset(self
):
210 my_uuid
= uuid
.uuid1()
211 cc1
= bt2
.ClockClass(name
='name', description
='some description',
212 frequency
=1001, precision
=176,
213 offset
=bt2
.ClockClassOffset(45, 3001),
214 is_absolute
=True, uuid
=my_uuid
)
215 cc2
= bt2
.ClockClass(name
='name', description
='some description',
216 frequency
=1001, precision
=176,
217 offset
=bt2
.ClockClassOffset(45, 3003),
218 is_absolute
=True, uuid
=my_uuid
)
219 self
.assertNotEqual(cc1
, cc2
)
221 def test_ne_absolute(self
):
222 my_uuid
= uuid
.uuid1()
223 cc1
= bt2
.ClockClass(name
='name', description
='some description',
224 frequency
=1001, precision
=176,
225 offset
=bt2
.ClockClassOffset(45, 3003),
226 is_absolute
=True, uuid
=my_uuid
)
227 cc2
= bt2
.ClockClass(name
='name', description
='some description',
228 frequency
=1001, precision
=176,
229 offset
=bt2
.ClockClassOffset(45, 3003),
230 is_absolute
=False, uuid
=my_uuid
)
231 self
.assertNotEqual(cc1
, cc2
)
233 def test_ne_uuid(self
):
234 cc1
= bt2
.ClockClass(name
='name', description
='some description',
235 frequency
=1001, precision
=176,
236 offset
=bt2
.ClockClassOffset(45, 3003),
237 is_absolute
=True, uuid
=uuid
.uuid1())
238 cc2
= bt2
.ClockClass(name
='name', description
='some description',
239 frequency
=1001, precision
=176,
240 offset
=bt2
.ClockClassOffset(45, 3003),
241 is_absolute
=True, uuid
=uuid
.uuid1())
242 self
.assertNotEqual(cc1
, cc2
)
244 def test_eq_invalid(self
):
245 self
.assertFalse(self
._cc
== 23)
248 class ClockClassValueTestCase(unittest
.TestCase
):
250 self
._cc
= bt2
.ClockClass('salut')
251 self
._cv
= self
._cc
.create_clock_value(123)
253 def test_create_default(self
):
254 self
.assertEqual(self
._cv
.clock_class
.addr
, self
._cc
.addr
)
255 self
.assertEqual(self
._cv
.cycles
, 123)
257 def test_create_invalid_cycles_type(self
):
258 with self
.assertRaises(TypeError):
259 self
._cc
.create_clock_value('yes')
261 def test_ns_from_epoch(self
):
262 self
._cv
.clock_class
.frequency
= 1000
263 self
._cv
.clock_class
.offset
= bt2
.ClockClassOffset(45, 354)
264 s_from_epoch
= 45 + ((354 + 123) / 1000)
265 ns_from_epoch
= int(s_from_epoch
* 1e9
)
266 self
.assertEqual(self
._cv
.ns_from_epoch
, ns_from_epoch
)
269 cv1
= self
._cc
.create_clock_value(123)
270 cv2
= self
._cc
.create_clock_value(123)
271 self
.assertEqual(cv1
, cv2
)
273 def test_ne_clock_class(self
):
274 cc1
= bt2
.ClockClass('yes')
275 cc2
= bt2
.ClockClass('yes')
276 cv1
= cc1
.create_clock_value(123)
277 cv2
= cc2
.create_clock_value(123)
278 self
.assertNotEqual(cv1
, cv2
)
280 def test_ne_cycles(self
):
281 cv1
= self
._cc
.create_clock_value(123)
282 cv2
= self
._cc
.create_clock_value(125)
283 self
.assertNotEqual(cv1
, cv2
)
285 def test_eq_invalid(self
):
286 self
.assertFalse(self
._cv
== 23)
288 def _test_copy(self
, cpy
):
289 self
.assertIsNot(cpy
, self
._cv
)
290 self
.assertNotEqual(cpy
.addr
, self
._cv
.addr
)
291 self
.assertEqual(cpy
, self
._cv
)
294 cpy
= copy
.copy(self
._cv
)
297 def test_deepcopy(self
):
298 cpy
= copy
.deepcopy(self
._cv
)
This page took 0.037052 seconds and 4 git commands to generate.