bt2: Adapt test_event.py and make it pass
[babeltrace.git] / tests / bindings / python / bt2 / test_clock_class.py
CommitLineData
9cf643d1
PP
1import unittest
2import uuid
3import copy
4import bt2
5
6
976c241d 7@unittest.skip("this is broken")
9cf643d1
PP
8class ClockClassOffsetTestCase(unittest.TestCase):
9 def test_create_default(self):
10 cco = bt2.ClockClassOffset()
11 self.assertEqual(cco.seconds, 0)
12 self.assertEqual(cco.cycles, 0)
13
14 def test_create(self):
15 cco = bt2.ClockClassOffset(23, 4871232)
16 self.assertEqual(cco.seconds, 23)
17 self.assertEqual(cco.cycles, 4871232)
18
19 def test_create_kwargs(self):
20 cco = bt2.ClockClassOffset(seconds=23, cycles=4871232)
21 self.assertEqual(cco.seconds, 23)
22 self.assertEqual(cco.cycles, 4871232)
23
24 def test_create_invalid_seconds(self):
25 with self.assertRaises(TypeError):
26 bt2.ClockClassOffset('hello', 4871232)
27
28 def test_create_invalid_cycles(self):
29 with self.assertRaises(TypeError):
30 bt2.ClockClassOffset(23, 'hello')
31
32 def test_eq(self):
33 cco1 = bt2.ClockClassOffset(23, 42)
34 cco2 = bt2.ClockClassOffset(23, 42)
35 self.assertEqual(cco1, cco2)
36
37 def test_ne_seconds(self):
38 cco1 = bt2.ClockClassOffset(23, 42)
39 cco2 = bt2.ClockClassOffset(24, 42)
40 self.assertNotEqual(cco1, cco2)
41
42 def test_ne_cycles(self):
43 cco1 = bt2.ClockClassOffset(23, 42)
44 cco2 = bt2.ClockClassOffset(23, 43)
45 self.assertNotEqual(cco1, cco2)
46
47 def test_eq_invalid(self):
48 self.assertFalse(bt2.ClockClassOffset() == 23)
49
50
976c241d 51@unittest.skip("this is broken")
9cf643d1
PP
52class ClockClassTestCase(unittest.TestCase):
53 def setUp(self):
811644b8
PP
54 self._cc = bt2.ClockClass('salut', 1000000)
55
56 def tearDown(self):
57 del self._cc
9cf643d1
PP
58
59 def test_create_default(self):
60 self.assertEqual(self._cc.name, 'salut')
61
62 def test_create_invalid_no_name(self):
63 with self.assertRaises(TypeError):
64 bt2.ClockClass()
65
66 def test_create_full(self):
67 my_uuid = uuid.uuid1()
68 cc = bt2.ClockClass(name='name', description='some description',
69 frequency=1001, precision=176,
70 offset=bt2.ClockClassOffset(45, 3003),
71 is_absolute=True, uuid=my_uuid)
72 self.assertEqual(cc.name, 'name')
73 self.assertEqual(cc.description, 'some description')
74 self.assertEqual(cc.frequency, 1001)
75 self.assertEqual(cc.precision, 176)
76 self.assertEqual(cc.offset, bt2.ClockClassOffset(45, 3003))
77 self.assertEqual(cc.is_absolute, True)
78 self.assertEqual(cc.uuid, copy.deepcopy(my_uuid))
79
80 def test_assign_name(self):
81 self._cc.name = 'the_clock'
82 self.assertEqual(self._cc.name, 'the_clock')
83
84 def test_assign_invalid_name(self):
85 with self.assertRaises(TypeError):
86 self._cc.name = 23
87
88 def test_assign_description(self):
89 self._cc.description = 'hi people'
90 self.assertEqual(self._cc.description, 'hi people')
91
92 def test_assign_invalid_description(self):
93 with self.assertRaises(TypeError):
94 self._cc.description = 23
95
96 def test_assign_frequency(self):
97 self._cc.frequency = 987654321
98 self.assertEqual(self._cc.frequency, 987654321)
99
100 def test_assign_invalid_frequency(self):
101 with self.assertRaises(TypeError):
102 self._cc.frequency = 'lel'
103
104 def test_assign_precision(self):
105 self._cc.precision = 12
106 self.assertEqual(self._cc.precision, 12)
107
108 def test_assign_invalid_precision(self):
109 with self.assertRaises(TypeError):
110 self._cc.precision = 'lel'
111
112 def test_assign_offset(self):
113 self._cc.offset = bt2.ClockClassOffset(12, 56)
114 self.assertEqual(self._cc.offset, bt2.ClockClassOffset(12, 56))
115
116 def test_assign_invalid_offset(self):
117 with self.assertRaises(TypeError):
118 self._cc.offset = object()
119
120 def test_assign_absolute(self):
121 self._cc.is_absolute = True
122 self.assertTrue(self._cc.is_absolute)
123
124 def test_assign_invalid_absolute(self):
125 with self.assertRaises(TypeError):
126 self._cc.is_absolute = 23
127
128 def test_assign_uuid(self):
129 the_uuid = uuid.uuid1()
130 self._cc.uuid = the_uuid
131 self.assertEqual(self._cc.uuid, the_uuid)
132
133 def test_assign_invalid_uuid(self):
134 with self.assertRaises(TypeError):
135 self._cc.uuid = object()
136
4b552f8b
SM
137 def test_create_clock_snapshot(self):
138 cs = self._cc(756)
139 self.assertEqual(cs.clock_class.addr, self._cc.addr)
9cf643d1
PP
140
141 def _test_copy(self, cpy):
142 self.assertIsNot(cpy, self._cc)
143 self.assertNotEqual(cpy.addr, self._cc.addr)
144 self.assertEqual(cpy, self._cc)
145
146 def test_copy(self):
147 cpy = copy.copy(self._cc)
148 self._test_copy(cpy)
149
150 def test_deepcopy(self):
151 cpy = copy.deepcopy(self._cc)
152 self._test_copy(cpy)
153
154 def test_eq(self):
155 my_uuid = uuid.uuid1()
156 cc1 = bt2.ClockClass(name='name', description='some description',
157 frequency=1001, precision=176,
158 offset=bt2.ClockClassOffset(45, 3003),
159 is_absolute=True, uuid=my_uuid)
160 cc2 = bt2.ClockClass(name='name', description='some description',
161 frequency=1001, precision=176,
162 offset=bt2.ClockClassOffset(45, 3003),
163 is_absolute=True, uuid=my_uuid)
164 self.assertEqual(cc1, cc2)
165
166 def test_ne_name(self):
167 my_uuid = uuid.uuid1()
168 cc1 = bt2.ClockClass(name='mane', description='some description',
169 frequency=1001, precision=176,
170 offset=bt2.ClockClassOffset(45, 3003),
171 is_absolute=True, uuid=my_uuid)
172 cc2 = bt2.ClockClass(name='name', description='some description',
173 frequency=1001, precision=176,
174 offset=bt2.ClockClassOffset(45, 3003),
175 is_absolute=True, uuid=my_uuid)
176 self.assertNotEqual(cc1, cc2)
177
178 def test_ne_description(self):
179 my_uuid = uuid.uuid1()
180 cc1 = bt2.ClockClass(name='name', description='some descripti2',
181 frequency=1001, precision=176,
182 offset=bt2.ClockClassOffset(45, 3003),
183 is_absolute=True, uuid=my_uuid)
184 cc2 = bt2.ClockClass(name='name', description='some description',
185 frequency=1001, precision=176,
186 offset=bt2.ClockClassOffset(45, 3003),
187 is_absolute=True, uuid=my_uuid)
188 self.assertNotEqual(cc1, cc2)
189
190 def test_ne_frequency(self):
191 my_uuid = uuid.uuid1()
192 cc1 = bt2.ClockClass(name='name', description='some description',
193 frequency=1003, precision=176,
194 offset=bt2.ClockClassOffset(45, 3003),
195 is_absolute=True, uuid=my_uuid)
196 cc2 = bt2.ClockClass(name='name', description='some description',
197 frequency=1001, precision=176,
198 offset=bt2.ClockClassOffset(45, 3003),
199 is_absolute=True, uuid=my_uuid)
200 self.assertNotEqual(cc1, cc2)
201
202 def test_ne_precision(self):
203 my_uuid = uuid.uuid1()
204 cc1 = bt2.ClockClass(name='name', description='some description',
205 frequency=1001, precision=171,
206 offset=bt2.ClockClassOffset(45, 3003),
207 is_absolute=True, uuid=my_uuid)
208 cc2 = bt2.ClockClass(name='name', description='some description',
209 frequency=1001, precision=176,
210 offset=bt2.ClockClassOffset(45, 3003),
211 is_absolute=True, uuid=my_uuid)
212 self.assertNotEqual(cc1, cc2)
213
214 def test_ne_offset(self):
215 my_uuid = uuid.uuid1()
216 cc1 = bt2.ClockClass(name='name', description='some description',
217 frequency=1001, precision=176,
218 offset=bt2.ClockClassOffset(45, 3001),
219 is_absolute=True, uuid=my_uuid)
220 cc2 = bt2.ClockClass(name='name', description='some description',
221 frequency=1001, precision=176,
222 offset=bt2.ClockClassOffset(45, 3003),
223 is_absolute=True, uuid=my_uuid)
224 self.assertNotEqual(cc1, cc2)
225
226 def test_ne_absolute(self):
227 my_uuid = uuid.uuid1()
228 cc1 = bt2.ClockClass(name='name', description='some description',
229 frequency=1001, precision=176,
230 offset=bt2.ClockClassOffset(45, 3003),
231 is_absolute=True, uuid=my_uuid)
232 cc2 = bt2.ClockClass(name='name', description='some description',
233 frequency=1001, precision=176,
234 offset=bt2.ClockClassOffset(45, 3003),
235 is_absolute=False, uuid=my_uuid)
236 self.assertNotEqual(cc1, cc2)
237
238 def test_ne_uuid(self):
239 cc1 = bt2.ClockClass(name='name', description='some description',
240 frequency=1001, precision=176,
241 offset=bt2.ClockClassOffset(45, 3003),
242 is_absolute=True, uuid=uuid.uuid1())
243 cc2 = bt2.ClockClass(name='name', description='some description',
244 frequency=1001, precision=176,
245 offset=bt2.ClockClassOffset(45, 3003),
246 is_absolute=True, uuid=uuid.uuid1())
247 self.assertNotEqual(cc1, cc2)
248
249 def test_eq_invalid(self):
250 self.assertFalse(self._cc == 23)
251
252
976c241d 253@unittest.skip("this is broken")
4b552f8b 254class ClockSnapshotTestCase(unittest.TestCase):
9cf643d1 255 def setUp(self):
811644b8
PP
256 self._cc = bt2.ClockClass('salut', 1000,
257 offset=bt2.ClockClassOffset(45, 354))
4b552f8b 258 self._cs = self._cc(123)
811644b8
PP
259
260 def tearDown(self):
261 del self._cc
4b552f8b 262 del self._cs
9cf643d1
PP
263
264 def test_create_default(self):
4b552f8b
SM
265 self.assertEqual(self._cs.clock_class.addr, self._cc.addr)
266 self.assertEqual(self._cs.cycles, 123)
9cf643d1
PP
267
268 def test_create_invalid_cycles_type(self):
269 with self.assertRaises(TypeError):
811644b8 270 self._cc('yes')
9cf643d1
PP
271
272 def test_ns_from_epoch(self):
9cf643d1
PP
273 s_from_epoch = 45 + ((354 + 123) / 1000)
274 ns_from_epoch = int(s_from_epoch * 1e9)
4b552f8b 275 self.assertEqual(self._cs.ns_from_epoch, ns_from_epoch)
9cf643d1
PP
276
277 def test_eq(self):
4b552f8b
SM
278 cs1 = self._cc(123)
279 cs2 = self._cc(123)
280 self.assertEqual(cs1, cs2)
9cf643d1 281
811644b8 282 def test_eq_int(self):
4b552f8b
SM
283 cs1 = self._cc(123)
284 self.assertEqual(cs1, 123)
811644b8 285
9cf643d1 286 def test_ne_clock_class(self):
811644b8
PP
287 cc1 = bt2.ClockClass('yes', 1500)
288 cc2 = bt2.ClockClass('yes', 1501)
4b552f8b
SM
289 cs1 = cc1(123)
290 cs2 = cc2(123)
291 self.assertNotEqual(cs1, cs2)
9cf643d1
PP
292
293 def test_ne_cycles(self):
4b552f8b
SM
294 cs1 = self._cc(123)
295 cs2 = self._cc(125)
296 self.assertNotEqual(cs1, cs2)
9cf643d1
PP
297
298 def test_eq_invalid(self):
4b552f8b 299 self.assertFalse(self._cs == 23)
9cf643d1
PP
300
301 def _test_copy(self, cpy):
4b552f8b
SM
302 self.assertIsNot(cpy, self._cs)
303 self.assertNotEqual(cpy.addr, self._cs.addr)
304 self.assertEqual(cpy, self._cs)
9cf643d1
PP
305
306 def test_copy(self):
4b552f8b 307 cpy = copy.copy(self._cs)
9cf643d1
PP
308 self._test_copy(cpy)
309
310 def test_deepcopy(self):
4b552f8b 311 cpy = copy.deepcopy(self._cs)
9cf643d1 312 self._test_copy(cpy)
This page took 0.048638 seconds and 4 git commands to generate.