Commit | Line | Data |
---|---|---|
0235b0db | 1 | # SPDX-License-Identifier: GPL-2.0-only |
d2d857a8 MJ |
2 | # |
3 | # Copyright (C) 2019 EfficiOS Inc. | |
4 | # | |
d2d857a8 | 5 | |
9cf643d1 | 6 | import unittest |
3cdfbaea | 7 | from utils import run_in_component_init |
f0a42b33 FD |
8 | from bt2 import stream_class as bt2_stream_class |
9 | from bt2 import trace_class as bt2_trace_class | |
10 | from bt2 import clock_class as bt2_clock_class | |
11 | from bt2 import event_class as bt2_event_class | |
12 | from bt2 import field_class as bt2_field_class | |
9cf643d1 PP |
13 | |
14 | ||
15 | class StreamClassTestCase(unittest.TestCase): | |
16 | def setUp(self): | |
3cdfbaea SM |
17 | def f(comp_self): |
18 | tc = comp_self._create_trace_class(assigns_automatic_stream_class_id=True) | |
19 | cc = comp_self._create_clock_class() | |
20 | return tc, cc | |
21 | ||
22 | self._tc, self._cc = run_in_component_init(f) | |
23 | self._trace = self._tc() | |
24 | ||
25 | def test_create_default(self): | |
26 | sc = self._tc.create_stream_class() | |
27 | ||
f0a42b33 | 28 | self.assertIs(type(sc), bt2_stream_class._StreamClass) |
3cdfbaea SM |
29 | self.assertIsNone(sc.name) |
30 | self.assertIsNone(sc.packet_context_field_class) | |
31 | self.assertIsNone(sc.event_common_context_field_class) | |
32 | self.assertIsNone(sc.default_clock_class) | |
33 | self.assertTrue(sc.assigns_automatic_event_class_id) | |
34 | self.assertTrue(sc.assigns_automatic_stream_id) | |
26fc5aed | 35 | self.assertFalse(sc.supports_packets) |
9b24b6aa PP |
36 | self.assertFalse(sc.packets_have_beginning_default_clock_snapshot) |
37 | self.assertFalse(sc.packets_have_end_default_clock_snapshot) | |
2e90378a PP |
38 | self.assertFalse(sc.supports_discarded_events) |
39 | self.assertFalse(sc.discarded_events_have_default_clock_snapshots) | |
40 | self.assertFalse(sc.supports_discarded_packets) | |
41 | self.assertFalse(sc.discarded_packets_have_default_clock_snapshots) | |
5783664e | 42 | self.assertEqual(len(sc.user_attributes), 0) |
3cdfbaea SM |
43 | |
44 | def test_create_name(self): | |
f5567ea8 FD |
45 | sc = self._tc.create_stream_class(name="bozo") |
46 | self.assertEqual(sc.name, "bozo") | |
3cdfbaea SM |
47 | |
48 | def test_create_invalid_name(self): | |
91910435 | 49 | with self.assertRaisesRegex(TypeError, "'int' is not a 'str' object"): |
3cdfbaea | 50 | self._tc.create_stream_class(name=17) |
9cf643d1 | 51 | |
d3bf1370 SM |
52 | self.assertEqual(len(self._tc), 0) |
53 | ||
3cdfbaea SM |
54 | def test_create_packet_context_field_class(self): |
55 | fc = self._tc.create_structure_field_class() | |
cfbd7cf3 FD |
56 | sc = self._tc.create_stream_class( |
57 | packet_context_field_class=fc, supports_packets=True | |
58 | ) | |
3cdfbaea | 59 | self.assertEqual(sc.packet_context_field_class, fc) |
f0a42b33 FD |
60 | self.assertIs( |
61 | type(sc.packet_context_field_class), bt2_field_class._StructureFieldClass | |
62 | ) | |
9cf643d1 | 63 | |
3cdfbaea | 64 | def test_create_invalid_packet_context_field_class(self): |
91910435 SM |
65 | with self.assertRaisesRegex( |
66 | TypeError, | |
67 | "'int' is not a '<class 'bt2.field_class._StructureFieldClass'>' object", | |
68 | ): | |
d3bf1370 SM |
69 | self._tc.create_stream_class( |
70 | packet_context_field_class=22, supports_packets=True | |
71 | ) | |
72 | ||
73 | self.assertEqual(len(self._tc), 0) | |
9cf643d1 | 74 | |
26fc5aed PP |
75 | def test_create_invalid_packet_context_field_class_no_packets(self): |
76 | fc = self._tc.create_structure_field_class() | |
77 | ||
91910435 SM |
78 | with self.assertRaisesRegex( |
79 | ValueError, | |
80 | "cannot have a packet context field class without supporting packets", | |
81 | ): | |
26fc5aed PP |
82 | self._tc.create_stream_class(packet_context_field_class=fc) |
83 | ||
d3bf1370 SM |
84 | self.assertEqual(len(self._tc), 0) |
85 | ||
3cdfbaea SM |
86 | def test_create_event_common_context_field_class(self): |
87 | fc = self._tc.create_structure_field_class() | |
88 | sc = self._tc.create_stream_class(event_common_context_field_class=fc) | |
89 | self.assertEqual(sc.event_common_context_field_class, fc) | |
f0a42b33 FD |
90 | self.assertIs( |
91 | type(sc.event_common_context_field_class), | |
92 | bt2_field_class._StructureFieldClass, | |
93 | ) | |
811644b8 | 94 | |
3cdfbaea | 95 | def test_create_invalid_event_common_context_field_class(self): |
91910435 SM |
96 | with self.assertRaisesRegex( |
97 | TypeError, | |
98 | "'int' is not a '<class 'bt2.field_class._StructureFieldClass'>' object", | |
99 | ): | |
3cdfbaea | 100 | self._tc.create_stream_class(event_common_context_field_class=22) |
9cf643d1 | 101 | |
d3bf1370 SM |
102 | self.assertEqual(len(self._tc), 0) |
103 | ||
3cdfbaea SM |
104 | def test_create_default_clock_class(self): |
105 | sc = self._tc.create_stream_class(default_clock_class=self._cc) | |
106 | self.assertEqual(sc.default_clock_class.addr, self._cc.addr) | |
f0a42b33 | 107 | self.assertIs(type(sc.default_clock_class), bt2_clock_class._ClockClass) |
9cf643d1 | 108 | |
3cdfbaea | 109 | def test_create_invalid_default_clock_class(self): |
91910435 SM |
110 | with self.assertRaisesRegex( |
111 | TypeError, "'int' is not a '<class 'bt2.clock_class._ClockClass'>' object" | |
112 | ): | |
3cdfbaea | 113 | self._tc.create_stream_class(default_clock_class=12) |
9cf643d1 | 114 | |
d3bf1370 SM |
115 | self.assertEqual(len(self._tc), 0) |
116 | ||
5783664e | 117 | def test_create_user_attributes(self): |
f5567ea8 FD |
118 | sc = self._tc.create_stream_class(user_attributes={"salut": 23}) |
119 | self.assertEqual(sc.user_attributes, {"salut": 23}) | |
5783664e PP |
120 | |
121 | def test_create_invalid_user_attributes(self): | |
91910435 SM |
122 | with self.assertRaisesRegex( |
123 | TypeError, "cannot create value object from 'object' object" | |
124 | ): | |
5783664e PP |
125 | self._tc.create_stream_class(user_attributes=object()) |
126 | ||
d3bf1370 SM |
127 | self.assertEqual(len(self._tc), 0) |
128 | ||
5783664e | 129 | def test_create_invalid_user_attributes_value_type(self): |
91910435 SM |
130 | with self.assertRaisesRegex( |
131 | TypeError, | |
132 | "'SignedIntegerValue' is not a '<class 'bt2.value.MapValue'>' object", | |
133 | ): | |
5783664e PP |
134 | self._tc.create_stream_class(user_attributes=23) |
135 | ||
d3bf1370 SM |
136 | self.assertEqual(len(self._tc), 0) |
137 | ||
3cdfbaea SM |
138 | def test_automatic_stream_ids(self): |
139 | sc = self._tc.create_stream_class(assigns_automatic_stream_id=True) | |
140 | self.assertTrue(sc.assigns_automatic_stream_id) | |
9cf643d1 | 141 | |
3cdfbaea SM |
142 | stream = self._trace.create_stream(sc) |
143 | self.assertIsNotNone(stream.id) | |
9cf643d1 | 144 | |
3cdfbaea SM |
145 | def test_automatic_stream_ids_raises(self): |
146 | sc = self._tc.create_stream_class(assigns_automatic_stream_id=True) | |
147 | self.assertTrue(sc.assigns_automatic_stream_id) | |
148 | ||
91910435 SM |
149 | with self.assertRaisesRegex( |
150 | ValueError, "id provided, but stream class assigns automatic stream ids" | |
151 | ): | |
3cdfbaea SM |
152 | self._trace.create_stream(sc, id=123) |
153 | ||
d3bf1370 SM |
154 | self.assertEqual(len(self._trace), 0) |
155 | ||
156 | def test_automatic_stream_ids_wrong_type(self): | |
157 | with self.assertRaisesRegex(TypeError, "str' is not a 'bool' object"): | |
f5567ea8 | 158 | self._tc.create_stream_class(assigns_automatic_stream_id="True") |
d3bf1370 SM |
159 | |
160 | self.assertEqual(len(self._tc), 0) | |
161 | ||
3cdfbaea SM |
162 | def test_no_automatic_stream_ids(self): |
163 | sc = self._tc.create_stream_class(assigns_automatic_stream_id=False) | |
164 | self.assertFalse(sc.assigns_automatic_stream_id) | |
165 | ||
166 | stream = self._trace.create_stream(sc, id=333) | |
167 | self.assertEqual(stream.id, 333) | |
168 | ||
169 | def test_no_automatic_stream_ids_raises(self): | |
170 | sc = self._tc.create_stream_class(assigns_automatic_stream_id=False) | |
171 | self.assertFalse(sc.assigns_automatic_stream_id) | |
172 | ||
91910435 SM |
173 | with self.assertRaisesRegex( |
174 | ValueError, | |
175 | "id not provided, but stream class does not assign automatic stream ids", | |
176 | ): | |
3cdfbaea SM |
177 | self._trace.create_stream(sc) |
178 | ||
d3bf1370 SM |
179 | self.assertEqual(len(self._trace), 0) |
180 | ||
3cdfbaea SM |
181 | def test_automatic_event_class_ids(self): |
182 | sc = self._tc.create_stream_class(assigns_automatic_event_class_id=True) | |
183 | self.assertTrue(sc.assigns_automatic_event_class_id) | |
184 | ||
185 | ec = sc.create_event_class() | |
186 | self.assertIsNotNone(ec.id) | |
187 | ||
188 | def test_automatic_event_class_ids_raises(self): | |
189 | sc = self._tc.create_stream_class(assigns_automatic_event_class_id=True) | |
190 | self.assertTrue(sc.assigns_automatic_event_class_id) | |
191 | ||
91910435 SM |
192 | with self.assertRaisesRegex( |
193 | ValueError, | |
194 | "id provided, but stream class assigns automatic event class ids", | |
195 | ): | |
3cdfbaea SM |
196 | sc.create_event_class(id=123) |
197 | ||
d3bf1370 SM |
198 | self.assertEqual(len(sc), 0) |
199 | ||
200 | def test_automatic_event_class_ids_wrong_type(self): | |
201 | with self.assertRaisesRegex(TypeError, "'str' is not a 'bool' object"): | |
f5567ea8 | 202 | self._tc.create_stream_class(assigns_automatic_event_class_id="True") |
d3bf1370 SM |
203 | |
204 | self.assertEqual(len(self._tc), 0) | |
205 | ||
3cdfbaea SM |
206 | def test_no_automatic_event_class_ids(self): |
207 | sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False) | |
208 | self.assertFalse(sc.assigns_automatic_event_class_id) | |
9cf643d1 | 209 | |
3cdfbaea SM |
210 | ec = sc.create_event_class(id=333) |
211 | self.assertEqual(ec.id, 333) | |
9cf643d1 | 212 | |
3cdfbaea SM |
213 | def test_no_automatic_event_class_ids_raises(self): |
214 | sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False) | |
215 | self.assertFalse(sc.assigns_automatic_event_class_id) | |
9cf643d1 | 216 | |
91910435 SM |
217 | with self.assertRaisesRegex( |
218 | ValueError, | |
219 | "id not provided, but stream class does not assign automatic event class ids", | |
220 | ): | |
3cdfbaea SM |
221 | sc.create_event_class() |
222 | ||
d3bf1370 SM |
223 | self.assertEqual(len(sc), 0) |
224 | ||
26fc5aed | 225 | def test_supports_packets_without_cs(self): |
cfbd7cf3 FD |
226 | sc = self._tc.create_stream_class( |
227 | default_clock_class=self._cc, supports_packets=True | |
228 | ) | |
26fc5aed PP |
229 | self.assertTrue(sc.supports_packets) |
230 | self.assertFalse(sc.packets_have_beginning_default_clock_snapshot) | |
231 | self.assertFalse(sc.packets_have_end_default_clock_snapshot) | |
232 | ||
233 | def test_supports_packets_with_begin_cs(self): | |
cfbd7cf3 FD |
234 | sc = self._tc.create_stream_class( |
235 | default_clock_class=self._cc, | |
236 | supports_packets=True, | |
237 | packets_have_beginning_default_clock_snapshot=True, | |
238 | ) | |
26fc5aed | 239 | self.assertTrue(sc.supports_packets) |
9b24b6aa | 240 | self.assertTrue(sc.packets_have_beginning_default_clock_snapshot) |
26fc5aed | 241 | self.assertFalse(sc.packets_have_end_default_clock_snapshot) |
3cdfbaea | 242 | |
26fc5aed | 243 | def test_supports_packets_with_end_cs(self): |
cfbd7cf3 FD |
244 | sc = self._tc.create_stream_class( |
245 | default_clock_class=self._cc, | |
246 | supports_packets=True, | |
247 | packets_have_end_default_clock_snapshot=True, | |
248 | ) | |
26fc5aed PP |
249 | self.assertTrue(sc.supports_packets) |
250 | self.assertFalse(sc.packets_have_beginning_default_clock_snapshot) | |
251 | self.assertTrue(sc.packets_have_end_default_clock_snapshot) | |
252 | ||
253 | def test_supports_packets_raises_type_error(self): | |
91910435 | 254 | with self.assertRaisesRegex(TypeError, "'int' is not a 'bool' object"): |
082db648 | 255 | self._tc.create_stream_class( |
cfbd7cf3 FD |
256 | default_clock_class=self._cc, supports_packets=23 |
257 | ) | |
3cdfbaea | 258 | |
d3bf1370 SM |
259 | self.assertEqual(len(self._tc), 0) |
260 | ||
26fc5aed | 261 | def test_packets_have_begin_default_cs_raises_type_error(self): |
91910435 | 262 | with self.assertRaisesRegex(TypeError, "'int' is not a 'bool' object"): |
082db648 | 263 | self._tc.create_stream_class( |
cfbd7cf3 FD |
264 | default_clock_class=self._cc, |
265 | packets_have_beginning_default_clock_snapshot=23, | |
266 | ) | |
3cdfbaea | 267 | |
d3bf1370 SM |
268 | self.assertEqual(len(self._tc), 0) |
269 | ||
26fc5aed | 270 | def test_packets_have_end_default_cs_raises_type_error(self): |
91910435 | 271 | with self.assertRaisesRegex(TypeError, "'int' is not a 'bool' object"): |
082db648 | 272 | self._tc.create_stream_class( |
cfbd7cf3 FD |
273 | default_clock_class=self._cc, packets_have_end_default_clock_snapshot=23 |
274 | ) | |
26fc5aed | 275 | |
d3bf1370 SM |
276 | self.assertEqual(len(self._tc), 0) |
277 | ||
26fc5aed | 278 | def test_does_not_support_packets_raises_with_begin_cs(self): |
91910435 SM |
279 | with self.assertRaisesRegex( |
280 | ValueError, | |
281 | "cannot not support packets, but have packet beginning default clock snapshot", | |
282 | ): | |
082db648 | 283 | self._tc.create_stream_class( |
cfbd7cf3 FD |
284 | default_clock_class=self._cc, |
285 | packets_have_beginning_default_clock_snapshot=True, | |
286 | ) | |
26fc5aed | 287 | |
d3bf1370 SM |
288 | self.assertEqual(len(self._tc), 0) |
289 | ||
26fc5aed | 290 | def test_does_not_support_packets_raises_with_end_cs(self): |
91910435 SM |
291 | with self.assertRaisesRegex( |
292 | ValueError, | |
293 | "cannot not support packets, but have packet end default clock snapshots", | |
294 | ): | |
082db648 | 295 | self._tc.create_stream_class( |
cfbd7cf3 FD |
296 | default_clock_class=self._cc, |
297 | packets_have_end_default_clock_snapshot=True, | |
298 | ) | |
3cdfbaea | 299 | |
d3bf1370 SM |
300 | self.assertEqual(len(self._tc), 0) |
301 | ||
2e90378a | 302 | def test_supports_discarded_events_without_cs(self): |
cfbd7cf3 FD |
303 | sc = self._tc.create_stream_class( |
304 | default_clock_class=self._cc, supports_discarded_events=True | |
305 | ) | |
2e90378a PP |
306 | self.assertTrue(sc.supports_discarded_events) |
307 | self.assertFalse(sc.discarded_events_have_default_clock_snapshots) | |
308 | ||
309 | def test_supports_discarded_events_with_cs(self): | |
cfbd7cf3 FD |
310 | sc = self._tc.create_stream_class( |
311 | default_clock_class=self._cc, | |
312 | supports_discarded_events=True, | |
313 | discarded_events_have_default_clock_snapshots=True, | |
314 | ) | |
2e90378a PP |
315 | self.assertTrue(sc.supports_discarded_events) |
316 | self.assertTrue(sc.discarded_events_have_default_clock_snapshots) | |
317 | ||
318 | def test_supports_discarded_events_raises_type_error(self): | |
91910435 | 319 | with self.assertRaisesRegex(TypeError, "'int' is not a 'bool' object"): |
082db648 | 320 | self._tc.create_stream_class( |
cfbd7cf3 FD |
321 | default_clock_class=self._cc, supports_discarded_events=23 |
322 | ) | |
2e90378a | 323 | |
d3bf1370 SM |
324 | self.assertEqual(len(self._tc), 0) |
325 | ||
2e90378a | 326 | def test_discarded_events_have_default_cs_raises_type_error(self): |
91910435 | 327 | with self.assertRaisesRegex(TypeError, "'int' is not a 'bool' object"): |
082db648 | 328 | self._tc.create_stream_class( |
cfbd7cf3 FD |
329 | default_clock_class=self._cc, |
330 | discarded_events_have_default_clock_snapshots=23, | |
331 | ) | |
2e90378a | 332 | |
d3bf1370 SM |
333 | self.assertEqual(len(self._tc), 0) |
334 | ||
2e90378a | 335 | def test_does_not_support_discarded_events_raises_with_cs(self): |
91910435 SM |
336 | with self.assertRaisesRegex( |
337 | ValueError, | |
338 | "cannot not support discarded events, but have default clock snapshots for discarded event messages", | |
339 | ): | |
082db648 | 340 | self._tc.create_stream_class( |
cfbd7cf3 FD |
341 | default_clock_class=self._cc, |
342 | discarded_events_have_default_clock_snapshots=True, | |
343 | ) | |
2e90378a | 344 | |
d3bf1370 SM |
345 | self.assertEqual(len(self._tc), 0) |
346 | ||
aa740722 SM |
347 | def test_supports_discarded_events_with_clock_snapshots_without_default_clock_class_raises( |
348 | self, | |
349 | ): | |
350 | with self.assertRaisesRegex( | |
351 | ValueError, | |
f5567ea8 | 352 | "cannot have no default clock class, but have default clock snapshots for discarded event messages", |
aa740722 SM |
353 | ): |
354 | self._tc.create_stream_class( | |
355 | supports_discarded_events=True, | |
356 | discarded_events_have_default_clock_snapshots=True, | |
357 | ) | |
358 | ||
359 | self.assertEqual(len(self._tc), 0) | |
360 | ||
2e90378a | 361 | def test_supports_discarded_packets_without_cs(self): |
cfbd7cf3 FD |
362 | sc = self._tc.create_stream_class( |
363 | default_clock_class=self._cc, | |
364 | supports_discarded_packets=True, | |
365 | supports_packets=True, | |
366 | ) | |
2e90378a PP |
367 | self.assertTrue(sc.supports_discarded_packets) |
368 | self.assertFalse(sc.discarded_packets_have_default_clock_snapshots) | |
369 | ||
370 | def test_supports_discarded_packets_with_cs(self): | |
cfbd7cf3 FD |
371 | sc = self._tc.create_stream_class( |
372 | default_clock_class=self._cc, | |
373 | supports_discarded_packets=True, | |
374 | discarded_packets_have_default_clock_snapshots=True, | |
375 | supports_packets=True, | |
376 | ) | |
2e90378a PP |
377 | self.assertTrue(sc.supports_discarded_packets) |
378 | self.assertTrue(sc.discarded_packets_have_default_clock_snapshots) | |
379 | ||
26fc5aed | 380 | def test_supports_discarded_packets_raises_without_packet_support(self): |
91910435 SM |
381 | with self.assertRaisesRegex( |
382 | ValueError, "cannot support discarded packets, but not support packets" | |
383 | ): | |
082db648 | 384 | self._tc.create_stream_class( |
cfbd7cf3 FD |
385 | default_clock_class=self._cc, supports_discarded_packets=True |
386 | ) | |
26fc5aed | 387 | |
d3bf1370 SM |
388 | self.assertEqual(len(self._tc), 0) |
389 | ||
2e90378a | 390 | def test_supports_discarded_packets_raises_type_error(self): |
91910435 | 391 | with self.assertRaisesRegex(TypeError, "'int' is not a 'bool' object"): |
082db648 | 392 | self._tc.create_stream_class( |
cfbd7cf3 FD |
393 | default_clock_class=self._cc, |
394 | supports_discarded_packets=23, | |
395 | supports_packets=True, | |
396 | ) | |
2e90378a | 397 | |
d3bf1370 SM |
398 | self.assertEqual(len(self._tc), 0) |
399 | ||
2e90378a | 400 | def test_discarded_packets_have_default_cs_raises_type_error(self): |
91910435 | 401 | with self.assertRaisesRegex(TypeError, "'int' is not a 'bool' object"): |
082db648 | 402 | self._tc.create_stream_class( |
cfbd7cf3 FD |
403 | default_clock_class=self._cc, |
404 | discarded_packets_have_default_clock_snapshots=23, | |
405 | supports_packets=True, | |
406 | ) | |
2e90378a | 407 | |
d3bf1370 SM |
408 | self.assertEqual(len(self._tc), 0) |
409 | ||
2e90378a | 410 | def test_does_not_support_discarded_packets_raises_with_cs(self): |
91910435 SM |
411 | with self.assertRaisesRegex( |
412 | ValueError, | |
413 | "cannot not support discarded packets, but have default clock snapshots for discarded packet messages", | |
414 | ): | |
082db648 | 415 | self._tc.create_stream_class( |
cfbd7cf3 FD |
416 | default_clock_class=self._cc, |
417 | discarded_packets_have_default_clock_snapshots=True, | |
418 | supports_packets=True, | |
419 | ) | |
2e90378a | 420 | |
d3bf1370 SM |
421 | self.assertEqual(len(self._tc), 0) |
422 | ||
aa740722 SM |
423 | def test_supports_discarded_packets_with_clock_snapshots_without_default_clock_class_raises( |
424 | self, | |
425 | ): | |
426 | with self.assertRaisesRegex( | |
427 | ValueError, | |
f5567ea8 | 428 | "cannot have no default clock class, but have default clock snapshots for discarded packet messages", |
aa740722 SM |
429 | ): |
430 | self._tc.create_stream_class( | |
431 | supports_packets=True, | |
432 | supports_discarded_packets=True, | |
433 | discarded_packets_have_default_clock_snapshots=True, | |
434 | ) | |
435 | ||
436 | self.assertEqual(len(self._tc), 0) | |
437 | ||
3cdfbaea SM |
438 | def test_trace_class(self): |
439 | sc = self._tc.create_stream_class() | |
440 | self.assertEqual(sc.trace_class.addr, self._tc.addr) | |
f0a42b33 | 441 | self.assertIs(type(sc.trace_class), bt2_trace_class._TraceClass) |
3cdfbaea SM |
442 | |
443 | def _create_stream_class_with_event_classes(self): | |
444 | sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False) | |
445 | ec1 = sc.create_event_class(id=23) | |
446 | ec2 = sc.create_event_class(id=17) | |
447 | return sc, ec1, ec2 | |
9cf643d1 PP |
448 | |
449 | def test_getitem(self): | |
3cdfbaea SM |
450 | sc, ec1, ec2 = self._create_stream_class_with_event_classes() |
451 | ||
452 | self.assertEqual(sc[23].addr, ec1.addr) | |
f0a42b33 | 453 | self.assertEqual(type(sc[23]), bt2_event_class._EventClass) |
3cdfbaea | 454 | self.assertEqual(sc[17].addr, ec2.addr) |
f0a42b33 | 455 | self.assertEqual(type(sc[17]), bt2_event_class._EventClass) |
9cf643d1 PP |
456 | |
457 | def test_getitem_wrong_key_type(self): | |
3cdfbaea SM |
458 | sc, _, _ = self._create_stream_class_with_event_classes() |
459 | ||
91910435 | 460 | with self.assertRaisesRegex(TypeError, "'str' is not an 'int' object"): |
f5567ea8 | 461 | sc["event23"] |
9cf643d1 PP |
462 | |
463 | def test_getitem_wrong_key(self): | |
3cdfbaea SM |
464 | sc, _, _ = self._create_stream_class_with_event_classes() |
465 | ||
f5567ea8 | 466 | with self.assertRaisesRegex(KeyError, "19"): |
3cdfbaea | 467 | sc[19] |
9cf643d1 PP |
468 | |
469 | def test_len(self): | |
3cdfbaea SM |
470 | sc, _, _ = self._create_stream_class_with_event_classes() |
471 | ||
472 | self.assertEqual(len(sc), 2) | |
9cf643d1 PP |
473 | |
474 | def test_iter(self): | |
3cdfbaea SM |
475 | sc, _, _ = self._create_stream_class_with_event_classes() |
476 | ||
477 | ec_ids = sorted(sc) | |
478 | self.assertEqual(ec_ids, [17, 23]) | |
d14ddbba SM |
479 | |
480 | ||
f5567ea8 | 481 | if __name__ == "__main__": |
d14ddbba | 482 | unittest.main() |