From 31592d1297d3cca30270ae94e34301fd3592f561 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 11 Apr 2020 12:17:36 -0400 Subject: [PATCH] Fix: bt2: read properties on _DiscardedEventsMessage Reading the count and clock snapshot properties on a _DiscardedEventsMessage does not work. For example, this: msg = self._create_discarded_events_message(stream, count=10) print(msg.count) Results in: File "test.py", line 10, in __init__ print(msg.count) File "/home/simark/build/babeltrace/src/bindings/python/bt2/build/build_lib/bt2/message.py", line 208, in count avail, count = self._get_count(self._ptr) AttributeError: '_DiscardedEventsMessage' object has no attribute '_get_count' The problem is simply that _DiscardedEventsMessage is missing inheriting from _DiscardedEventsMessageConst. Change-Id: Id40ea54bb26b4e4aec264d84bda52ed815090341 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/3392 Tested-by: jenkins Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/3365 --- src/bindings/python/bt2/bt2/message.py | 2 +- tests/bindings/python/bt2/test_message.py | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/bindings/python/bt2/bt2/message.py b/src/bindings/python/bt2/bt2/message.py index fd92361d..d0a2b9ef 100644 --- a/src/bindings/python/bt2/bt2/message.py +++ b/src/bindings/python/bt2/bt2/message.py @@ -273,7 +273,7 @@ class _DiscardedEventsMessageConst(_DiscardedMessageConst): return self.stream.cls.discarded_events_have_default_clock_snapshots -class _DiscardedEventsMessage(_DiscardedMessage): +class _DiscardedEventsMessage(_DiscardedEventsMessageConst, _DiscardedMessage): _borrow_stream_ptr = staticmethod(native_bt.message_discarded_events_borrow_stream) _set_count = staticmethod(native_bt.message_discarded_events_set_count) diff --git a/tests/bindings/python/bt2/test_message.py b/tests/bindings/python/bt2/test_message.py index 96367ac6..ff67976d 100644 --- a/tests/bindings/python/bt2/test_message.py +++ b/tests/bindings/python/bt2/test_message.py @@ -417,8 +417,7 @@ class CreateDiscardedEventMessageTestCase(unittest.TestCase): msg = utils.run_in_message_iterator_next(create_stream_class, msg_iter_next) self.assertIs(type(msg), bt2._DiscardedEventsMessage) - # Broken at the moment. - # self.assertIs(msg.count, None) + self.assertIs(msg.count, None) # With event count. def test_create_with_count(self): @@ -430,8 +429,7 @@ class CreateDiscardedEventMessageTestCase(unittest.TestCase): msg = utils.run_in_message_iterator_next(create_stream_class, msg_iter_next) self.assertIs(type(msg), bt2._DiscardedEventsMessage) - # Broken at the moment. - # self.assertEqual(msg.count, 242) + self.assertEqual(msg.count, 242) # With clock snapshots. def test_create_with_clock_snapshots(self): @@ -449,9 +447,8 @@ class CreateDiscardedEventMessageTestCase(unittest.TestCase): msg = utils.run_in_message_iterator_next(create_stream_class, msg_iter_next) self.assertIs(type(msg), bt2._DiscardedEventsMessage) - # Broken at the moment. - # self.assertEqual(msg.beginning_default_clock_snapshot, 10); - # self.assertEqual(msg.end_default_clock_snapshot, 20); + self.assertEqual(msg.beginning_default_clock_snapshot, 10) + self.assertEqual(msg.end_default_clock_snapshot, 20) # Trying to create when the stream does not support discarded events. def test_create_unsupported_raises(self): -- 2.34.1