From e8ac1aaec8f07304d16bf787950c14cd7c49fc75 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 6 Jun 2019 18:57:59 -0400 Subject: [PATCH] bt2: rename object's own BT class property to `cls` Having `mein_event.event_class` is redundant; what we really want is `mein_event.class`, but `class` is a reserved word, so use `cls`. Signed-off-by: Philippe Proulx Change-Id: Ib1f0c91ca37e91b7704ca61fb7380bb79cb48927 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1394 Reviewed-by: Simon Marchi --- bindings/python/bt2/bt2/component.py | 4 ++-- bindings/python/bt2/bt2/event.py | 6 +++--- bindings/python/bt2/bt2/message.py | 10 +++++----- bindings/python/bt2/bt2/message_iterator.py | 18 ++++++++--------- bindings/python/bt2/bt2/stream.py | 2 +- .../bt2/trace_collection_message_iterator.py | 20 +++++++++---------- tests/bindings/python/bt2/test_component.py | 4 ++-- .../python/bt2/test_component_class.py | 2 +- tests/bindings/python/bt2/test_event.py | 2 +- tests/bindings/python/bt2/test_graph.py | 4 ++-- tests/bindings/python/bt2/test_message.py | 12 +++++------ .../python/bt2/test_message_iterator.py | 2 +- tests/bindings/python/bt2/test_stream.py | 2 +- 13 files changed, 44 insertions(+), 44 deletions(-) diff --git a/bindings/python/bt2/bt2/component.py b/bindings/python/bt2/bt2/component.py index 5889e8ab..3480f657 100644 --- a/bindings/python/bt2/bt2/component.py +++ b/bindings/python/bt2/bt2/component.py @@ -185,7 +185,7 @@ class _Component: return name @property - def component_class(self): + def cls(self): cc_ptr = self._borrow_component_class_ptr(self._ptr) assert cc_ptr is not None return _create_component_class_from_ptr_and_get_ref(cc_ptr, self._comp_cls_type) @@ -576,7 +576,7 @@ class _UserComponent(metaclass=_UserComponentType): return name @property - def component_class(self): + def cls(self): comp_ptr = self._as_not_self_specific_component_ptr(self._ptr) cc_ptr = self._borrow_component_class_ptr(comp_ptr) return _create_component_class_from_ptr_and_get_ref(cc_ptr, self._comp_cls_type) diff --git a/bindings/python/bt2/bt2/event.py b/bindings/python/bt2/bt2/event.py index 66882bdf..4ff398b7 100644 --- a/bindings/python/bt2/bt2/event.py +++ b/bindings/python/bt2/bt2/event.py @@ -32,18 +32,18 @@ import bt2 class _Event(object._UniqueObject): @property - def event_class(self): + def cls(self): event_class_ptr = native_bt.event_borrow_class(self._ptr) assert event_class_ptr is not None return bt2.event_class._EventClass._create_from_ptr_and_get_ref(event_class_ptr) @property def name(self): - return self.event_class.name + return self.cls.name @property def id(self): - return self.event_class.id + return self.cls.id @property def packet(self): diff --git a/bindings/python/bt2/bt2/message.py b/bindings/python/bt2/bt2/message.py index 179a38ff..56b545da 100644 --- a/bindings/python/bt2/bt2/message.py +++ b/bindings/python/bt2/bt2/message.py @@ -60,7 +60,7 @@ class _EventMessage(_Message, _MessageWithDefaultClockSnapshot): @property def default_clock_snapshot(self): - self._check_has_default_clock_class(self.event.packet.stream.stream_class.default_clock_class) + self._check_has_default_clock_class(self.event.packet.stream.cls.default_clock_class) return self._get_default_clock_snapshot(self._borrow_default_clock_snapshot_ptr) @property @@ -74,7 +74,7 @@ class _EventMessage(_Message, _MessageWithDefaultClockSnapshot): class _PacketMessage(_Message, _MessageWithDefaultClockSnapshot): @property def default_clock_snapshot(self): - self._check_has_default_clock_class(self.packet.stream.stream_class.default_clock_class) + self._check_has_default_clock_class(self.packet.stream.cls.default_clock_class) return self._get_default_clock_snapshot(self._borrow_default_clock_snapshot_ptr) @property @@ -113,7 +113,7 @@ class _StreamEndMessage(_StreamMessage): class _StreamActivityMessage(_Message): @property def default_clock_snapshot(self): - self._check_has_default_clock_class(self.stream.stream_class.default_clock_class) + self._check_has_default_clock_class(self.stream.cls.default_clock_class) status, snapshot_ptr = self._borrow_default_clock_snapshot_ptr(self._ptr) if status == native_bt.MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN: @@ -207,7 +207,7 @@ class _DiscardedEventsMessage(_DiscardedMessage): @property def _has_default_clock_snapshots(self): - return self.stream.stream_class.discarded_events_have_default_clock_snapshots + return self.stream.cls.discarded_events_have_default_clock_snapshots class _DiscardedPacketsMessage(_DiscardedMessage): @@ -219,7 +219,7 @@ class _DiscardedPacketsMessage(_DiscardedMessage): @property def _has_default_clock_snapshots(self): - return self.stream.stream_class.discarded_packets_have_default_clock_snapshots + return self.stream.cls.discarded_packets_have_default_clock_snapshots _MESSAGE_TYPE_TO_CLS = { diff --git a/bindings/python/bt2/bt2/message_iterator.py b/bindings/python/bt2/bt2/message_iterator.py index dd5da109..7f996b00 100644 --- a/bindings/python/bt2/bt2/message_iterator.py +++ b/bindings/python/bt2/bt2/message_iterator.py @@ -152,7 +152,7 @@ class _UserMessageIterator(_MessageIterator): def _create_event_message(self, event_class, packet, default_clock_snapshot=None): utils._check_type(event_class, bt2.event_class._EventClass) utils._check_type(packet, bt2.packet._Packet) - self._validate_default_clock_snapshot(packet.stream.stream_class, default_clock_snapshot) + self._validate_default_clock_snapshot(packet.stream.cls, default_clock_snapshot) if default_clock_snapshot is not None: utils._check_uint64(default_clock_snapshot) @@ -188,7 +188,7 @@ class _UserMessageIterator(_MessageIterator): def _create_stream_activity_beginning_message(self, stream, default_clock_snapshot=None): utils._check_type(stream, bt2.stream._Stream) - self._validate_default_clock_snapshot(stream.stream_class, default_clock_snapshot) + self._validate_default_clock_snapshot(stream.cls, default_clock_snapshot) ptr = native_bt.message_stream_activity_beginning_create(self._ptr, stream._ptr) @@ -205,7 +205,7 @@ class _UserMessageIterator(_MessageIterator): def _create_stream_activity_end_message(self, stream, default_clock_snapshot=None): utils._check_type(stream, bt2.stream._Stream) - self._validate_default_clock_snapshot(stream.stream_class, default_clock_snapshot) + self._validate_default_clock_snapshot(stream.cls, default_clock_snapshot) ptr = native_bt.message_stream_activity_end_create(self._ptr, stream._ptr) @@ -232,7 +232,7 @@ class _UserMessageIterator(_MessageIterator): def _create_packet_beginning_message(self, packet, default_clock_snapshot=None): utils._check_type(packet, bt2.packet._Packet) - if packet.stream.stream_class.packets_have_beginning_default_clock_snapshot: + if packet.stream.cls.packets_have_beginning_default_clock_snapshot: if default_clock_snapshot is None: raise ValueError("packet beginning messages in this stream must have a default clock snapshots") @@ -253,7 +253,7 @@ class _UserMessageIterator(_MessageIterator): def _create_packet_end_message(self, packet, default_clock_snapshot=None): utils._check_type(packet, bt2.packet._Packet) - if packet.stream.stream_class.packets_have_end_default_clock_snapshot: + if packet.stream.cls.packets_have_end_default_clock_snapshot: if default_clock_snapshot is None: raise ValueError("packet end messages in this stream must have a default clock snapshots") @@ -276,10 +276,10 @@ class _UserMessageIterator(_MessageIterator): end_clock_snapshot=None): utils._check_type(stream, bt2.stream._Stream) - if not stream.stream_class.supports_discarded_events: + if not stream.cls.supports_discarded_events: raise ValueError('stream class does not support discarded events') - if stream.stream_class.discarded_events_have_default_clock_snapshots: + if stream.cls.discarded_events_have_default_clock_snapshots: if beg_clock_snapshot is None or end_clock_snapshot is None: raise ValueError('discarded events have default clock snapshots for this stream class') @@ -307,10 +307,10 @@ class _UserMessageIterator(_MessageIterator): def _create_discarded_packets_message(self, stream, count=None, beg_clock_snapshot=None, end_clock_snapshot=None): utils._check_type(stream, bt2.stream._Stream) - if not stream.stream_class.supports_discarded_packets: + if not stream.cls.supports_discarded_packets: raise ValueError('stream class does not support discarded packets') - if stream.stream_class.discarded_packets_have_default_clock_snapshots: + if stream.cls.discarded_packets_have_default_clock_snapshots: if beg_clock_snapshot is None or end_clock_snapshot is None: raise ValueError('discarded packets have default clock snapshots for this stream class') diff --git a/bindings/python/bt2/bt2/stream.py b/bindings/python/bt2/bt2/stream.py index df304925..5accfcd0 100644 --- a/bindings/python/bt2/bt2/stream.py +++ b/bindings/python/bt2/bt2/stream.py @@ -31,7 +31,7 @@ class _Stream(bt2.object._SharedObject): _put_ref = staticmethod(native_bt.stream_put_ref) @property - def stream_class(self): + def cls(self): stream_class_ptr = native_bt.stream_borrow_class(self._ptr) assert stream_class_ptr is not None return bt2.stream_class._StreamClass._create_from_ptr_and_get_ref(stream_class_ptr) diff --git a/bindings/python/bt2/bt2/trace_collection_message_iterator.py b/bindings/python/bt2/bt2/trace_collection_message_iterator.py index 2185fcd5..10b555f1 100644 --- a/bindings/python/bt2/bt2/trace_collection_message_iterator.py +++ b/bindings/python/bt2/bt2/trace_collection_message_iterator.py @@ -34,11 +34,11 @@ _ComponentAndSpec = namedtuple('_ComponentAndSpec', ['comp', 'spec']) class ComponentSpec: - def __init__(self, plugin_name, component_class_name, params=None): + def __init__(self, plugin_name, class_name, params=None): utils._check_str(plugin_name) - utils._check_str(component_class_name) + utils._check_str(class_name) self._plugin_name = plugin_name - self._component_class_name = component_class_name + self._class_name = class_name if type(params) is str: self._params = bt2.create_value({'paths': [params]}) @@ -50,8 +50,8 @@ class ComponentSpec: return self._plugin_name @property - def component_class_name(self): - return self._component_class_name + def class_name(self): + return self._class_name @property def params(self): @@ -135,7 +135,7 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): # contains the stream intersection range for each exposed # trace query_exec = bt2.QueryExecutor() - trace_info_res = query_exec.query(src_comp_and_spec.comp.component_class, + trace_info_res = query_exec.query(src_comp_and_spec.comp.cls, 'trace-info', params) begin = None end = None @@ -197,7 +197,7 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): def _get_unique_comp_name(self, comp_spec): name = '{}-{}'.format(comp_spec.plugin_name, - comp_spec.component_class_name) + comp_spec.class_name) comps_and_specs = itertools.chain(self._src_comps_and_specs, self._flt_comps_and_specs) @@ -218,13 +218,13 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): else: comp_classes = plugin.filter_component_classes - if comp_spec.component_class_name not in comp_classes: + if comp_spec.class_name not in comp_classes: cc_type = 'source' if comp_cls_type == _CompClsType.SOURCE else 'filter' raise bt2.Error('no such {} component class in "{}" plugin: {}'.format(cc_type, comp_spec.plugin_name, - comp_spec.component_class_name)) + comp_spec.class_name)) - comp_cls = comp_classes[comp_spec.component_class_name] + comp_cls = comp_classes[comp_spec.class_name] name = self._get_unique_comp_name(comp_spec) comp = self._graph.add_component(comp_cls, name, comp_spec.params) return comp diff --git a/tests/bindings/python/bt2/test_component.py b/tests/bindings/python/bt2/test_component.py index 30523ecd..a01404e4 100644 --- a/tests/bindings/python/bt2/test_component.py +++ b/tests/bindings/python/bt2/test_component.py @@ -27,7 +27,7 @@ class UserComponentTestCase(unittest.TestCase): def test_class(self): class MySink(bt2._UserSinkComponent): def __init__(comp_self, params): - self.assertEqual(comp_self.component_class, MySink) + self.assertEqual(comp_self.cls, MySink) def _consume(self): pass @@ -88,7 +88,7 @@ class GenericComponentTestCase(unittest.TestCase): pass comp = self._create_comp(MySink) - self.assertEqual(comp.component_class, MySink) + self.assertEqual(comp.cls, MySink) def test_addr(self): class MySink(bt2._UserSinkComponent): diff --git a/tests/bindings/python/bt2/test_component_class.py b/tests/bindings/python/bt2/test_component_class.py index 432cc8a6..f7f5627d 100644 --- a/tests/bindings/python/bt2/test_component_class.py +++ b/tests/bindings/python/bt2/test_component_class.py @@ -288,7 +288,7 @@ class GenericComponentClassTestCase(unittest.TestCase): self._py_comp_cls = MySink graph = bt2.Graph() comp = graph.add_component(MySink, 'salut') - self._comp_cls = comp.component_class + self._comp_cls = comp.cls self.assertTrue(issubclass(type(self._comp_cls), bt2.component._GenericComponentClass)) diff --git a/tests/bindings/python/bt2/test_event.py b/tests/bindings/python/bt2/test_event.py index d420b33f..34a1447e 100644 --- a/tests/bindings/python/bt2/test_event.py +++ b/tests/bindings/python/bt2/test_event.py @@ -110,7 +110,7 @@ class EventTestCase(unittest.TestCase): def test_attr_event_class(self): msg = self._create_test_event_message() - self.assertEqual(msg.event.event_class.addr, self.event_class.addr) + self.assertEqual(msg.event.cls.addr, self.event_class.addr) def test_attr_name(self): msg = self._create_test_event_message() diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index 48e02873..bd1fec1a 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -56,7 +56,7 @@ class GraphTestCase(unittest.TestCase): comp = self._graph.add_component(MySink, 'salut') assert comp - comp2 = self._graph.add_component(comp.component_class, 'salut2') + comp2 = self._graph.add_component(comp.cls, 'salut2') self.assertEqual(comp2.name, 'salut2') def test_add_component_params(self): @@ -234,7 +234,7 @@ class GraphTestCase(unittest.TestCase): self.assertIsInstance(msg, bt2.message._PacketBeginningMessage) elif comp_self._at >= 2 and comp_self._at <= 6: self.assertIsInstance(msg, bt2.message._EventMessage) - self.assertEqual(msg.event.event_class.name, 'salut') + self.assertEqual(msg.event.cls.name, 'salut') elif comp_self._at == 7: self.assertIsInstance(msg, bt2.message._PacketEndMessage) elif comp_self._at == 8: diff --git a/tests/bindings/python/bt2/test_message.py b/tests/bindings/python/bt2/test_message.py index e9ef1587..5f11c9a9 100644 --- a/tests/bindings/python/bt2/test_message.py +++ b/tests/bindings/python/bt2/test_message.py @@ -120,7 +120,7 @@ class AllMessagesTestCase(unittest.TestCase): self.assertEqual(msg.default_clock_snapshot.value, i) elif i == 3: self.assertIsInstance(msg, bt2.message._EventMessage) - self.assertEqual(msg.event.event_class.addr, self._event_class.addr) + self.assertEqual(msg.event.cls.addr, self._event_class.addr) self.assertEqual(msg.default_clock_snapshot.value, i) elif i == 4: self.assertIsInstance(msg, bt2.message._MessageIteratorInactivityMessage) @@ -129,7 +129,7 @@ class AllMessagesTestCase(unittest.TestCase): self.assertIsInstance(msg, bt2.message._DiscardedEventsMessage) self.assertEqual(msg.stream.addr, self._stream.addr) self.assertEqual(msg.count, 890) - self.assertEqual(msg.stream.stream_class.default_clock_class.addr, self._clock_class.addr) + self.assertEqual(msg.stream.cls.default_clock_class.addr, self._clock_class.addr) self.assertEqual(msg.beginning_default_clock_snapshot.value, i) self.assertEqual(msg.end_default_clock_snapshot.value, i) elif i == 6: @@ -140,7 +140,7 @@ class AllMessagesTestCase(unittest.TestCase): self.assertIsInstance(msg, bt2.message._DiscardedPacketsMessage) self.assertEqual(msg.stream.addr, self._stream.addr) self.assertEqual(msg.count, 678) - self.assertEqual(msg.stream.stream_class.default_clock_class.addr, self._clock_class.addr) + self.assertEqual(msg.stream.cls.default_clock_class.addr, self._clock_class.addr) self.assertEqual(msg.beginning_default_clock_snapshot.value, i) self.assertEqual(msg.end_default_clock_snapshot.value, i) elif i == 8: @@ -171,14 +171,14 @@ class AllMessagesTestCase(unittest.TestCase): self.assertEqual(msg.packet.addr, self._packet.addr) elif i == 3: self.assertIsInstance(msg, bt2.message._EventMessage) - self.assertEqual(msg.event.event_class.addr, self._event_class.addr) + self.assertEqual(msg.event.cls.addr, self._event_class.addr) with self.assertRaises(bt2.NonexistentClockSnapshot): msg.default_clock_snapshot elif i == 4: self.assertIsInstance(msg, bt2.message._DiscardedEventsMessage) self.assertEqual(msg.stream.addr, self._stream.addr) self.assertEqual(msg.count, 890) - self.assertIsNone(msg.stream.stream_class.default_clock_class) + self.assertIsNone(msg.stream.cls.default_clock_class) with self.assertRaises(bt2.NonexistentClockSnapshot): msg.beginning_default_clock_snapshot with self.assertRaises(bt2.NonexistentClockSnapshot): @@ -190,7 +190,7 @@ class AllMessagesTestCase(unittest.TestCase): self.assertIsInstance(msg, bt2.message._DiscardedPacketsMessage) self.assertEqual(msg.stream.addr, self._stream.addr) self.assertEqual(msg.count, 678) - self.assertIsNone(msg.stream.stream_class.default_clock_class) + self.assertIsNone(msg.stream.cls.default_clock_class) with self.assertRaises(bt2.NonexistentClockSnapshot): msg.beginning_default_clock_snapshot with self.assertRaises(bt2.NonexistentClockSnapshot): diff --git a/tests/bindings/python/bt2/test_message_iterator.py b/tests/bindings/python/bt2/test_message_iterator.py index 9c8277b7..7a571797 100644 --- a/tests/bindings/python/bt2/test_message_iterator.py +++ b/tests/bindings/python/bt2/test_message_iterator.py @@ -167,6 +167,6 @@ class OutputPortMessageIteratorTestCase(unittest.TestCase): self.assertIsInstance(msg, bt2.message._StreamEndMessage) else: self.assertIsInstance(msg, bt2.message._EventMessage) - self.assertEqual(msg.event.event_class.name, 'salut') + self.assertEqual(msg.event.cls.name, 'salut') field = msg.event.payload_field['my_int'] self.assertEqual(field, at * 3) diff --git a/tests/bindings/python/bt2/test_stream.py b/tests/bindings/python/bt2/test_stream.py index 19874f23..2f6d1f42 100644 --- a/tests/bindings/python/bt2/test_stream.py +++ b/tests/bindings/python/bt2/test_stream.py @@ -25,7 +25,7 @@ class StreamTestCase(unittest.TestCase): def test_stream_class(self): stream = self._tr.create_stream(self._sc) - self.assertEqual(stream.stream_class, self._sc) + self.assertEqual(stream.cls, self._sc) def test_invalid_id(self): sc = self._tc.create_stream_class(assigns_automatic_stream_id=False) -- 2.34.1