X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_message.py;h=11d12a024b09526349698648d7d6db676e4fe42b;hb=f5567ea88d172767b34373bc6e402da8bfd85ef8;hp=a99972aadc7d54f226f9de639e34f602a9c58bb2;hpb=5d9ef4cb64e5bd7793d443cbfcc0248bb8804580;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_message.py b/tests/bindings/python/bt2/test_message.py index a99972aa..11d12a02 100644 --- a/tests/bindings/python/bt2/test_message.py +++ b/tests/bindings/python/bt2/test_message.py @@ -24,7 +24,7 @@ class AllMessagesTestCase(unittest.TestCase): def __init__(self, config, self_port_output): self._at = 0 self._with_stream_msgs_clock_snapshots = self_port_output.user_data.get( - 'with_stream_msgs_clock_snapshots', False + "with_stream_msgs_clock_snapshots", False ) def __next__(self): @@ -107,9 +107,9 @@ class AllMessagesTestCase(unittest.TestCase): class MySrc(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, config, params, obj): - self._add_output_port('out', params) + self._add_output_port("out", params) - with_cc = bool(params['with_cc']) + with_cc = bool(params["with_cc"]) tc = self._create_trace_class() if with_cc: cc = self._create_clock_class() @@ -130,15 +130,15 @@ class AllMessagesTestCase(unittest.TestCase): # Create payload field class my_int_fc = tc.create_signed_integer_field_class(32) payload_fc = tc.create_structure_field_class() - payload_fc += [('my_int', my_int_fc)] + payload_fc += [("my_int", my_int_fc)] # Create specific context field class my_int_fc = tc.create_signed_integer_field_class(32) specific_fc = tc.create_structure_field_class() - specific_fc += [('my_int', my_int_fc)] + specific_fc += [("my_int", my_int_fc)] ec = sc.create_event_class( - name='salut', + name="salut", payload_field_class=payload_fc, specific_context_field_class=specific_fc, ) @@ -159,10 +159,10 @@ class AllMessagesTestCase(unittest.TestCase): self._iter = MyIter def test_all_msg_with_cc(self): - params = {'with_cc': True} - self._src_comp = self._graph.add_component(self._src, 'my_source', params) + params = {"with_cc": True} + self._src_comp = self._graph.add_component(self._src, "my_source", params) self._msg_iter = TestOutputPortMessageIterator( - self._graph, self._src_comp.output_ports['out'] + self._graph, self._src_comp.output_ports["out"] ) for i, msg in enumerate(self._msg_iter): @@ -193,7 +193,7 @@ class AllMessagesTestCase(unittest.TestCase): type(msg.event.payload_field), bt2_field._StructureFieldConst ) self.assertIs( - type(msg.event.payload_field['my_int']), + type(msg.event.payload_field["my_int"]), bt2_field._SignedIntegerFieldConst, ) @@ -267,10 +267,10 @@ class AllMessagesTestCase(unittest.TestCase): raise Exception def test_all_msg_without_cc(self): - params = {'with_cc': False} - self._src_comp = self._graph.add_component(self._src, 'my_source', params) + params = {"with_cc": False} + self._src_comp = self._graph.add_component(self._src, "my_source", params) self._msg_iter = TestOutputPortMessageIterator( - self._graph, self._src_comp.output_ports['out'] + self._graph, self._src_comp.output_ports["out"] ) for i, msg in enumerate(self._msg_iter): @@ -279,7 +279,7 @@ class AllMessagesTestCase(unittest.TestCase): self.assertIs(type(msg.stream), bt2_stream._StreamConst) self.assertEqual(msg.stream.addr, self._stream.addr) with self.assertRaisesRegex( - ValueError, 'stream class has no default clock class' + ValueError, "stream class has no default clock class" ): msg.default_clock_snapshot elif i == 1: @@ -292,7 +292,7 @@ class AllMessagesTestCase(unittest.TestCase): self.assertIs(type(msg.event.cls), bt2_event_class._EventClassConst) self.assertEqual(msg.event.cls.addr, self._event_class.addr) with self.assertRaisesRegex( - ValueError, 'stream class has no default clock class' + ValueError, "stream class has no default clock class" ): msg.default_clock_snapshot elif i == 3: @@ -304,12 +304,12 @@ class AllMessagesTestCase(unittest.TestCase): self.assertIsNone(msg.stream.cls.default_clock_class) with self.assertRaisesRegex( ValueError, - 'such a message has no clock snapshots for this stream class', + "such a message has no clock snapshots for this stream class", ): msg.beginning_default_clock_snapshot with self.assertRaisesRegex( ValueError, - 'such a message has no clock snapshots for this stream class', + "such a message has no clock snapshots for this stream class", ): msg.end_default_clock_snapshot elif i == 4: @@ -328,12 +328,12 @@ class AllMessagesTestCase(unittest.TestCase): self.assertIsNone(msg.stream.cls.default_clock_class) with self.assertRaisesRegex( ValueError, - 'such a message has no clock snapshots for this stream class', + "such a message has no clock snapshots for this stream class", ): msg.beginning_default_clock_snapshot with self.assertRaisesRegex( ValueError, - 'such a message has no clock snapshots for this stream class', + "such a message has no clock snapshots for this stream class", ): msg.end_default_clock_snapshot elif i == 6: @@ -341,18 +341,18 @@ class AllMessagesTestCase(unittest.TestCase): self.assertIs(type(msg.stream), bt2_stream._StreamConst) self.assertEqual(msg.stream.addr, self._stream.addr) with self.assertRaisesRegex( - ValueError, 'stream class has no default clock class' + ValueError, "stream class has no default clock class" ): msg.default_clock_snapshot else: raise Exception def test_msg_stream_with_clock_snapshots(self): - params = {'with_cc': True, 'with_stream_msgs_clock_snapshots': True} + params = {"with_cc": True, "with_stream_msgs_clock_snapshots": True} - self._src_comp = self._graph.add_component(self._src, 'my_source', params) + self._src_comp = self._graph.add_component(self._src, "my_source", params) self._msg_iter = TestOutputPortMessageIterator( - self._graph, self._src_comp.output_ports['out'] + self._graph, self._src_comp.output_ports["out"] ) msgs = list(self._msg_iter) @@ -418,6 +418,23 @@ class CreateDiscardedEventMessageTestCase(unittest.TestCase): self.assertIs(type(msg), bt2._DiscardedEventsMessage) self.assertEqual(msg.count, 242) + # With event count == 0. + def test_create_with_count_zero_raises(self): + def create_stream_class(tc, cc): + return tc.create_stream_class(supports_discarded_events=True) + + def msg_iter_next(msg_iter, stream): + with self.assertRaisesRegex( + ValueError, + "discarded event count is 0", + ): + msg_iter._create_discarded_events_message(stream, count=0) + + return 123 + + res = utils.run_in_message_iterator_next(create_stream_class, msg_iter_next) + self.assertEqual(res, 123) + # With clock snapshots. def test_create_with_clock_snapshots(self): def create_stream_class(tc, cc): @@ -444,7 +461,7 @@ class CreateDiscardedEventMessageTestCase(unittest.TestCase): def msg_iter_next(msg_iter, stream): with self.assertRaisesRegex( - ValueError, 'stream class does not support discarded events' + ValueError, "stream class does not support discarded events" ): msg_iter._create_discarded_events_message(stream) @@ -462,7 +479,7 @@ class CreateDiscardedEventMessageTestCase(unittest.TestCase): def msg_iter_next(msg_iter, stream): with self.assertRaisesRegex( ValueError, - 'discarded events have no default clock snapshots for this stream class', + "discarded events have no default clock snapshots for this stream class", ): msg_iter._create_discarded_events_message( stream, beg_clock_snapshot=10, end_clock_snapshot=20 @@ -485,7 +502,7 @@ class CreateDiscardedEventMessageTestCase(unittest.TestCase): def msg_iter_next(msg_iter, stream): with self.assertRaisesRegex( ValueError, - 'discarded events have default clock snapshots for this stream class', + "discarded events have default clock snapshots for this stream class", ): msg_iter._create_discarded_events_message(stream) @@ -506,7 +523,7 @@ class CreateDiscardedEventMessageTestCase(unittest.TestCase): def msg_iter_next(msg_iter, stream): with self.assertRaisesRegex( ValueError, - r'beginning default clock snapshot value \(20\) is greater than end default clock snapshot value \(10\)', + r"beginning default clock snapshot value \(20\) is greater than end default clock snapshot value \(10\)", ): msg_iter._create_discarded_events_message( stream, beg_clock_snapshot=20, end_clock_snapshot=10 @@ -547,6 +564,25 @@ class CreateDiscardedPacketMessageTestCase(unittest.TestCase): self.assertIs(type(msg), bt2._DiscardedPacketsMessage) self.assertEqual(msg.count, 242) + # With packet count == 0. + def test_create_with_count_zero_raises(self): + def create_stream_class(tc, cc): + return tc.create_stream_class( + supports_packets=True, supports_discarded_packets=True + ) + + def msg_iter_next(msg_iter, stream): + with self.assertRaisesRegex( + ValueError, + "discarded packet count is 0", + ): + msg_iter._create_discarded_packets_message(stream, count=0) + + return 123 + + res = utils.run_in_message_iterator_next(create_stream_class, msg_iter_next) + self.assertEqual(res, 123) + # With clock snapshots. def test_create_with_clock_snapshots(self): def create_stream_class(tc, cc): @@ -570,11 +606,13 @@ class CreateDiscardedPacketMessageTestCase(unittest.TestCase): # Trying to create when the stream does not support discarded packets. def test_create_unsupported_raises(self): def create_stream_class(tc, cc): - return tc.create_stream_class(supports_packets=True,) + return tc.create_stream_class( + supports_packets=True, + ) def msg_iter_next(msg_iter, stream): with self.assertRaisesRegex( - ValueError, 'stream class does not support discarded packets' + ValueError, "stream class does not support discarded packets" ): msg_iter._create_discarded_packets_message(stream) @@ -594,7 +632,7 @@ class CreateDiscardedPacketMessageTestCase(unittest.TestCase): def msg_iter_next(msg_iter, stream): with self.assertRaisesRegex( ValueError, - 'discarded packets have no default clock snapshots for this stream class', + "discarded packets have no default clock snapshots for this stream class", ): msg_iter._create_discarded_packets_message( stream, beg_clock_snapshot=10, end_clock_snapshot=20 @@ -618,7 +656,7 @@ class CreateDiscardedPacketMessageTestCase(unittest.TestCase): def msg_iter_next(msg_iter, stream): with self.assertRaisesRegex( ValueError, - 'discarded packets have default clock snapshots for this stream class', + "discarded packets have default clock snapshots for this stream class", ): msg_iter._create_discarded_packets_message(stream) @@ -640,7 +678,7 @@ class CreateDiscardedPacketMessageTestCase(unittest.TestCase): def msg_iter_next(msg_iter, stream): with self.assertRaisesRegex( ValueError, - r'beginning default clock snapshot value \(20\) is greater than end default clock snapshot value \(10\)', + r"beginning default clock snapshot value \(20\) is greater than end default clock snapshot value \(10\)", ): msg_iter._create_discarded_packets_message( stream, beg_clock_snapshot=20, end_clock_snapshot=10 @@ -652,5 +690,5 @@ class CreateDiscardedPacketMessageTestCase(unittest.TestCase): self.assertEqual(res, 123) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main()