From cfbd7cf3bde05e8a6606478889dcd663604ef7b5 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Thu, 18 Jul 2019 10:11:55 -0400 Subject: [PATCH] Apply black code formatter on all Python code Signed-off-by: Francis Deslauriers Change-Id: I2b66d32d12c93d353097b25d80050e4dcfe5b1ff Reviewed-on: https://review.lttng.org/c/babeltrace/+/1642 Tested-by: jenkins Reviewed-by: Philippe Proulx --- doc/bindings/python/source/conf.py | 5 +- src/bindings/python/bt2/bt2/__init__.py.in | 8 +- src/bindings/python/bt2/bt2/clock_class.py | 10 +- src/bindings/python/bt2/bt2/clock_snapshot.py | 5 +- src/bindings/python/bt2/bt2/component.py | 305 ++++++---- src/bindings/python/bt2/bt2/connection.py | 16 +- src/bindings/python/bt2/bt2/event.py | 18 +- src/bindings/python/bt2/bt2/event_class.py | 25 +- src/bindings/python/bt2/bt2/field.py | 78 ++- src/bindings/python/bt2/bt2/field_class.py | 195 +++++-- src/bindings/python/bt2/bt2/field_path.py | 4 +- src/bindings/python/bt2/bt2/graph.py | 92 +-- .../python/bt2/bt2/integer_range_set.py | 25 +- src/bindings/python/bt2/bt2/message.py | 77 ++- .../python/bt2/bt2/message_iterator.py | 130 +++-- src/bindings/python/bt2/bt2/object.py | 10 +- src/bindings/python/bt2/bt2/packet.py | 6 +- src/bindings/python/bt2/bt2/plugin.py | 60 +- src/bindings/python/bt2/bt2/port.py | 12 +- src/bindings/python/bt2/bt2/py_plugin.py | 19 +- src/bindings/python/bt2/bt2/query_executor.py | 22 +- src/bindings/python/bt2/bt2/stream.py | 8 +- src/bindings/python/bt2/bt2/stream_class.py | 111 ++-- src/bindings/python/bt2/bt2/trace.py | 23 +- src/bindings/python/bt2/bt2/trace_class.py | 159 +++-- .../bt2/trace_collection_message_iterator.py | 77 ++- src/bindings/python/bt2/bt2/utils.py | 18 +- src/bindings/python/bt2/bt2/value.py | 34 +- src/bindings/python/bt2/setup.py.in | 75 +-- tests/bindings/python/bt2/test_clock_class.py | 29 +- .../python/bt2/test_component_class.py | 50 +- tests/bindings/python/bt2/test_connection.py | 18 +- .../python/bt2/test_ctf_writer_clock.py | 221 ++++--- tests/bindings/python/bt2/test_event.py | 74 ++- tests/bindings/python/bt2/test_event_class.py | 12 +- tests/bindings/python/bt2/test_field.py | 544 ++++++++++++++---- tests/bindings/python/bt2/test_field_class.py | 137 +++-- tests/bindings/python/bt2/test_graph.py | 92 +-- .../python/bt2/test_integer_range_set.py | 12 +- tests/bindings/python/bt2/test_message.py | 112 ++-- .../python/bt2/test_message_iterator.py | 43 +- tests/bindings/python/bt2/test_packet.py | 10 +- tests/bindings/python/bt2/test_plugin.py | 12 +- tests/bindings/python/bt2/test_port.py | 95 ++- .../python/bt2/test_query_executor.py | 19 +- .../bindings/python/bt2/test_stream_class.py | 131 +++-- tests/bindings/python/bt2/test_trace_class.py | 13 +- .../test_trace_collection_message_iterator.py | 15 +- tests/bindings/python/bt2/test_value.py | 505 +++++++++++++--- tests/bindings/python/bt2/utils.py | 3 + .../bt_plugin_trimmer_test.py | 16 +- .../test_lttng_utils_debug_info.py | 9 +- .../src.ctf.fs/query/test_query_trace_info.py | 81 +-- .../bt_plugin_test_python_plugin_provider.py | 18 +- tests/utils/python/testrunner.py | 37 +- 55 files changed, 2672 insertions(+), 1263 deletions(-) diff --git a/doc/bindings/python/source/conf.py b/doc/bindings/python/source/conf.py index e39de7c6..84c05bbc 100644 --- a/doc/bindings/python/source/conf.py +++ b/doc/bindings/python/source/conf.py @@ -6,10 +6,7 @@ import os # general configuration needs_sphinx = '1.2' -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.ifconfig', -] +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.ifconfig'] templates_path = ['_templates'] source_suffix = '.rst' source_encoding = 'utf-8-sig' diff --git a/src/bindings/python/bt2/bt2/__init__.py.in b/src/bindings/python/bt2/bt2/__init__.py.in index 1e5b8ee3..49e02d4a 100644 --- a/src/bindings/python/bt2/bt2/__init__.py.in +++ b/src/bindings/python/bt2/bt2/__init__.py.in @@ -126,8 +126,12 @@ def _init_and_register_exit(): import atexit atexit.register(_native_bt.bt2_cc_exit_handler) - version = (_native_bt.version_get_major(), _native_bt.version_get_minor(), - _native_bt.version_get_patch(), _native_bt.version_get_extra()) + version = ( + _native_bt.version_get_major(), + _native_bt.version_get_minor(), + _native_bt.version_get_patch(), + _native_bt.version_get_extra(), + ) _native_bt.bt2_cc_init_from_bt2() diff --git a/src/bindings/python/bt2/bt2/clock_class.py b/src/bindings/python/bt2/bt2/clock_class.py index 6d0ff72a..932a2663 100644 --- a/src/bindings/python/bt2/bt2/clock_class.py +++ b/src/bindings/python/bt2/bt2/clock_class.py @@ -59,8 +59,7 @@ class _ClockClass(object._SharedObject): def _name(self, name): utils._check_str(name) status = native_bt.clock_class_set_name(self._ptr, name) - utils._handle_func_status(status, - "cannot set clock class object's name") + utils._handle_func_status(status, "cannot set clock class object's name") _name = property(fset=_name) @@ -71,8 +70,7 @@ class _ClockClass(object._SharedObject): def _description(self, description): utils._check_str(description) status = native_bt.clock_class_set_description(self._ptr, description) - utils._handle_func_status(status, - "cannot set clock class object's description") + utils._handle_func_status(status, "cannot set clock class object's description") _description = property(fset=_description) @@ -114,7 +112,9 @@ class _ClockClass(object._SharedObject): def _origin_is_unix_epoch(self, origin_is_unix_epoch): utils._check_bool(origin_is_unix_epoch) - native_bt.clock_class_set_origin_is_unix_epoch(self._ptr, int(origin_is_unix_epoch)) + native_bt.clock_class_set_origin_is_unix_epoch( + self._ptr, int(origin_is_unix_epoch) + ) _origin_is_unix_epoch = property(fset=_origin_is_unix_epoch) diff --git a/src/bindings/python/bt2/bt2/clock_snapshot.py b/src/bindings/python/bt2/bt2/clock_snapshot.py index adf03e39..5c53fdd7 100644 --- a/src/bindings/python/bt2/bt2/clock_snapshot.py +++ b/src/bindings/python/bt2/bt2/clock_snapshot.py @@ -41,8 +41,9 @@ class _ClockSnapshot(object._UniqueObject): @property def ns_from_origin(self): status, ns = native_bt.clock_snapshot_get_ns_from_origin(self._ptr) - utils._handle_func_status(status, - "cannot get clock snapshot's nanoseconds from origin") + utils._handle_func_status( + status, "cannot get clock snapshot's nanoseconds from origin" + ) return ns def __eq__(self, other): diff --git a/src/bindings/python/bt2/bt2/component.py b/src/bindings/python/bt2/bt2/component.py index 18b502ac..ef86bbcf 100644 --- a/src/bindings/python/bt2/bt2/component.py +++ b/src/bindings/python/bt2/bt2/component.py @@ -41,6 +41,7 @@ import os # - _bt_as_component_class_ptr: static method, convert the passed component class # pointer to a 'bt_component_class *'. + class _GenericComponentClass(object._SharedObject): @property def name(self): @@ -76,19 +77,25 @@ class _GenericComponentClass(object._SharedObject): class _GenericSourceComponentClass(_GenericComponentClass): _get_ref = staticmethod(native_bt.component_class_source_get_ref) _put_ref = staticmethod(native_bt.component_class_source_put_ref) - _bt_as_component_class_ptr = staticmethod(native_bt.component_class_source_as_component_class) + _bt_as_component_class_ptr = staticmethod( + native_bt.component_class_source_as_component_class + ) class _GenericFilterComponentClass(_GenericComponentClass): _get_ref = staticmethod(native_bt.component_class_filter_get_ref) _put_ref = staticmethod(native_bt.component_class_filter_put_ref) - _bt_as_component_class_ptr = staticmethod(native_bt.component_class_filter_as_component_class) + _bt_as_component_class_ptr = staticmethod( + native_bt.component_class_filter_as_component_class + ) class _GenericSinkComponentClass(_GenericComponentClass): _get_ref = staticmethod(native_bt.component_class_sink_get_ref) _put_ref = staticmethod(native_bt.component_class_sink_put_ref) - _bt_as_component_class_ptr = staticmethod(native_bt.component_class_sink_as_component_class) + _bt_as_component_class_ptr = staticmethod( + native_bt.component_class_sink_as_component_class + ) class _PortIterator(collections.abc.Iterator): @@ -119,11 +126,14 @@ class _ComponentPorts(collections.abc.Mapping): # bt_component_sink *. Its type must match the type expected by the # functions passed as arguments. - def __init__(self, component_ptr, - borrow_port_ptr_by_name, - borrow_port_ptr_at_index, - get_port_count, - port_pycls): + def __init__( + self, + component_ptr, + borrow_port_ptr_by_name, + borrow_port_ptr_at_index, + get_port_count, + port_pycls, + ): self._component_ptr = component_ptr self._borrow_port_ptr_by_name = borrow_port_ptr_by_name self._borrow_port_ptr_at_index = borrow_port_ptr_at_index @@ -161,6 +171,7 @@ class _ComponentPorts(collections.abc.Mapping): # - _bt_as_component_ptr: static method, must return the passed specialized # component pointer (e.g. 'bt_component_sink *') as a 'bt_component *'. + class _Component: @property def name(self): @@ -178,7 +189,9 @@ class _Component: def cls(self): cc_ptr = self._bt_borrow_component_class_ptr(self._ptr) assert cc_ptr is not None - return _create_component_class_from_ptr_and_get_ref(cc_ptr, self._bt_comp_cls_type) + return _create_component_class_from_ptr_and_get_ref( + cc_ptr, self._bt_comp_cls_type + ) def __eq__(self, other): if not hasattr(other, 'addr'): @@ -188,23 +201,35 @@ class _Component: class _SourceComponent(_Component): - _bt_borrow_component_class_ptr = staticmethod(native_bt.component_source_borrow_class_const) + _bt_borrow_component_class_ptr = staticmethod( + native_bt.component_source_borrow_class_const + ) _bt_comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_SOURCE - _bt_as_component_class_ptr = staticmethod(native_bt.component_class_source_as_component_class) + _bt_as_component_class_ptr = staticmethod( + native_bt.component_class_source_as_component_class + ) _bt_as_component_ptr = staticmethod(native_bt.component_source_as_component_const) class _FilterComponent(_Component): - _bt_borrow_component_class_ptr = staticmethod(native_bt.component_filter_borrow_class_const) + _bt_borrow_component_class_ptr = staticmethod( + native_bt.component_filter_borrow_class_const + ) _bt_comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_FILTER - _bt_as_component_class_ptr = staticmethod(native_bt.component_class_filter_as_component_class) + _bt_as_component_class_ptr = staticmethod( + native_bt.component_class_filter_as_component_class + ) _bt_as_component_ptr = staticmethod(native_bt.component_filter_as_component_const) class _SinkComponent(_Component): - _bt_borrow_component_class_ptr = staticmethod(native_bt.component_sink_borrow_class_const) + _bt_borrow_component_class_ptr = staticmethod( + native_bt.component_sink_borrow_class_const + ) _bt_comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_SINK - _bt_as_component_class_ptr = staticmethod(native_bt.component_class_sink_as_component_class) + _bt_as_component_class_ptr = staticmethod( + native_bt.component_class_sink_as_component_class + ) _bt_as_component_ptr = staticmethod(native_bt.component_sink_as_component_const) @@ -216,11 +241,13 @@ class _GenericSourceComponent(object._SharedObject, _SourceComponent): @property def output_ports(self): - return _ComponentPorts(self._ptr, - native_bt.component_source_borrow_output_port_by_name_const, - native_bt.component_source_borrow_output_port_by_index_const, - native_bt.component_source_get_output_port_count, - bt2.port._OutputPort) + return _ComponentPorts( + self._ptr, + native_bt.component_source_borrow_output_port_by_name_const, + native_bt.component_source_borrow_output_port_by_index_const, + native_bt.component_source_get_output_port_count, + bt2.port._OutputPort, + ) # This is analogous to _GenericFilterComponentClass, but for filter @@ -231,19 +258,23 @@ class _GenericFilterComponent(object._SharedObject, _FilterComponent): @property def output_ports(self): - return _ComponentPorts(self._ptr, - native_bt.component_filter_borrow_output_port_by_name_const, - native_bt.component_filter_borrow_output_port_by_index_const, - native_bt.component_filter_get_output_port_count, - bt2.port._OutputPort) + return _ComponentPorts( + self._ptr, + native_bt.component_filter_borrow_output_port_by_name_const, + native_bt.component_filter_borrow_output_port_by_index_const, + native_bt.component_filter_get_output_port_count, + bt2.port._OutputPort, + ) @property def input_ports(self): - return _ComponentPorts(self._ptr, - native_bt.component_filter_borrow_input_port_by_name_const, - native_bt.component_filter_borrow_input_port_by_index_const, - native_bt.component_filter_get_input_port_count, - bt2.port._InputPort) + return _ComponentPorts( + self._ptr, + native_bt.component_filter_borrow_input_port_by_name_const, + native_bt.component_filter_borrow_input_port_by_index_const, + native_bt.component_filter_get_input_port_count, + bt2.port._InputPort, + ) # This is analogous to _GenericSinkComponentClass, but for sink @@ -254,11 +285,13 @@ class _GenericSinkComponent(object._SharedObject, _SinkComponent): @property def input_ports(self): - return _ComponentPorts(self._ptr, - native_bt.component_sink_borrow_input_port_by_name_const, - native_bt.component_sink_borrow_input_port_by_index_const, - native_bt.component_sink_get_input_port_count, - bt2.port._InputPort) + return _ComponentPorts( + self._ptr, + native_bt.component_sink_borrow_input_port_by_name_const, + native_bt.component_sink_borrow_input_port_by_index_const, + native_bt.component_sink_get_input_port_count, + bt2.port._InputPort, + ) _COMP_CLS_TYPE_TO_GENERIC_COMP_PYCLS = { @@ -281,6 +314,7 @@ _COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS = { # # Steals the reference to ptr from the caller. + def _create_component_from_ptr(ptr, comp_cls_type): return _COMP_CLS_TYPE_TO_GENERIC_COMP_PYCLS[comp_cls_type]._create_from_ptr(ptr) @@ -288,8 +322,11 @@ def _create_component_from_ptr(ptr, comp_cls_type): # Same as the above, but acquire a new reference instead of stealing the # reference from the caller. + def _create_component_from_ptr_and_get_ref(ptr, comp_cls_type): - return _COMP_CLS_TYPE_TO_GENERIC_COMP_PYCLS[comp_cls_type]._create_from_ptr_and_get_ref(ptr) + return _COMP_CLS_TYPE_TO_GENERIC_COMP_PYCLS[ + comp_cls_type + ]._create_from_ptr_and_get_ref(ptr) # Create a component class Python object of type @@ -298,8 +335,11 @@ def _create_component_from_ptr_and_get_ref(ptr, comp_cls_type): # # Acquires a new reference to ptr. + def _create_component_class_from_ptr_and_get_ref(ptr, comp_cls_type): - return _COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS[comp_cls_type]._create_from_ptr_and_get_ref(ptr) + return _COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS[ + comp_cls_type + ]._create_from_ptr_and_get_ref(ptr) def _trim_docstring(docstring): @@ -432,32 +472,43 @@ class _UserComponentType(type): if _UserSourceComponent in bases: _UserComponentType._bt_set_iterator_class(cls, iter_cls) - cc_ptr = native_bt.bt2_component_class_source_create(cls, - comp_cls_name, - comp_cls_descr, - comp_cls_help) + cc_ptr = native_bt.bt2_component_class_source_create( + cls, comp_cls_name, comp_cls_descr, comp_cls_help + ) elif _UserFilterComponent in bases: _UserComponentType._bt_set_iterator_class(cls, iter_cls) - cc_ptr = native_bt.bt2_component_class_filter_create(cls, - comp_cls_name, - comp_cls_descr, - comp_cls_help) + cc_ptr = native_bt.bt2_component_class_filter_create( + cls, comp_cls_name, comp_cls_descr, comp_cls_help + ) elif _UserSinkComponent in bases: if not hasattr(cls, '_graph_is_configured'): - raise bt2.IncompleteUserClass("cannot create component class '{}': missing a _graph_is_configured() method".format(class_name)) + raise bt2.IncompleteUserClass( + "cannot create component class '{}': missing a _graph_is_configured() method".format( + class_name + ) + ) if not hasattr(cls, '_consume'): - raise bt2.IncompleteUserClass("cannot create component class '{}': missing a _consume() method".format(class_name)) - - cc_ptr = native_bt.bt2_component_class_sink_create(cls, - comp_cls_name, - comp_cls_descr, - comp_cls_help) + raise bt2.IncompleteUserClass( + "cannot create component class '{}': missing a _consume() method".format( + class_name + ) + ) + + cc_ptr = native_bt.bt2_component_class_sink_create( + cls, comp_cls_name, comp_cls_descr, comp_cls_help + ) else: - raise bt2.IncompleteUserClass("cannot find a known component class base in the bases of '{}'".format(class_name)) + raise bt2.IncompleteUserClass( + "cannot find a known component class base in the bases of '{}'".format( + class_name + ) + ) if cc_ptr is None: - raise bt2.CreationError("cannot create component class '{}'".format(class_name)) + raise bt2.CreationError( + "cannot create component class '{}'".format(class_name) + ) cls._bt_cc_ptr = cc_ptr @@ -478,18 +529,32 @@ class _UserComponentType(type): return self def __call__(cls, *args, **kwargs): - raise bt2.Error('cannot directly instantiate a user component from a Python module') + raise bt2.Error( + 'cannot directly instantiate a user component from a Python module' + ) @staticmethod def _bt_set_iterator_class(cls, iter_cls): if iter_cls is None: - raise bt2.IncompleteUserClass("cannot create component class '{}': missing message iterator class".format(cls.__name__)) + raise bt2.IncompleteUserClass( + "cannot create component class '{}': missing message iterator class".format( + cls.__name__ + ) + ) if not issubclass(iter_cls, bt2.message_iterator._UserMessageIterator): - raise bt2.IncompleteUserClass("cannot create component class '{}': message iterator class does not inherit bt2._UserMessageIterator".format(cls.__name__)) + raise bt2.IncompleteUserClass( + "cannot create component class '{}': message iterator class does not inherit bt2._UserMessageIterator".format( + cls.__name__ + ) + ) if not hasattr(iter_cls, '__next__'): - raise bt2.IncompleteUserClass("cannot create component class '{}': message iterator class is missing a __next__() method".format(cls.__name__)) + raise bt2.IncompleteUserClass( + "cannot create component class '{}': message iterator class is missing a __next__() method".format( + cls.__name__ + ) + ) cls._iter_cls = iter_cls @@ -520,8 +585,7 @@ class _UserComponentType(type): else: params = None - query_exec = bt2.QueryExecutor._create_from_ptr_and_get_ref( - query_exec_ptr) + query_exec = bt2.QueryExecutor._create_from_ptr_and_get_ref(query_exec_ptr) # this can raise, but the native side checks the exception results = cls._query(query_exec, obj, params, log_level) @@ -551,6 +615,7 @@ class _UserComponentType(type): cc_ptr = cls._bt_as_component_class_ptr(cls._bt_cc_ptr) native_bt.component_class_put_ref(cc_ptr) + # Subclasses must provide these methods or property: # # - _bt_as_not_self_specific_component_ptr: static method, must return the passed @@ -562,6 +627,7 @@ class _UserComponentType(type): # - _bt_comp_cls_type: property, one of the native_bt.COMPONENT_CLASS_TYPE_* # constants. + class _UserComponent(metaclass=_UserComponentType): @property def name(self): @@ -581,7 +647,9 @@ class _UserComponent(metaclass=_UserComponentType): def cls(self): comp_ptr = self._bt_as_not_self_specific_component_ptr(self._bt_ptr) cc_ptr = self._bt_borrow_component_class_ptr(comp_ptr) - return _create_component_class_from_ptr_and_get_ref(cc_ptr, self._bt_comp_cls_type) + return _create_component_class_from_ptr_and_get_ref( + cc_ptr, self._bt_comp_cls_type + ) @property def addr(self): @@ -596,9 +664,10 @@ class _UserComponent(metaclass=_UserComponentType): def _port_connected(self, port, other_port): pass - def _bt_port_connected_from_native(self, self_port_ptr, self_port_type, other_port_ptr): - port = bt2.port._create_self_from_ptr_and_get_ref( - self_port_ptr, self_port_type) + def _bt_port_connected_from_native( + self, self_port_ptr, self_port_type, other_port_ptr + ): + port = bt2.port._create_self_from_ptr_and_get_ref(self_port_ptr, self_port_type) if self_port_type == native_bt.PORT_TYPE_OUTPUT: other_port_type = native_bt.PORT_TYPE_INPUT @@ -606,7 +675,8 @@ class _UserComponent(metaclass=_UserComponentType): other_port_type = native_bt.PORT_TYPE_OUTPUT other_port = bt2.port._create_from_ptr_and_get_ref( - other_port_ptr, other_port_type) + other_port_ptr, other_port_type + ) self._port_connected(port, other_port) def _bt_graph_is_configured_from_native(self): @@ -624,9 +694,16 @@ class _UserComponent(metaclass=_UserComponentType): return tc - def _create_clock_class(self, frequency=None, name=None, description=None, - precision=None, offset=None, origin_is_unix_epoch=True, - uuid=None): + def _create_clock_class( + self, + frequency=None, + name=None, + description=None, + precision=None, + offset=None, + origin_is_unix_epoch=True, + uuid=None, + ): ptr = self._bt_as_self_component_ptr(self._bt_ptr) cc_ptr = native_bt.clock_class_create(ptr) @@ -659,8 +736,12 @@ class _UserComponent(metaclass=_UserComponentType): class _UserSourceComponent(_UserComponent, _SourceComponent): - _bt_as_not_self_specific_component_ptr = staticmethod(native_bt.self_component_source_as_component_source) - _bt_as_self_component_ptr = staticmethod(native_bt.self_component_source_as_self_component) + _bt_as_not_self_specific_component_ptr = staticmethod( + native_bt.self_component_source_as_component_source + ) + _bt_as_self_component_ptr = staticmethod( + native_bt.self_component_source_as_self_component + ) @property def _output_ports(self): @@ -668,25 +749,32 @@ class _UserSourceComponent(_UserComponent, _SourceComponent): ptr = self._bt_as_not_self_specific_component_ptr(self_ptr) return native_bt.component_source_get_output_port_count(ptr) - return _ComponentPorts(self._bt_ptr, - native_bt.self_component_source_borrow_output_port_by_name, - native_bt.self_component_source_borrow_output_port_by_index, - get_output_port_count, - bt2.port._UserComponentOutputPort) + return _ComponentPorts( + self._bt_ptr, + native_bt.self_component_source_borrow_output_port_by_name, + native_bt.self_component_source_borrow_output_port_by_index, + get_output_port_count, + bt2.port._UserComponentOutputPort, + ) def _add_output_port(self, name, user_data=None): utils._check_str(name) fn = native_bt.self_component_source_add_output_port comp_status, self_port_ptr = fn(self._bt_ptr, name, user_data) - utils._handle_func_status(comp_status, - 'cannot add output port to source component object') + utils._handle_func_status( + comp_status, 'cannot add output port to source component object' + ) assert self_port_ptr is not None return bt2.port._UserComponentOutputPort._create_from_ptr(self_port_ptr) class _UserFilterComponent(_UserComponent, _FilterComponent): - _bt_as_not_self_specific_component_ptr = staticmethod(native_bt.self_component_filter_as_component_filter) - _bt_as_self_component_ptr = staticmethod(native_bt.self_component_filter_as_self_component) + _bt_as_not_self_specific_component_ptr = staticmethod( + native_bt.self_component_filter_as_component_filter + ) + _bt_as_self_component_ptr = staticmethod( + native_bt.self_component_filter_as_self_component + ) @property def _output_ports(self): @@ -694,11 +782,13 @@ class _UserFilterComponent(_UserComponent, _FilterComponent): ptr = self._bt_as_not_self_specific_component_ptr(self_ptr) return native_bt.component_filter_get_output_port_count(ptr) - return _ComponentPorts(self._bt_ptr, - native_bt.self_component_filter_borrow_output_port_by_name, - native_bt.self_component_filter_borrow_output_port_by_index, - get_output_port_count, - bt2.port._UserComponentOutputPort) + return _ComponentPorts( + self._bt_ptr, + native_bt.self_component_filter_borrow_output_port_by_name, + native_bt.self_component_filter_borrow_output_port_by_index, + get_output_port_count, + bt2.port._UserComponentOutputPort, + ) @property def _input_ports(self): @@ -706,18 +796,21 @@ class _UserFilterComponent(_UserComponent, _FilterComponent): ptr = self._bt_as_not_self_specific_component_ptr(self_ptr) return native_bt.component_filter_get_input_port_count(ptr) - return _ComponentPorts(self._bt_ptr, - native_bt.self_component_filter_borrow_input_port_by_name, - native_bt.self_component_filter_borrow_input_port_by_index, - get_input_port_count, - bt2.port._UserComponentInputPort) + return _ComponentPorts( + self._bt_ptr, + native_bt.self_component_filter_borrow_input_port_by_name, + native_bt.self_component_filter_borrow_input_port_by_index, + get_input_port_count, + bt2.port._UserComponentInputPort, + ) def _add_output_port(self, name, user_data=None): utils._check_str(name) fn = native_bt.self_component_filter_add_output_port comp_status, self_port_ptr = fn(self._bt_ptr, name, user_data) - utils._handle_func_status(comp_status, - 'cannot add output port to filter component object') + utils._handle_func_status( + comp_status, 'cannot add output port to filter component object' + ) assert self_port_ptr return bt2.port._UserComponentOutputPort._create_from_ptr(self_port_ptr) @@ -725,15 +818,20 @@ class _UserFilterComponent(_UserComponent, _FilterComponent): utils._check_str(name) fn = native_bt.self_component_filter_add_input_port comp_status, self_port_ptr = fn(self._bt_ptr, name, user_data) - utils._handle_func_status(comp_status, - 'cannot add input port to filter component object') + utils._handle_func_status( + comp_status, 'cannot add input port to filter component object' + ) assert self_port_ptr return bt2.port._UserComponentInputPort._create_from_ptr(self_port_ptr) class _UserSinkComponent(_UserComponent, _SinkComponent): - _bt_as_not_self_specific_component_ptr = staticmethod(native_bt.self_component_sink_as_component_sink) - _bt_as_self_component_ptr = staticmethod(native_bt.self_component_sink_as_self_component) + _bt_as_not_self_specific_component_ptr = staticmethod( + native_bt.self_component_sink_as_component_sink + ) + _bt_as_self_component_ptr = staticmethod( + native_bt.self_component_sink_as_self_component + ) @property def _input_ports(self): @@ -741,17 +839,20 @@ class _UserSinkComponent(_UserComponent, _SinkComponent): ptr = self._bt_as_not_self_specific_component_ptr(self_ptr) return native_bt.component_sink_get_input_port_count(ptr) - return _ComponentPorts(self._bt_ptr, - native_bt.self_component_sink_borrow_input_port_by_name, - native_bt.self_component_sink_borrow_input_port_by_index, - get_input_port_count, - bt2.port._UserComponentInputPort) + return _ComponentPorts( + self._bt_ptr, + native_bt.self_component_sink_borrow_input_port_by_name, + native_bt.self_component_sink_borrow_input_port_by_index, + get_input_port_count, + bt2.port._UserComponentInputPort, + ) def _add_input_port(self, name, user_data=None): utils._check_str(name) fn = native_bt.self_component_sink_add_input_port comp_status, self_port_ptr = fn(self._bt_ptr, name, user_data) - utils._handle_func_status(comp_status, - 'cannot add input port to sink component object') + utils._handle_func_status( + comp_status, 'cannot add input port to sink component object' + ) assert self_port_ptr return bt2.port._UserComponentInputPort._create_from_ptr(self_port_ptr) diff --git a/src/bindings/python/bt2/bt2/connection.py b/src/bindings/python/bt2/bt2/connection.py index 4c52a776..9ffd7bb1 100644 --- a/src/bindings/python/bt2/bt2/connection.py +++ b/src/bindings/python/bt2/bt2/connection.py @@ -33,11 +33,19 @@ class _Connection(bt2.object._SharedObject): @property def downstream_port(self): port_ptr = native_bt.connection_borrow_downstream_port_const(self._ptr) - utils._handle_ptr(port_ptr, "cannot get connection object's downstream port object") - return bt2.port._create_from_ptr_and_get_ref(port_ptr, native_bt.PORT_TYPE_INPUT) + utils._handle_ptr( + port_ptr, "cannot get connection object's downstream port object" + ) + return bt2.port._create_from_ptr_and_get_ref( + port_ptr, native_bt.PORT_TYPE_INPUT + ) @property def upstream_port(self): port_ptr = native_bt.connection_borrow_upstream_port_const(self._ptr) - utils._handle_ptr(port_ptr, "cannot get connection object's upstream port object") - return bt2.port._create_from_ptr_and_get_ref(port_ptr, native_bt.PORT_TYPE_OUTPUT) + utils._handle_ptr( + port_ptr, "cannot get connection object's upstream port object" + ) + return bt2.port._create_from_ptr_and_get_ref( + port_ptr, native_bt.PORT_TYPE_OUTPUT + ) diff --git a/src/bindings/python/bt2/bt2/event.py b/src/bindings/python/bt2/bt2/event.py index 8864b1df..c8a7d320 100644 --- a/src/bindings/python/bt2/bt2/event.py +++ b/src/bindings/python/bt2/bt2/event.py @@ -67,9 +67,9 @@ class _Event(object._UniqueObject): if field_ptr is None: return - return bt2.field._create_field_from_ptr(field_ptr, self._owner_ptr, - self._owner_get_ref, - self._owner_put_ref) + return bt2.field._create_field_from_ptr( + field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref + ) @property def specific_context_field(self): @@ -78,9 +78,9 @@ class _Event(object._UniqueObject): if field_ptr is None: return - return bt2.field._create_field_from_ptr(field_ptr, self._owner_ptr, - self._owner_get_ref, - self._owner_put_ref) + return bt2.field._create_field_from_ptr( + field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref + ) @property def payload_field(self): @@ -89,9 +89,9 @@ class _Event(object._UniqueObject): if field_ptr is None: return - return bt2.field._create_field_from_ptr(field_ptr, self._owner_ptr, - self._owner_get_ref, - self._owner_put_ref) + return bt2.field._create_field_from_ptr( + field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref + ) def __getitem__(self, key): utils._check_str(key) diff --git a/src/bindings/python/bt2/bt2/event_class.py b/src/bindings/python/bt2/bt2/event_class.py index cb7cc73f..00aae1b1 100644 --- a/src/bindings/python/bt2/bt2/event_class.py +++ b/src/bindings/python/bt2/bt2/event_class.py @@ -113,14 +113,15 @@ class _EventClass(object._SharedObject): def _emf_uri(self, emf_uri): utils._check_str(emf_uri) status = native_bt.event_class_set_emf_uri(self._ptr, emf_uri) - utils._handle_func_status(status, - "cannot set event class object's EMF URI") + utils._handle_func_status(status, "cannot set event class object's EMF URI") _emf_uri = property(fset=_emf_uri) @property def specific_context_field_class(self): - fc_ptr = native_bt.event_class_borrow_specific_context_field_class_const(self._ptr) + fc_ptr = native_bt.event_class_borrow_specific_context_field_class_const( + self._ptr + ) if fc_ptr is None: return @@ -130,9 +131,12 @@ class _EventClass(object._SharedObject): def _specific_context_field_class(self, context_field_class): if context_field_class is not None: utils._check_type(context_field_class, bt2.field_class._StructureFieldClass) - status = native_bt.event_class_set_specific_context_field_class(self._ptr, context_field_class._ptr) - utils._handle_func_status(status, - "cannot set event class object's context field class") + status = native_bt.event_class_set_specific_context_field_class( + self._ptr, context_field_class._ptr + ) + utils._handle_func_status( + status, "cannot set event class object's context field class" + ) _specific_context_field_class = property(fset=_specific_context_field_class) @@ -148,9 +152,12 @@ class _EventClass(object._SharedObject): def _payload_field_class(self, payload_field_class): if payload_field_class is not None: utils._check_type(payload_field_class, bt2.field_class._StructureFieldClass) - status = native_bt.event_class_set_payload_field_class(self._ptr, payload_field_class._ptr) - utils._handle_func_status(status, - "cannot set event class object's payload field class") + status = native_bt.event_class_set_payload_field_class( + self._ptr, payload_field_class._ptr + ) + utils._handle_func_status( + status, "cannot set event class object's payload field class" + ) _payload_field_class = property(fset=_payload_field_class) diff --git a/src/bindings/python/bt2/bt2/field.py b/src/bindings/python/bt2/bt2/field.py index a1c2bf32..bb35300c 100644 --- a/src/bindings/python/bt2/bt2/field.py +++ b/src/bindings/python/bt2/bt2/field.py @@ -34,7 +34,8 @@ def _create_field_from_ptr(ptr, owner_ptr, owner_get_ref, owner_put_ref): utils._handle_ptr(field_class_ptr, "cannot get field object's class") typeid = native_bt.field_class_get_type(field_class_ptr) field = _TYPE_ID_TO_OBJ[typeid]._create_from_ptr_and_get_ref( - ptr, owner_ptr, owner_get_ref, owner_put_ref) + ptr, owner_ptr, owner_get_ref, owner_put_ref + ) return field @@ -42,6 +43,7 @@ def _create_field_from_ptr(ptr, owner_ptr, owner_get_ref, owner_put_ref): # currently selected field. If `field` is of any other type, return `field` # directly. + def _get_leaf_field(field): if not isinstance(field, _VariantField): return field @@ -83,7 +85,9 @@ class _NumericField(_Field): if isinstance(other, numbers.Complex): return complex(other) - raise TypeError("'{}' object is not a number object".format(other.__class__.__name__)) + raise TypeError( + "'{}' object is not a number object".format(other.__class__.__name__) + ) def __int__(self): return int(self._value) @@ -96,8 +100,11 @@ class _NumericField(_Field): def __lt__(self, other): if not isinstance(other, numbers.Number): - raise TypeError('unorderable types: {}() < {}()'.format(self.__class__.__name__, - other.__class__.__name__)) + raise TypeError( + 'unorderable types: {}() < {}()'.format( + self.__class__.__name__, other.__class__.__name__ + ) + ) return self._value < self._extract_value(other) @@ -280,8 +287,7 @@ class _EnumerationField(_IntegerField): @property def labels(self): status, labels = self._get_mapping_labels(self._ptr) - utils._handle_func_status(status, - "cannot get label for enumeration field") + utils._handle_func_status(status, "cannot get label for enumeration field") assert labels is not None return labels @@ -289,12 +295,16 @@ class _EnumerationField(_IntegerField): class _UnsignedEnumerationField(_EnumerationField, _UnsignedIntegerField): _NAME = 'Unsigned Enumeration' - _get_mapping_labels = staticmethod(native_bt.field_unsigned_enumeration_get_mapping_labels) + _get_mapping_labels = staticmethod( + native_bt.field_unsigned_enumeration_get_mapping_labels + ) class _SignedEnumerationField(_EnumerationField, _SignedIntegerField): _NAME = 'Signed Enumeration' - _get_mapping_labels = staticmethod(native_bt.field_signed_enumeration_get_mapping_labels) + _get_mapping_labels = staticmethod( + native_bt.field_signed_enumeration_get_mapping_labels + ) @functools.total_ordering @@ -347,8 +357,9 @@ class _StringField(_Field): def __iadd__(self, value): value = self._value_to_str(value) status = native_bt.field_string_append(self._ptr, value) - utils._handle_func_status(status, - "cannot append to string field object's value") + utils._handle_func_status( + status, "cannot append to string field object's value" + ) return self @@ -415,14 +426,16 @@ class _StructureField(_ContainerField, collections.abc.MutableMapping): def __getitem__(self, key): utils._check_str(key) - field_ptr = native_bt.field_structure_borrow_member_field_by_name(self._ptr, key) + field_ptr = native_bt.field_structure_borrow_member_field_by_name( + self._ptr, key + ) if field_ptr is None: raise KeyError(key) - return _create_field_from_ptr(field_ptr, self._owner_ptr, - self._owner_get_ref, - self._owner_put_ref) + return _create_field_from_ptr( + field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref + ) def member_at_index(self, index): utils._check_uint64(index) @@ -430,11 +443,13 @@ class _StructureField(_ContainerField, collections.abc.MutableMapping): if index >= len(self): raise IndexError - field_ptr = native_bt.field_structure_borrow_member_field_by_index(self._ptr, index) + field_ptr = native_bt.field_structure_borrow_member_field_by_index( + self._ptr, index + ) assert field_ptr is not None - return _create_field_from_ptr(field_ptr, self._owner_ptr, - self._owner_get_ref, - self._owner_put_ref) + return _create_field_from_ptr( + field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref + ) class _VariantField(_ContainerField, _Field): @@ -453,9 +468,9 @@ class _VariantField(_ContainerField, _Field): field_ptr = native_bt.field_variant_borrow_selected_option_field(self._ptr) utils._handle_ptr(field_ptr, "cannot get variant field's selected option") - return _create_field_from_ptr(field_ptr, self._owner_ptr, - self._owner_get_ref, - self._owner_put_ref) + return _create_field_from_ptr( + field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref + ) def _spec_eq(self, other): return _get_leaf_field(self) == other @@ -483,18 +498,24 @@ class _ArrayField(_ContainerField, _Field, collections.abc.MutableSequence): def __getitem__(self, index): if not isinstance(index, numbers.Integral): - raise TypeError("'{}' is not an integral number object: invalid index".format(index.__class__.__name__)) + raise TypeError( + "'{}' is not an integral number object: invalid index".format( + index.__class__.__name__ + ) + ) index = int(index) if index < 0 or index >= len(self): raise IndexError('{} field object index is out of range'.format(self._NAME)) - field_ptr = native_bt.field_array_borrow_element_field_by_index(self._ptr, index) - assert(field_ptr) - return _create_field_from_ptr(field_ptr, self._owner_ptr, - self._owner_get_ref, - self._owner_put_ref) + field_ptr = native_bt.field_array_borrow_element_field_by_index( + self._ptr, index + ) + assert field_ptr + return _create_field_from_ptr( + field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref + ) def __setitem__(self, index, value): # raises if index is somehow invalid @@ -536,8 +557,7 @@ class _StaticArrayField(_ArrayField, _Field): def _set_value(self, values): if len(self) != len(values): - raise ValueError( - 'expected length of value and array field to match') + raise ValueError('expected length of value and array field to match') for index, value in enumerate(values): if value is not None: diff --git a/src/bindings/python/bt2/bt2/field_class.py b/src/bindings/python/bt2/bt2/field_class.py index 80936539..1128e4df 100644 --- a/src/bindings/python/bt2/bt2/field_class.py +++ b/src/bindings/python/bt2/bt2/field_class.py @@ -46,14 +46,16 @@ class _FieldClass(object._SharedObject): def _check_create_status(self, ptr): if ptr is None: - raise bt2.CreationError('cannot create {} field class object'.format(self._NAME.lower())) + raise bt2.CreationError( + 'cannot create {} field class object'.format(self._NAME.lower()) + ) class _IntegerFieldClass(_FieldClass): @property def field_value_range(self): size = native_bt.field_class_integer_get_field_value_range(self._ptr) - assert(size >= 1) + assert size >= 1 return size def _field_value_range(self, size): @@ -65,22 +67,22 @@ class _IntegerFieldClass(_FieldClass): @property def preferred_display_base(self): - base = native_bt.field_class_integer_get_preferred_display_base( - self._ptr) - assert(base >= 0) + base = native_bt.field_class_integer_get_preferred_display_base(self._ptr) + assert base >= 0 return base def _preferred_display_base(self, base): utils._check_uint64(base) - if base not in (IntegerDisplayBase.BINARY, - IntegerDisplayBase.OCTAL, - IntegerDisplayBase.DECIMAL, - IntegerDisplayBase.HEXADECIMAL): + if base not in ( + IntegerDisplayBase.BINARY, + IntegerDisplayBase.OCTAL, + IntegerDisplayBase.DECIMAL, + IntegerDisplayBase.HEXADECIMAL, + ): raise ValueError("Display base is not a valid IntegerDisplayBase value") - native_bt.field_class_integer_set_preferred_display_base( - self._ptr, base) + native_bt.field_class_integer_set_preferred_display_base(self._ptr, base) _preferred_display_base = property(fset=_preferred_display_base) @@ -103,7 +105,8 @@ class _RealFieldClass(_FieldClass): def _is_single_precision(self, is_single_precision): utils._check_bool(is_single_precision) native_bt.field_class_real_set_is_single_precision( - self._ptr, is_single_precision) + self._ptr, is_single_precision + ) _is_single_precision = property(fset=_is_single_precision) @@ -113,7 +116,9 @@ class _RealFieldClass(_FieldClass): class _EnumerationFieldClassMapping: def __init__(self, mapping_ptr): base_mapping_ptr = self._as_enumeration_field_class_mapping_ptr(mapping_ptr) - self._label = native_bt.field_class_enumeration_mapping_get_label(base_mapping_ptr) + self._label = native_bt.field_class_enumeration_mapping_get_label( + base_mapping_ptr + ) assert self._label is not None ranges_ptr = self._mapping_borrow_ranges_ptr(mapping_ptr) assert ranges_ptr is not None @@ -130,14 +135,22 @@ class _EnumerationFieldClassMapping: class _UnsignedEnumerationFieldClassMapping(_EnumerationFieldClassMapping): _ranges_type = bt2.integer_range_set.UnsignedIntegerRangeSet - _as_enumeration_field_class_mapping_ptr = staticmethod(native_bt.field_class_unsigned_enumeration_mapping_as_mapping_const) - _mapping_borrow_ranges_ptr = staticmethod(native_bt.field_class_unsigned_enumeration_mapping_borrow_ranges_const) + _as_enumeration_field_class_mapping_ptr = staticmethod( + native_bt.field_class_unsigned_enumeration_mapping_as_mapping_const + ) + _mapping_borrow_ranges_ptr = staticmethod( + native_bt.field_class_unsigned_enumeration_mapping_borrow_ranges_const + ) class _SignedEnumerationFieldClassMapping(_EnumerationFieldClassMapping): _ranges_type = bt2.integer_range_set.SignedIntegerRangeSet - _as_enumeration_field_class_mapping_ptr = staticmethod(native_bt.field_class_signed_enumeration_mapping_as_mapping_const) - _mapping_borrow_ranges_ptr = staticmethod(native_bt.field_class_signed_enumeration_mapping_borrow_ranges_const) + _as_enumeration_field_class_mapping_ptr = staticmethod( + native_bt.field_class_signed_enumeration_mapping_as_mapping_const + ) + _mapping_borrow_ranges_ptr = staticmethod( + native_bt.field_class_signed_enumeration_mapping_borrow_ranges_const + ) class _EnumerationFieldClass(_IntegerFieldClass, collections.abc.Mapping): @@ -154,12 +167,15 @@ class _EnumerationFieldClass(_IntegerFieldClass, collections.abc.Mapping): raise bt2.Error("duplicate mapping label '{}'".format(label)) status = self._add_mapping(self._ptr, label, ranges._ptr) - utils._handle_func_status(status, - 'cannot add mapping to enumeration field class object') + utils._handle_func_status( + status, 'cannot add mapping to enumeration field class object' + ) def mappings_for_value(self, value): status, labels = self._get_mapping_labels_for_value(self._ptr, value) - utils._handle_func_status(status, 'cannot get mapping labels for value {}'.format(value)) + utils._handle_func_status( + status, 'cannot get mapping labels for value {}'.format(value) + ) return [self[label] for label in labels] def __iter__(self): @@ -183,20 +199,26 @@ class _EnumerationFieldClass(_IntegerFieldClass, collections.abc.Mapping): return self -class _UnsignedEnumerationFieldClass(_EnumerationFieldClass, _UnsignedIntegerFieldClass): +class _UnsignedEnumerationFieldClass( + _EnumerationFieldClass, _UnsignedIntegerFieldClass +): _NAME = 'Unsigned enumeration' _range_set_type = bt2.integer_range_set.UnsignedIntegerRangeSet _add_mapping = staticmethod(native_bt.field_class_unsigned_enumeration_add_mapping) @staticmethod def _get_mapping_by_index(enum_ptr, index): - mapping_ptr = native_bt.field_class_unsigned_enumeration_borrow_mapping_by_index_const(enum_ptr, index) + mapping_ptr = native_bt.field_class_unsigned_enumeration_borrow_mapping_by_index_const( + enum_ptr, index + ) assert mapping_ptr is not None return _UnsignedEnumerationFieldClassMapping(mapping_ptr) @staticmethod def _get_mapping_by_label(enum_ptr, label): - mapping_ptr = native_bt.field_class_unsigned_enumeration_borrow_mapping_by_label_const(enum_ptr, label) + mapping_ptr = native_bt.field_class_unsigned_enumeration_borrow_mapping_by_label_const( + enum_ptr, label + ) if mapping_ptr is None: return @@ -206,7 +228,9 @@ class _UnsignedEnumerationFieldClass(_EnumerationFieldClass, _UnsignedIntegerFie @staticmethod def _get_mapping_labels_for_value(enum_ptr, value): utils._check_uint64(value) - return native_bt.field_class_unsigned_enumeration_get_mapping_labels_for_value(enum_ptr, value) + return native_bt.field_class_unsigned_enumeration_get_mapping_labels_for_value( + enum_ptr, value + ) class _SignedEnumerationFieldClass(_EnumerationFieldClass, _SignedIntegerFieldClass): @@ -216,13 +240,17 @@ class _SignedEnumerationFieldClass(_EnumerationFieldClass, _SignedIntegerFieldCl @staticmethod def _get_mapping_by_index(enum_ptr, index): - mapping_ptr = native_bt.field_class_signed_enumeration_borrow_mapping_by_index_const(enum_ptr, index) + mapping_ptr = native_bt.field_class_signed_enumeration_borrow_mapping_by_index_const( + enum_ptr, index + ) assert mapping_ptr is not None return _SignedEnumerationFieldClassMapping(mapping_ptr) @staticmethod def _get_mapping_by_label(enum_ptr, label): - mapping_ptr = native_bt.field_class_signed_enumeration_borrow_mapping_by_label_const(enum_ptr, label) + mapping_ptr = native_bt.field_class_signed_enumeration_borrow_mapping_by_label_const( + enum_ptr, label + ) if mapping_ptr is None: return @@ -232,7 +260,9 @@ class _SignedEnumerationFieldClass(_EnumerationFieldClass, _SignedIntegerFieldCl @staticmethod def _get_mapping_labels_for_value(enum_ptr, value): utils._check_int64(value) - return native_bt.field_class_signed_enumeration_get_mapping_labels_for_value(enum_ptr, value) + return native_bt.field_class_signed_enumeration_get_mapping_labels_for_value( + enum_ptr, value + ) class _StringFieldClass(_FieldClass): @@ -263,9 +293,12 @@ class _StructureFieldClass(_FieldClass, collections.abc.Mapping): if name in self: raise bt2.Error("duplicate member name '{}'".format(name)) - status = native_bt.field_class_structure_append_member(self._ptr, name, field_class._ptr) - utils._handle_func_status(status, - 'cannot append member to structure field class object') + status = native_bt.field_class_structure_append_member( + self._ptr, name, field_class._ptr + ) + utils._handle_func_status( + status, 'cannot append member to structure field class object' + ) def __len__(self): count = native_bt.field_class_structure_get_member_count(self._ptr) @@ -276,16 +309,22 @@ class _StructureFieldClass(_FieldClass, collections.abc.Mapping): def _create_member_from_ptr(member_ptr): name = native_bt.field_class_structure_member_get_name(member_ptr) assert name is not None - fc_ptr = native_bt.field_class_structure_member_borrow_field_class_const(member_ptr) + fc_ptr = native_bt.field_class_structure_member_borrow_field_class_const( + member_ptr + ) assert fc_ptr is not None fc = _create_field_class_from_ptr_and_get_ref(fc_ptr) return _StructureFieldClassMember(name, fc) def __getitem__(self, key): if not isinstance(key, str): - raise TypeError("key must be a 'str' object, got '{}'".format(key.__class__.__name__)) + raise TypeError( + "key must be a 'str' object, got '{}'".format(key.__class__.__name__) + ) - member_ptr = native_bt.field_class_structure_borrow_member_by_name_const(self._ptr, key) + member_ptr = native_bt.field_class_structure_borrow_member_by_name_const( + self._ptr, key + ) if member_ptr is None: raise KeyError(key) @@ -294,7 +333,9 @@ class _StructureFieldClass(_FieldClass, collections.abc.Mapping): def __iter__(self): for idx in range(len(self)): - member_ptr = native_bt.field_class_structure_borrow_member_by_index_const(self._ptr, idx) + member_ptr = native_bt.field_class_structure_borrow_member_by_index_const( + self._ptr, idx + ) assert member_ptr is not None yield native_bt.field_class_structure_member_get_name(member_ptr) @@ -310,7 +351,9 @@ class _StructureFieldClass(_FieldClass, collections.abc.Mapping): if index >= len(self): raise IndexError - member_ptr = native_bt.field_class_structure_borrow_member_by_index_const(self._ptr, index) + member_ptr = native_bt.field_class_structure_borrow_member_by_index_const( + self._ptr, index + ) assert member_ptr is not None return self._create_member_from_ptr(member_ptr) @@ -341,8 +384,12 @@ class _VariantFieldClassWithSelectorOption(_VariantFieldClassOption): class _VariantFieldClass(_FieldClass, collections.abc.Mapping): _NAME = 'Variant' - _borrow_option_by_name_ptr = staticmethod(native_bt.field_class_variant_borrow_option_by_name_const) - _borrow_member_by_index_ptr = staticmethod(native_bt.field_class_variant_borrow_option_by_index_const) + _borrow_option_by_name_ptr = staticmethod( + native_bt.field_class_variant_borrow_option_by_name_const + ) + _borrow_member_by_index_ptr = staticmethod( + native_bt.field_class_variant_borrow_option_by_index_const + ) @staticmethod def _as_option_ptr(opt_ptr): @@ -363,7 +410,9 @@ class _VariantFieldClass(_FieldClass, collections.abc.Mapping): def __getitem__(self, key): if not isinstance(key, str): - raise TypeError("key must be a 'str' object, got '{}'".format(key.__class__.__name__)) + raise TypeError( + "key must be a 'str' object, got '{}'".format(key.__class__.__name__) + ) opt_ptr = self._borrow_option_by_name_ptr(self._ptr, key) @@ -400,9 +449,12 @@ class _VariantFieldClassWithoutSelector(_VariantFieldClass): if name in self: raise bt2.Error("duplicate option name '{}'".format(name)) - status = native_bt.field_class_variant_without_selector_append_option(self._ptr, name, field_class._ptr) - utils._handle_func_status(status, - 'cannot append option to variant field class object') + status = native_bt.field_class_variant_without_selector_append_option( + self._ptr, name, field_class._ptr + ) + utils._handle_func_status( + status, 'cannot append option to variant field class object' + ) def __iadd__(self, options): for name, field_class in options: @@ -418,7 +470,9 @@ class _VariantFieldClassWithSelector(_VariantFieldClass): base_opt_ptr = self._as_option_ptr(opt_ptr) name = native_bt.field_class_variant_option_get_name(base_opt_ptr) assert name is not None - fc_ptr = native_bt.field_class_variant_option_borrow_field_class_const(base_opt_ptr) + fc_ptr = native_bt.field_class_variant_option_borrow_field_class_const( + base_opt_ptr + ) assert fc_ptr is not None fc = _create_field_class_from_ptr_and_get_ref(fc_ptr) range_set_ptr = self._option_borrow_ranges_ptr(opt_ptr) @@ -428,7 +482,9 @@ class _VariantFieldClassWithSelector(_VariantFieldClass): @property def selector_field_path(self): - ptr = native_bt.field_class_variant_with_selector_borrow_selector_field_path_const(self._ptr) + ptr = native_bt.field_class_variant_with_selector_borrow_selector_field_path_const( + self._ptr + ) if ptr is None: return @@ -449,8 +505,9 @@ class _VariantFieldClassWithSelector(_VariantFieldClass): # TODO: check overlaps (precondition of self._append_option()) status = self._append_option(self._ptr, name, field_class._ptr, ranges._ptr) - utils._handle_func_status(status, - 'cannot append option to variant field class object') + utils._handle_func_status( + status, 'cannot append option to variant field class object' + ) def __iadd__(self, options): for name, field_class, ranges in options: @@ -461,28 +518,50 @@ class _VariantFieldClassWithSelector(_VariantFieldClass): class _VariantFieldClassWithUnsignedSelector(_VariantFieldClassWithSelector): _NAME = 'Variant (with unsigned selector)' - _borrow_option_by_name_ptr = staticmethod(native_bt.field_class_variant_with_unsigned_selector_borrow_option_by_name_const) - _borrow_member_by_index_ptr = staticmethod(native_bt.field_class_variant_with_unsigned_selector_borrow_option_by_index_const) - _as_option_ptr = staticmethod(native_bt.field_class_variant_with_unsigned_selector_option_as_option_const) - _append_option = staticmethod(native_bt.field_class_variant_with_unsigned_selector_append_option) - _option_borrow_ranges_ptr = staticmethod(native_bt.field_class_variant_with_unsigned_selector_option_borrow_ranges_const) + _borrow_option_by_name_ptr = staticmethod( + native_bt.field_class_variant_with_unsigned_selector_borrow_option_by_name_const + ) + _borrow_member_by_index_ptr = staticmethod( + native_bt.field_class_variant_with_unsigned_selector_borrow_option_by_index_const + ) + _as_option_ptr = staticmethod( + native_bt.field_class_variant_with_unsigned_selector_option_as_option_const + ) + _append_option = staticmethod( + native_bt.field_class_variant_with_unsigned_selector_append_option + ) + _option_borrow_ranges_ptr = staticmethod( + native_bt.field_class_variant_with_unsigned_selector_option_borrow_ranges_const + ) _range_set_type = bt2.integer_range_set.UnsignedIntegerRangeSet class _VariantFieldClassWithSignedSelector(_VariantFieldClassWithSelector): _NAME = 'Variant (with signed selector)' - _borrow_option_by_name_ptr = staticmethod(native_bt.field_class_variant_with_signed_selector_borrow_option_by_name_const) - _borrow_member_by_index_ptr = staticmethod(native_bt.field_class_variant_with_signed_selector_borrow_option_by_index_const) - _as_option_ptr = staticmethod(native_bt.field_class_variant_with_signed_selector_option_as_option_const) - _append_option = staticmethod(native_bt.field_class_variant_with_signed_selector_append_option) - _option_borrow_ranges_ptr = staticmethod(native_bt.field_class_variant_with_signed_selector_option_borrow_ranges_const) + _borrow_option_by_name_ptr = staticmethod( + native_bt.field_class_variant_with_signed_selector_borrow_option_by_name_const + ) + _borrow_member_by_index_ptr = staticmethod( + native_bt.field_class_variant_with_signed_selector_borrow_option_by_index_const + ) + _as_option_ptr = staticmethod( + native_bt.field_class_variant_with_signed_selector_option_as_option_const + ) + _append_option = staticmethod( + native_bt.field_class_variant_with_signed_selector_append_option + ) + _option_borrow_ranges_ptr = staticmethod( + native_bt.field_class_variant_with_signed_selector_option_borrow_ranges_const + ) _range_set_type = bt2.integer_range_set.SignedIntegerRangeSet class _ArrayFieldClass(_FieldClass): @property def element_field_class(self): - elem_fc_ptr = native_bt.field_class_array_borrow_element_field_class_const(self._ptr) + elem_fc_ptr = native_bt.field_class_array_borrow_element_field_class_const( + self._ptr + ) return _create_field_class_from_ptr_and_get_ref(elem_fc_ptr) @@ -495,7 +574,9 @@ class _StaticArrayFieldClass(_ArrayFieldClass): class _DynamicArrayFieldClass(_ArrayFieldClass): @property def length_field_path(self): - ptr = native_bt.field_class_dynamic_array_borrow_length_field_path_const(self._ptr) + ptr = native_bt.field_class_dynamic_array_borrow_length_field_path_const( + self._ptr + ) if ptr is None: return diff --git a/src/bindings/python/bt2/bt2/field_path.py b/src/bindings/python/bt2/bt2/field_path.py index 2191171e..2df37015 100644 --- a/src/bindings/python/bt2/bt2/field_path.py +++ b/src/bindings/python/bt2/bt2/field_path.py @@ -69,7 +69,7 @@ class _FieldPath(object._SharedObject, collections.abc.Iterable): idx = native_bt.field_path_item_index_get_index(item_ptr) yield _IndexFieldPathItem(idx) elif item_type == native_bt.FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT: - yield _CurrentArrayElementFieldPathItem() + yield _CurrentArrayElementFieldPathItem() else: assert False @@ -78,5 +78,5 @@ _SCOPE_TO_OBJ = { native_bt.SCOPE_PACKET_CONTEXT: Scope.PACKET_CONTEXT, native_bt.SCOPE_EVENT_COMMON_CONTEXT: Scope.EVENT_COMMON_CONTEXT, native_bt.SCOPE_EVENT_SPECIFIC_CONTEXT: Scope.EVENT_SPECIFIC_CONTEXT, - native_bt.SCOPE_EVENT_PAYLOAD: Scope.EVENT_PAYLOAD + native_bt.SCOPE_EVENT_PAYLOAD: Scope.EVENT_PAYLOAD, } diff --git a/src/bindings/python/bt2/bt2/graph.py b/src/bindings/python/bt2/bt2/graph.py index 9e30c18f..1f280ba1 100644 --- a/src/bindings/python/bt2/bt2/graph.py +++ b/src/bindings/python/bt2/bt2/graph.py @@ -29,28 +29,40 @@ import bt2.logging import bt2 -def _graph_port_added_listener_from_native(user_listener, - component_ptr, component_type, - port_ptr, port_type): - component = bt2.component._create_component_from_ptr_and_get_ref(component_ptr, component_type) +def _graph_port_added_listener_from_native( + user_listener, component_ptr, component_type, port_ptr, port_type +): + component = bt2.component._create_component_from_ptr_and_get_ref( + component_ptr, component_type + ) port = bt2.port._create_from_ptr_and_get_ref(port_ptr, port_type) user_listener(component, port) -def _graph_ports_connected_listener_from_native(user_listener, - upstream_component_ptr, upstream_component_type, - upstream_port_ptr, - downstream_component_ptr, downstream_component_type, - downstream_port_ptr): +def _graph_ports_connected_listener_from_native( + user_listener, + upstream_component_ptr, + upstream_component_type, + upstream_port_ptr, + downstream_component_ptr, + downstream_component_type, + downstream_port_ptr, +): upstream_component = bt2.component._create_component_from_ptr_and_get_ref( - upstream_component_ptr, upstream_component_type) + upstream_component_ptr, upstream_component_type + ) upstream_port = bt2.port._create_from_ptr_and_get_ref( - upstream_port_ptr, native_bt.PORT_TYPE_OUTPUT) + upstream_port_ptr, native_bt.PORT_TYPE_OUTPUT + ) downstream_component = bt2.component._create_component_from_ptr_and_get_ref( - downstream_component_ptr, downstream_component_type) + downstream_component_ptr, downstream_component_type + ) downstream_port = bt2.port._create_from_ptr_and_get_ref( - downstream_port_ptr, native_bt.PORT_TYPE_INPUT) - user_listener(upstream_component, upstream_port, downstream_component, downstream_port) + downstream_port_ptr, native_bt.PORT_TYPE_INPUT + ) + user_listener( + upstream_component, upstream_port, downstream_component, downstream_port + ) class Graph(object._SharedObject): @@ -65,9 +77,13 @@ class Graph(object._SharedObject): super().__init__(ptr) - - def add_component(self, component_class, name, params=None, - logging_level=bt2.logging.LoggingLevel.NONE): + def add_component( + self, + component_class, + name, + params=None, + logging_level=bt2.logging.LoggingLevel.NONE, + ): if isinstance(component_class, bt2.component._GenericSourceComponentClass): cc_ptr = component_class._ptr add_fn = native_bt.graph_add_source_component @@ -93,8 +109,11 @@ class Graph(object._SharedObject): add_fn = native_bt.graph_add_filter_component cc_type = native_bt.COMPONENT_CLASS_TYPE_FILTER else: - raise TypeError("'{}' is not a component class".format( - component_class.__class__.__name__)) + raise TypeError( + "'{}' is not a component class".format( + component_class.__class__.__name__ + ) + ) utils._check_str(name) utils._check_log_level(logging_level) @@ -102,8 +121,7 @@ class Graph(object._SharedObject): params_ptr = params._ptr if params is not None else None - status, comp_ptr = add_fn(self._ptr, cc_ptr, name, - params_ptr, logging_level) + status, comp_ptr = add_fn(self._ptr, cc_ptr, name, params_ptr, logging_level) utils._handle_func_status(status, 'cannot add component to graph') assert comp_ptr return bt2.component._create_component_from_ptr(comp_ptr, cc_type) @@ -111,12 +129,11 @@ class Graph(object._SharedObject): def connect_ports(self, upstream_port, downstream_port): utils._check_type(upstream_port, bt2.port._OutputPort) utils._check_type(downstream_port, bt2.port._InputPort) - status, conn_ptr = native_bt.graph_connect_ports(self._ptr, - upstream_port._ptr, - downstream_port._ptr) - utils._handle_func_status(status, - 'cannot connect component ports within graph') - assert(conn_ptr) + status, conn_ptr = native_bt.graph_connect_ports( + self._ptr, upstream_port._ptr, downstream_port._ptr + ) + utils._handle_func_status(status, 'cannot connect component ports within graph') + assert conn_ptr return bt2.connection._Connection._create_from_ptr(conn_ptr) def add_port_added_listener(self, listener): @@ -124,8 +141,9 @@ class Graph(object._SharedObject): raise TypeError("'listener' parameter is not callable") fn = native_bt.bt2_graph_add_port_added_listener - listener_from_native = functools.partial(_graph_port_added_listener_from_native, - listener) + listener_from_native = functools.partial( + _graph_port_added_listener_from_native, listener + ) listener_ids = fn(self._ptr, listener_from_native) if listener_ids is None: @@ -137,8 +155,9 @@ class Graph(object._SharedObject): raise TypeError("'listener' parameter is not callable") fn = native_bt.bt2_graph_add_ports_connected_listener - listener_from_native = functools.partial(_graph_ports_connected_listener_from_native, - listener) + listener_from_native = functools.partial( + _graph_ports_connected_listener_from_native, listener + ) listener_ids = fn(self._ptr, listener_from_native) if listener_ids is None: @@ -149,8 +168,9 @@ class Graph(object._SharedObject): status = native_bt.graph_run(self._ptr) try: - utils._handle_func_status(status, - 'graph object stopped running because of an unexpected error') + utils._handle_func_status( + status, 'graph object stopped running because of an unexpected error' + ) except bt2.Stop: # done return @@ -164,12 +184,14 @@ class Graph(object._SharedObject): @property def is_canceled(self): is_canceled = native_bt.graph_is_canceled(self._ptr) - assert(is_canceled >= 0) + assert is_canceled >= 0 return is_canceled > 0 def create_output_port_message_iterator(self, output_port): utils._check_type(output_port, bt2.port._OutputPort) - msg_iter_ptr = native_bt.port_output_message_iterator_create(self._ptr, output_port._ptr) + msg_iter_ptr = native_bt.port_output_message_iterator_create( + self._ptr, output_port._ptr + ) if msg_iter_ptr is None: raise bt2.CreationError('cannot create output port message iterator') diff --git a/src/bindings/python/bt2/bt2/integer_range_set.py b/src/bindings/python/bt2/bt2/integer_range_set.py index 2e79da04..f7222fef 100644 --- a/src/bindings/python/bt2/bt2/integer_range_set.py +++ b/src/bindings/python/bt2/bt2/integer_range_set.py @@ -31,7 +31,11 @@ class _IntegerRange: self._check_type(upper) if lower > upper: - raise ValueError("range's lower bound ({}) is greater than its upper bound ({})".format(lower, upper)) + raise ValueError( + "range's lower bound ({}) is greater than its upper bound ({})".format( + lower, upper + ) + ) self._lower = lower self._upper = upper @@ -117,8 +121,7 @@ class _IntegerRangeSet(object._SharedObject, collections.abc.MutableSet): rg = self._range_type(rg[0], rg[1]) status = self._add_range(self._ptr, rg.lower, rg.upper) - utils._handle_func_status(status, - 'cannot add range to range set object') + utils._handle_func_status(status, 'cannot add range to range set object') def discard(self, rg): raise NotImplementedError @@ -127,9 +130,13 @@ class _IntegerRangeSet(object._SharedObject, collections.abc.MutableSet): class SignedIntegerRangeSet(_IntegerRangeSet): _get_ref = staticmethod(native_bt.integer_range_set_signed_get_ref) _put_ref = staticmethod(native_bt.integer_range_set_signed_put_ref) - _as_range_set_ptr = staticmethod(native_bt.integer_range_set_signed_as_range_set_const) + _as_range_set_ptr = staticmethod( + native_bt.integer_range_set_signed_as_range_set_const + ) _create_range_set = staticmethod(native_bt.integer_range_set_signed_create) - _borrow_range_by_index_ptr = staticmethod(native_bt.integer_range_set_signed_borrow_range_by_index_const) + _borrow_range_by_index_ptr = staticmethod( + native_bt.integer_range_set_signed_borrow_range_by_index_const + ) _range_get_lower = staticmethod(native_bt.integer_range_signed_get_lower) _range_get_upper = staticmethod(native_bt.integer_range_signed_get_upper) _add_range = staticmethod(native_bt.integer_range_set_signed_add_range) @@ -140,9 +147,13 @@ class SignedIntegerRangeSet(_IntegerRangeSet): class UnsignedIntegerRangeSet(_IntegerRangeSet): _get_ref = staticmethod(native_bt.integer_range_set_unsigned_get_ref) _put_ref = staticmethod(native_bt.integer_range_set_unsigned_put_ref) - _as_range_set_ptr = staticmethod(native_bt.integer_range_set_unsigned_as_range_set_const) + _as_range_set_ptr = staticmethod( + native_bt.integer_range_set_unsigned_as_range_set_const + ) _create_range_set = staticmethod(native_bt.integer_range_set_unsigned_create) - _borrow_range_by_index_ptr = staticmethod(native_bt.integer_range_set_unsigned_borrow_range_by_index_const) + _borrow_range_by_index_ptr = staticmethod( + native_bt.integer_range_set_unsigned_borrow_range_by_index_const + ) _range_get_lower = staticmethod(native_bt.integer_range_unsigned_get_lower) _range_get_upper = staticmethod(native_bt.integer_range_unsigned_get_upper) _add_range = staticmethod(native_bt.integer_range_set_unsigned_add_range) diff --git a/src/bindings/python/bt2/bt2/message.py b/src/bindings/python/bt2/bt2/message.py index a2e885b8..35cb1bbe 100644 --- a/src/bindings/python/bt2/bt2/message.py +++ b/src/bindings/python/bt2/bt2/message.py @@ -44,7 +44,9 @@ class _Message(object._SharedObject): @staticmethod def _check_has_default_clock_class(clock_class): if clock_class is None: - raise bt2.NonexistentClockSnapshot('cannot get default clock snapshot: stream class has no default clock class') + raise bt2.NonexistentClockSnapshot( + 'cannot get default clock snapshot: stream class has no default clock class' + ) class _MessageWithDefaultClockSnapshot: @@ -52,11 +54,14 @@ class _MessageWithDefaultClockSnapshot: snapshot_ptr = borrow_clock_snapshot_ptr(self._ptr) return bt2.clock_snapshot._ClockSnapshot._create_from_ptr_and_get_ref( - snapshot_ptr, self._ptr, self._get_ref, self._put_ref) + snapshot_ptr, self._ptr, self._get_ref, self._put_ref + ) class _EventMessage(_Message, _MessageWithDefaultClockSnapshot): - _borrow_default_clock_snapshot_ptr = staticmethod(native_bt.message_event_borrow_default_clock_snapshot_const) + _borrow_default_clock_snapshot_ptr = staticmethod( + native_bt.message_event_borrow_default_clock_snapshot_const + ) @property def default_clock_snapshot(self): @@ -68,7 +73,8 @@ class _EventMessage(_Message, _MessageWithDefaultClockSnapshot): event_ptr = native_bt.message_event_borrow_event(self._ptr) assert event_ptr is not None return bt2.event._Event._create_from_ptr_and_get_ref( - event_ptr, self._ptr, self._get_ref, self._put_ref) + event_ptr, self._ptr, self._get_ref, self._put_ref + ) class _PacketMessage(_Message, _MessageWithDefaultClockSnapshot): @@ -86,12 +92,16 @@ class _PacketMessage(_Message, _MessageWithDefaultClockSnapshot): class _PacketBeginningMessage(_PacketMessage): _borrow_packet_ptr = staticmethod(native_bt.message_packet_beginning_borrow_packet) - _borrow_default_clock_snapshot_ptr = staticmethod(native_bt.message_packet_beginning_borrow_default_clock_snapshot_const) + _borrow_default_clock_snapshot_ptr = staticmethod( + native_bt.message_packet_beginning_borrow_default_clock_snapshot_const + ) class _PacketEndMessage(_PacketMessage): _borrow_packet_ptr = staticmethod(native_bt.message_packet_end_borrow_packet) - _borrow_default_clock_snapshot_ptr = staticmethod(native_bt.message_packet_end_borrow_default_clock_snapshot_const) + _borrow_default_clock_snapshot_ptr = staticmethod( + native_bt.message_packet_end_borrow_default_clock_snapshot_const + ) class _StreamMessage(_Message, _MessageWithDefaultClockSnapshot): @@ -111,7 +121,8 @@ class _StreamMessage(_Message, _MessageWithDefaultClockSnapshot): return bt2.clock_snapshot._UnknownClockSnapshot() return bt2.clock_snapshot._ClockSnapshot._create_from_ptr_and_get_ref( - snapshot_ptr, self._ptr, self._get_ref, self._put_ref) + snapshot_ptr, self._ptr, self._get_ref, self._put_ref + ) def _default_clock_snapshot(self, raw_value): utils._check_uint64(raw_value) @@ -122,18 +133,28 @@ class _StreamMessage(_Message, _MessageWithDefaultClockSnapshot): class _StreamBeginningMessage(_StreamMessage): _borrow_stream_ptr = staticmethod(native_bt.message_stream_beginning_borrow_stream) - _borrow_default_clock_snapshot_ptr = staticmethod(native_bt.message_stream_beginning_borrow_default_clock_snapshot_const) - _set_default_clock_snapshot = staticmethod(native_bt.message_stream_beginning_set_default_clock_snapshot) + _borrow_default_clock_snapshot_ptr = staticmethod( + native_bt.message_stream_beginning_borrow_default_clock_snapshot_const + ) + _set_default_clock_snapshot = staticmethod( + native_bt.message_stream_beginning_set_default_clock_snapshot + ) class _StreamEndMessage(_StreamMessage): _borrow_stream_ptr = staticmethod(native_bt.message_stream_end_borrow_stream) - _borrow_default_clock_snapshot_ptr = staticmethod(native_bt.message_stream_end_borrow_default_clock_snapshot_const) - _set_default_clock_snapshot = staticmethod(native_bt.message_stream_end_set_default_clock_snapshot) + _borrow_default_clock_snapshot_ptr = staticmethod( + native_bt.message_stream_end_borrow_default_clock_snapshot_const + ) + _set_default_clock_snapshot = staticmethod( + native_bt.message_stream_end_set_default_clock_snapshot + ) class _MessageIteratorInactivityMessage(_Message, _MessageWithDefaultClockSnapshot): - _borrow_default_clock_snapshot_ptr = staticmethod(native_bt.message_message_iterator_inactivity_borrow_default_clock_snapshot_const) + _borrow_default_clock_snapshot_ptr = staticmethod( + native_bt.message_message_iterator_inactivity_borrow_default_clock_snapshot_const + ) @property def default_clock_snapshot(self): @@ -163,12 +184,16 @@ class _DiscardedMessage(_Message, _MessageWithDefaultClockSnapshot): def _check_has_default_clock_snapshots(self): if not self._has_default_clock_snapshots: - raise bt2.NonexistentClockSnapshot('cannot get default clock snapshot: such a message has no clock snapshots for this stream class') + raise bt2.NonexistentClockSnapshot( + 'cannot get default clock snapshot: such a message has no clock snapshots for this stream class' + ) @property def beginning_default_clock_snapshot(self): self._check_has_default_clock_snapshots() - return self._get_default_clock_snapshot(self._borrow_beginning_clock_snapshot_ptr) + return self._get_default_clock_snapshot( + self._borrow_beginning_clock_snapshot_ptr + ) @property def end_default_clock_snapshot(self): @@ -177,11 +202,17 @@ class _DiscardedMessage(_Message, _MessageWithDefaultClockSnapshot): class _DiscardedEventsMessage(_DiscardedMessage): - _borrow_stream_ptr = staticmethod(native_bt.message_discarded_events_borrow_stream_const) + _borrow_stream_ptr = staticmethod( + native_bt.message_discarded_events_borrow_stream_const + ) _get_count = staticmethod(native_bt.message_discarded_events_get_count) _set_count = staticmethod(native_bt.message_discarded_events_set_count) - _borrow_beginning_clock_snapshot_ptr = staticmethod(native_bt.message_discarded_events_borrow_beginning_default_clock_snapshot_const) - _borrow_end_clock_snapshot_ptr = staticmethod(native_bt.message_discarded_events_borrow_end_default_clock_snapshot_const) + _borrow_beginning_clock_snapshot_ptr = staticmethod( + native_bt.message_discarded_events_borrow_beginning_default_clock_snapshot_const + ) + _borrow_end_clock_snapshot_ptr = staticmethod( + native_bt.message_discarded_events_borrow_end_default_clock_snapshot_const + ) @property def _has_default_clock_snapshots(self): @@ -189,11 +220,17 @@ class _DiscardedEventsMessage(_DiscardedMessage): class _DiscardedPacketsMessage(_DiscardedMessage): - _borrow_stream_ptr = staticmethod(native_bt.message_discarded_packets_borrow_stream_const) + _borrow_stream_ptr = staticmethod( + native_bt.message_discarded_packets_borrow_stream_const + ) _get_count = staticmethod(native_bt.message_discarded_packets_get_count) _set_count = staticmethod(native_bt.message_discarded_packets_set_count) - _borrow_beginning_clock_snapshot_ptr = staticmethod(native_bt.message_discarded_packets_borrow_beginning_default_clock_snapshot_const) - _borrow_end_clock_snapshot_ptr = staticmethod(native_bt.message_discarded_packets_borrow_end_default_clock_snapshot_const) + _borrow_beginning_clock_snapshot_ptr = staticmethod( + native_bt.message_discarded_packets_borrow_beginning_default_clock_snapshot_const + ) + _borrow_end_clock_snapshot_ptr = staticmethod( + native_bt.message_discarded_packets_borrow_end_default_clock_snapshot_const + ) @property def _has_default_clock_snapshots(self): diff --git a/src/bindings/python/bt2/bt2/message_iterator.py b/src/bindings/python/bt2/bt2/message_iterator.py index eb22dfb4..9d3a4d22 100644 --- a/src/bindings/python/bt2/bt2/message_iterator.py +++ b/src/bindings/python/bt2/bt2/message_iterator.py @@ -34,15 +34,16 @@ class _MessageIterator(collections.abc.Iterator): class _GenericMessageIterator(object._SharedObject, _MessageIterator): def __init__(self, ptr): - self._current_msgs = [] - self._at = 0 - super().__init__(ptr) + self._current_msgs = [] + self._at = 0 + super().__init__(ptr) def __next__(self): if len(self._current_msgs) == self._at: status, msgs = self._get_msg_range(self._ptr) - utils._handle_func_status(status, - 'unexpected error: cannot advance the message iterator') + utils._handle_func_status( + status, 'unexpected error: cannot advance the message iterator' + ) self._current_msgs = msgs self._at = 0 @@ -62,17 +63,24 @@ class _GenericMessageIterator(object._SharedObject, _MessageIterator): self._at = 0 status = self._seek_beginning(self._ptr) - utils._handle_func_status(status, - 'cannot seek message iterator beginning') + utils._handle_func_status(status, 'cannot seek message iterator beginning') # This is created when a component wants to iterate on one of its input ports. class _UserComponentInputPortMessageIterator(_GenericMessageIterator): _get_msg_range = staticmethod(native_bt.bt2_self_component_port_input_get_msg_range) - _get_ref = staticmethod(native_bt.self_component_port_input_message_iterator_get_ref) - _put_ref = staticmethod(native_bt.self_component_port_input_message_iterator_put_ref) - _can_seek_beginning = staticmethod(native_bt.self_component_port_input_message_iterator_can_seek_beginning) - _seek_beginning = staticmethod(native_bt.self_component_port_input_message_iterator_seek_beginning) + _get_ref = staticmethod( + native_bt.self_component_port_input_message_iterator_get_ref + ) + _put_ref = staticmethod( + native_bt.self_component_port_input_message_iterator_put_ref + ) + _can_seek_beginning = staticmethod( + native_bt.self_component_port_input_message_iterator_can_seek_beginning + ) + _seek_beginning = staticmethod( + native_bt.self_component_port_input_message_iterator_seek_beginning + ) # This is created when the user wants to iterate on a component's output port, @@ -81,8 +89,12 @@ class _OutputPortMessageIterator(_GenericMessageIterator): _get_msg_range = staticmethod(native_bt.bt2_port_output_get_msg_range) _get_ref = staticmethod(native_bt.port_output_message_iterator_get_ref) _put_ref = staticmethod(native_bt.port_output_message_iterator_put_ref) - _can_seek_beginning = staticmethod(native_bt.port_output_message_iterator_can_seek_beginning) - _seek_beginning = staticmethod(native_bt.port_output_message_iterator_seek_beginning) + _can_seek_beginning = staticmethod( + native_bt.port_output_message_iterator_can_seek_beginning + ) + _seek_beginning = staticmethod( + native_bt.port_output_message_iterator_seek_beginning + ) # This is extended by the user to implement component classes in Python. It @@ -110,7 +122,8 @@ class _UserMessageIterator(_MessageIterator): def _bt_init_from_native(self, self_output_port_ptr): self_output_port = bt2.port._create_self_from_ptr_and_get_ref( - self_output_port_ptr, native_bt.PORT_TYPE_OUTPUT) + self_output_port_ptr, native_bt.PORT_TYPE_OUTPUT + ) self.__init__(self_output_port) def __init__(self, output_port): @@ -165,8 +178,9 @@ class _UserMessageIterator(_MessageIterator): def _bt_seek_beginning_from_native(self): self._seek_beginning() - def _create_event_message(self, event_class, parent=None, - default_clock_snapshot=None): + def _create_event_message( + self, event_class, parent=None, default_clock_snapshot=None + ): utils._check_type(event_class, bt2.event_class._EventClass) if event_class.stream_class.supports_packets: @@ -176,26 +190,34 @@ class _UserMessageIterator(_MessageIterator): if default_clock_snapshot is not None: if event_class.stream_class.default_clock_class is None: - raise ValueError('event messages in this stream must not have a default clock snapshot') + raise ValueError( + 'event messages in this stream must not have a default clock snapshot' + ) utils._check_uint64(default_clock_snapshot) if event_class.stream_class.supports_packets: ptr = native_bt.message_event_create_with_packet_and_default_clock_snapshot( - self._bt_ptr, event_class._ptr, parent._ptr, default_clock_snapshot) + self._bt_ptr, event_class._ptr, parent._ptr, default_clock_snapshot + ) else: ptr = native_bt.message_event_create_with_default_clock_snapshot( - self._bt_ptr, event_class._ptr, parent._ptr, default_clock_snapshot) + self._bt_ptr, event_class._ptr, parent._ptr, default_clock_snapshot + ) else: if event_class.stream_class.default_clock_class is not None: - raise ValueError('event messages in this stream must have a default clock snapshot') + raise ValueError( + 'event messages in this stream must have a default clock snapshot' + ) if event_class.stream_class.supports_packets: ptr = native_bt.message_event_create_with_packet( - self._bt_ptr, event_class._ptr, parent._ptr) + self._bt_ptr, event_class._ptr, parent._ptr + ) else: ptr = native_bt.message_event_create( - self._bt_ptr, event_class._ptr, parent._ptr) + self._bt_ptr, event_class._ptr, parent._ptr + ) if ptr is None: raise bt2.CreationError('cannot create event message object') @@ -205,7 +227,8 @@ class _UserMessageIterator(_MessageIterator): def _create_message_iterator_inactivity_message(self, clock_class, clock_snapshot): utils._check_type(clock_class, bt2.clock_class._ClockClass) ptr = native_bt.message_message_iterator_inactivity_create( - self._bt_ptr, clock_class._ptr, clock_snapshot) + self._bt_ptr, clock_class._ptr, clock_snapshot + ) if ptr is None: raise bt2.CreationError('cannot create inactivity message object') @@ -245,14 +268,19 @@ class _UserMessageIterator(_MessageIterator): 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 snapshot") + raise ValueError( + "packet beginning messages in this stream must have a default clock snapshot" + ) utils._check_uint64(default_clock_snapshot) ptr = native_bt.message_packet_beginning_create_with_default_clock_snapshot( - self._bt_ptr, packet._ptr, default_clock_snapshot) + self._bt_ptr, packet._ptr, default_clock_snapshot + ) else: if default_clock_snapshot is not None: - raise ValueError("packet beginning messages in this stream must not have a default clock snapshot") + raise ValueError( + "packet beginning messages in this stream must not have a default clock snapshot" + ) ptr = native_bt.message_packet_beginning_create(self._bt_ptr, packet._ptr) @@ -266,14 +294,19 @@ class _UserMessageIterator(_MessageIterator): 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 snapshot") + raise ValueError( + "packet end messages in this stream must have a default clock snapshot" + ) utils._check_uint64(default_clock_snapshot) ptr = native_bt.message_packet_end_create_with_default_clock_snapshot( - self._bt_ptr, packet._ptr, default_clock_snapshot) + self._bt_ptr, packet._ptr, default_clock_snapshot + ) else: if default_clock_snapshot is not None: - raise ValueError("packet end messages in this stream must not have a default clock snapshot") + raise ValueError( + "packet end messages in this stream must not have a default clock snapshot" + ) ptr = native_bt.message_packet_end_create(self._bt_ptr, packet._ptr) @@ -282,9 +315,9 @@ class _UserMessageIterator(_MessageIterator): return bt2.message._PacketEndMessage(ptr) - def _create_discarded_events_message(self, stream, count=None, - beg_clock_snapshot=None, - end_clock_snapshot=None): + def _create_discarded_events_message( + self, stream, count=None, beg_clock_snapshot=None, end_clock_snapshot=None + ): utils._check_type(stream, bt2.stream._Stream) if not stream.cls.supports_discarded_events: @@ -292,18 +325,22 @@ class _UserMessageIterator(_MessageIterator): 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') + raise ValueError( + 'discarded events have default clock snapshots for this stream class' + ) utils._check_uint64(beg_clock_snapshot) utils._check_uint64(end_clock_snapshot) ptr = native_bt.message_discarded_events_create_with_default_clock_snapshots( - self._bt_ptr, stream._ptr, beg_clock_snapshot, end_clock_snapshot) + self._bt_ptr, stream._ptr, beg_clock_snapshot, end_clock_snapshot + ) else: if beg_clock_snapshot is not None or end_clock_snapshot is not None: - raise ValueError('discarded events have no default clock snapshots for this stream class') + raise ValueError( + 'discarded events have no default clock snapshots for this stream class' + ) - ptr = native_bt.message_discarded_events_create( - self._bt_ptr, stream._ptr) + ptr = native_bt.message_discarded_events_create(self._bt_ptr, stream._ptr) if ptr is None: raise bt2.CreationError('cannot discarded events message object') @@ -315,7 +352,9 @@ class _UserMessageIterator(_MessageIterator): return msg - def _create_discarded_packets_message(self, stream, count=None, beg_clock_snapshot=None, end_clock_snapshot=None): + 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.cls.supports_discarded_packets: @@ -323,18 +362,22 @@ class _UserMessageIterator(_MessageIterator): 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') + raise ValueError( + 'discarded packets have default clock snapshots for this stream class' + ) utils._check_uint64(beg_clock_snapshot) utils._check_uint64(end_clock_snapshot) ptr = native_bt.message_discarded_packets_create_with_default_clock_snapshots( - self._bt_ptr, stream._ptr, beg_clock_snapshot, end_clock_snapshot) + self._bt_ptr, stream._ptr, beg_clock_snapshot, end_clock_snapshot + ) else: if beg_clock_snapshot is not None or end_clock_snapshot is not None: - raise ValueError('discarded packets have no default clock snapshots for this stream class') + raise ValueError( + 'discarded packets have no default clock snapshots for this stream class' + ) - ptr = native_bt.message_discarded_packets_create( - self._bt_ptr, stream._ptr) + ptr = native_bt.message_discarded_packets_create(self._bt_ptr, stream._ptr) if ptr is None: raise bt2.CreationError('cannot discarded packets message object') @@ -345,4 +388,3 @@ class _UserMessageIterator(_MessageIterator): msg._count = count return msg - diff --git a/src/bindings/python/bt2/bt2/object.py b/src/bindings/python/bt2/bt2/object.py index f73ec04b..290f3feb 100644 --- a/src/bindings/python/bt2/bt2/object.py +++ b/src/bindings/python/bt2/bt2/object.py @@ -38,9 +38,9 @@ class _BaseObject: return int(self._ptr) def __repr__(self): - return '<{}.{} object @ {}>'.format(self.__class__.__module__, - self.__class__.__name__, - hex(self.addr)) + return '<{}.{} object @ {}>'.format( + self.__class__.__module__, self.__class__.__name__, hex(self.addr) + ) def __copy__(self): raise NotImplementedError @@ -58,6 +58,7 @@ class _BaseObject: # of unique objects, we make it so acquiring a reference on a unique object # acquires a reference on its owner. + class _UniqueObject(_BaseObject): # Create a _UniqueObject. @@ -69,8 +70,7 @@ class _UniqueObject(_BaseObject): # - owner_put_ref: Callback to put a reference on the owner. @classmethod - def _create_from_ptr_and_get_ref(cls, ptr, owner_ptr, - owner_get_ref, owner_put_ref): + def _create_from_ptr_and_get_ref(cls, ptr, owner_ptr, owner_get_ref, owner_put_ref): obj = cls.__new__(cls) obj._ptr = ptr diff --git a/src/bindings/python/bt2/bt2/packet.py b/src/bindings/python/bt2/bt2/packet.py index 93e9ac8f..266f7bcb 100644 --- a/src/bindings/python/bt2/bt2/packet.py +++ b/src/bindings/python/bt2/bt2/packet.py @@ -42,6 +42,6 @@ class _Packet(object._SharedObject): if field_ptr is None: return - return bt2.field._create_field_from_ptr(field_ptr, self._ptr, - self._get_ref, - self._put_ref) + return bt2.field._create_field_from_ptr( + field_ptr, self._ptr, self._get_ref, self._put_ref + ) diff --git a/src/bindings/python/bt2/bt2/plugin.py b/src/bindings/python/bt2/bt2/plugin.py index 620bd76a..86612920 100644 --- a/src/bindings/python/bt2/bt2/plugin.py +++ b/src/bindings/python/bt2/bt2/plugin.py @@ -34,9 +34,13 @@ def find_plugins(path, recurse=True, fail_on_load_error=False): plugin_set_ptr = None if os.path.isfile(path): - status, plugin_set_ptr = native_bt.bt2_plugin_find_all_from_file(path, fail_on_load_error) + status, plugin_set_ptr = native_bt.bt2_plugin_find_all_from_file( + path, fail_on_load_error + ) elif os.path.isdir(path): - status, plugin_set_ptr = native_bt.bt2_plugin_find_all_from_dir(path, int(recurse), int(fail_on_load_error)) + status, plugin_set_ptr = native_bt.bt2_plugin_find_all_from_dir( + path, int(recurse), int(fail_on_load_error) + ) else: raise bt2.Error("invalid path: '{}'".format(path)) @@ -67,7 +71,7 @@ class _PluginSet(object._SharedObject, collections.abc.Sequence): def __len__(self): count = native_bt.plugin_set_get_plugin_count(self._ptr) - assert(count >= 0) + assert count >= 0 return count def __getitem__(self, index): @@ -125,12 +129,16 @@ class _PluginComponentClassesIterator(collections.abc.Iterator): if self._at == total: raise StopIteration - comp_cls_ptr = self._plugin_comp_cls._borrow_component_class_by_index(plugin_ptr, self._at) + comp_cls_ptr = self._plugin_comp_cls._borrow_component_class_by_index( + plugin_ptr, self._at + ) assert comp_cls_ptr is not None self._at += 1 comp_cls_type = self._plugin_comp_cls._comp_cls_type - comp_cls_pycls = bt2.component._COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS[comp_cls_type] + comp_cls_pycls = bt2.component._COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS[ + comp_cls_type + ] comp_cls_ptr = comp_cls_pycls._bt_as_component_class_ptr(comp_cls_ptr) name = native_bt.component_class_get_name(comp_cls_ptr) assert name is not None @@ -148,7 +156,9 @@ class _PluginComponentClasses(collections.abc.Mapping): if cc_ptr is None: raise KeyError(key) - return bt2.component._create_component_class_from_ptr_and_get_ref(cc_ptr, self._comp_cls_type) + return bt2.component._create_component_class_from_ptr_and_get_ref( + cc_ptr, self._comp_cls_type + ) def __len__(self): return self._component_class_count(self._plugin._ptr) @@ -158,23 +168,41 @@ class _PluginComponentClasses(collections.abc.Mapping): class _PluginSourceComponentClasses(_PluginComponentClasses): - _component_class_count = staticmethod(native_bt.plugin_get_source_component_class_count) - _borrow_component_class_by_name = staticmethod(native_bt.plugin_borrow_source_component_class_by_name_const) - _borrow_component_class_by_index = staticmethod(native_bt.plugin_borrow_source_component_class_by_index_const) + _component_class_count = staticmethod( + native_bt.plugin_get_source_component_class_count + ) + _borrow_component_class_by_name = staticmethod( + native_bt.plugin_borrow_source_component_class_by_name_const + ) + _borrow_component_class_by_index = staticmethod( + native_bt.plugin_borrow_source_component_class_by_index_const + ) _comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_SOURCE class _PluginFilterComponentClasses(_PluginComponentClasses): - _component_class_count = staticmethod(native_bt.plugin_get_filter_component_class_count) - _borrow_component_class_by_name = staticmethod(native_bt.plugin_borrow_filter_component_class_by_name_const) - _borrow_component_class_by_index = staticmethod(native_bt.plugin_borrow_filter_component_class_by_index_const) + _component_class_count = staticmethod( + native_bt.plugin_get_filter_component_class_count + ) + _borrow_component_class_by_name = staticmethod( + native_bt.plugin_borrow_filter_component_class_by_name_const + ) + _borrow_component_class_by_index = staticmethod( + native_bt.plugin_borrow_filter_component_class_by_index_const + ) _comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_FILTER class _PluginSinkComponentClasses(_PluginComponentClasses): - _component_class_count = staticmethod(native_bt.plugin_get_sink_component_class_count) - _borrow_component_class_by_name = staticmethod(native_bt.plugin_borrow_sink_component_class_by_name_const) - _borrow_component_class_by_index = staticmethod(native_bt.plugin_borrow_sink_component_class_by_index_const) + _component_class_count = staticmethod( + native_bt.plugin_get_sink_component_class_count + ) + _borrow_component_class_by_name = staticmethod( + native_bt.plugin_borrow_sink_component_class_by_name_const + ) + _borrow_component_class_by_index = staticmethod( + native_bt.plugin_borrow_sink_component_class_by_index_const + ) _comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_SINK @@ -185,7 +213,7 @@ class _Plugin(object._SharedObject): @property def name(self): name = native_bt.plugin_get_name(self._ptr) - assert(name is not None) + assert name is not None return name @property diff --git a/src/bindings/python/bt2/bt2/port.py b/src/bindings/python/bt2/bt2/port.py index 4ba59f06..1d649b35 100644 --- a/src/bindings/python/bt2/bt2/port.py +++ b/src/bindings/python/bt2/bt2/port.py @@ -110,10 +110,14 @@ class _UserComponentPort(_Port): class _UserComponentInputPort(_UserComponentPort, _InputPort): - _as_self_port_ptr = staticmethod(native_bt.self_component_port_input_as_self_component_port) + _as_self_port_ptr = staticmethod( + native_bt.self_component_port_input_as_self_component_port + ) def create_message_iterator(self): - msg_iter_ptr = native_bt.self_component_port_input_message_iterator_create(self._ptr) + msg_iter_ptr = native_bt.self_component_port_input_message_iterator_create( + self._ptr + ) if msg_iter_ptr is None: raise bt2.CreationError('cannot create message iterator object') @@ -121,7 +125,9 @@ class _UserComponentInputPort(_UserComponentPort, _InputPort): class _UserComponentOutputPort(_UserComponentPort, _OutputPort): - _as_self_port_ptr = staticmethod(native_bt.self_component_port_output_as_self_component_port) + _as_self_port_ptr = staticmethod( + native_bt.self_component_port_output_as_self_component_port + ) _PORT_TYPE_TO_PYCLS = { diff --git a/src/bindings/python/bt2/bt2/py_plugin.py b/src/bindings/python/bt2/bt2/py_plugin.py index b8450308..5f620ab7 100644 --- a/src/bindings/python/bt2/bt2/py_plugin.py +++ b/src/bindings/python/bt2/bt2/py_plugin.py @@ -32,12 +32,15 @@ def plugin_component_class(component_class): return component_class -def register_plugin(module_name, name, description=None, author=None, - license=None, version=None): +def register_plugin( + module_name, name, description=None, author=None, license=None, version=None +): import sys if module_name not in sys.modules: - raise RuntimeError("cannot find module '{}' in loaded modules".format(module_name)) + raise RuntimeError( + "cannot find module '{}' in loaded modules".format(module_name) + ) utils._check_str(name) @@ -52,11 +55,13 @@ def register_plugin(module_name, name, description=None, author=None, if version is not None: if not _validate_version(version): - raise ValueError('wrong version: expecting a tuple: (major, minor, patch) or (major, minor, patch, extra)') + raise ValueError( + 'wrong version: expecting a tuple: (major, minor, patch) or (major, minor, patch, extra)' + ) - sys.modules[module_name]._bt_plugin_info = _PluginInfo(name, description, - author, license, - version) + sys.modules[module_name]._bt_plugin_info = _PluginInfo( + name, description, author, license, version + ) def _validate_version(version): diff --git a/src/bindings/python/bt2/bt2/query_executor.py b/src/bindings/python/bt2/bt2/query_executor.py index f734609e..17ddd97e 100644 --- a/src/bindings/python/bt2/bt2/query_executor.py +++ b/src/bindings/python/bt2/bt2/query_executor.py @@ -40,17 +40,21 @@ class QueryExecutor(object._SharedObject): def cancel(self): status = native_bt.query_executor_cancel(self._ptr) - utils._handle_func_status(status, - 'cannot cancel query executor object') + utils._handle_func_status(status, 'cannot cancel query executor object') @property def is_canceled(self): is_canceled = native_bt.query_executor_is_canceled(self._ptr) - assert(is_canceled >= 0) + assert is_canceled >= 0 return is_canceled > 0 - def query(self, component_class, object, params=None, - logging_level=bt2.logging.LoggingLevel.NONE): + def query( + self, + component_class, + object, + params=None, + logging_level=bt2.logging.LoggingLevel.NONE, + ): if self.is_canceled: raise bt2.Canceled @@ -78,9 +82,9 @@ class QueryExecutor(object._SharedObject): utils._check_log_level(logging_level) cc_ptr = component_class._bt_component_class_ptr() - status, result_ptr = native_bt.query_executor_query(self._ptr, cc_ptr, - object, params_ptr, - logging_level) + status, result_ptr = native_bt.query_executor_query( + self._ptr, cc_ptr, object, params_ptr, logging_level + ) utils._handle_func_status(status, 'cannot query component class') - assert(result_ptr) + assert result_ptr return bt2.value._create_from_ptr(result_ptr) diff --git a/src/bindings/python/bt2/bt2/stream.py b/src/bindings/python/bt2/bt2/stream.py index eb780b0e..451ad6c9 100644 --- a/src/bindings/python/bt2/bt2/stream.py +++ b/src/bindings/python/bt2/bt2/stream.py @@ -34,7 +34,9 @@ class _Stream(bt2.object._SharedObject): 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) + return bt2.stream_class._StreamClass._create_from_ptr_and_get_ref( + stream_class_ptr + ) @property def name(self): @@ -53,7 +55,9 @@ class _Stream(bt2.object._SharedObject): def create_packet(self): if not self.cls.supports_packets: - raise bt2.Error('cannot create packet: stream class does not support packets') + raise bt2.Error( + 'cannot create packet: stream class does not support packets' + ) packet_ptr = native_bt.packet_create(self._ptr) diff --git a/src/bindings/python/bt2/bt2/stream_class.py b/src/bindings/python/bt2/bt2/stream_class.py index cf34cf4c..08186333 100644 --- a/src/bindings/python/bt2/bt2/stream_class.py +++ b/src/bindings/python/bt2/bt2/stream_class.py @@ -48,7 +48,9 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): def __iter__(self): for idx in range(len(self)): - ec_ptr = native_bt.stream_class_borrow_event_class_by_index_const(self._ptr, idx) + ec_ptr = native_bt.stream_class_borrow_event_class_by_index_const( + self._ptr, idx + ) assert ec_ptr is not None id = native_bt.event_class_get_id(ec_ptr) @@ -56,17 +58,27 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): yield id - def create_event_class(self, id=None, name=None, log_level=None, emf_uri=None, - specific_context_field_class=None, - payload_field_class=None): + def create_event_class( + self, + id=None, + name=None, + log_level=None, + emf_uri=None, + specific_context_field_class=None, + payload_field_class=None, + ): if self.assigns_automatic_event_class_id: if id is not None: - raise ValueError('id provided, but stream class assigns automatic event class ids') + raise ValueError( + 'id provided, but stream class assigns automatic event class ids' + ) ec_ptr = native_bt.event_class_create(self._ptr) else: if id is None: - raise ValueError('id not provided, but stream class does not assign automatic event class ids') + raise ValueError( + 'id not provided, but stream class does not assign automatic event class ids' + ) utils._check_uint64(id) ec_ptr = native_bt.event_class_create_with_id(self._ptr, id) @@ -104,8 +116,7 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): def _name(self, name): utils._check_str(name) status = native_bt.stream_class_set_name(self._ptr, name) - utils._handle_func_status(status, - "cannot set stream class object's name") + utils._handle_func_status(status, "cannot set stream class object's name") _name = property(fset=_name) @@ -115,7 +126,9 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): def _assigns_automatic_event_class_id(self, auto_id): utils._check_bool(auto_id) - return native_bt.stream_class_set_assigns_automatic_event_class_id(self._ptr, auto_id) + return native_bt.stream_class_set_assigns_automatic_event_class_id( + self._ptr, auto_id + ) _assigns_automatic_event_class_id = property(fset=_assigns_automatic_event_class_id) @@ -125,7 +138,9 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): def _assigns_automatic_stream_id(self, auto_id): utils._check_bool(auto_id) - return native_bt.stream_class_set_assigns_automatic_stream_id(self._ptr, auto_id) + return native_bt.stream_class_set_assigns_automatic_stream_id( + self._ptr, auto_id + ) _assigns_automatic_stream_id = property(fset=_assigns_automatic_stream_id) @@ -135,7 +150,9 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): @property def packets_have_beginning_default_clock_snapshot(self): - return native_bt.stream_class_packets_have_beginning_default_clock_snapshot(self._ptr) + return native_bt.stream_class_packets_have_beginning_default_clock_snapshot( + self._ptr + ) @property def packets_have_end_default_clock_snapshot(self): @@ -147,12 +164,16 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): utils._check_bool(with_end_cs) if not supports and (with_begin_cs or with_end_cs): - raise ValueError('cannot not support packets, but have default clock snapshots') + raise ValueError( + 'cannot not support packets, but have default clock snapshots' + ) if not supports and self.packet_context_field_class is not None: raise ValueError('stream class already has a packet context field class') - native_bt.stream_class_set_supports_packets(self._ptr, supports, with_begin_cs, with_end_cs) + native_bt.stream_class_set_supports_packets( + self._ptr, supports, with_begin_cs, with_end_cs + ) @property def supports_discarded_events(self): @@ -163,13 +184,19 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): utils._check_bool(with_cs) if not supports and with_cs: - raise ValueError('cannot not support discarded events, but have default clock snapshots') + raise ValueError( + 'cannot not support discarded events, but have default clock snapshots' + ) - native_bt.stream_class_set_supports_discarded_events(self._ptr, supports, with_cs) + native_bt.stream_class_set_supports_discarded_events( + self._ptr, supports, with_cs + ) @property def discarded_events_have_default_clock_snapshots(self): - return native_bt.stream_class_discarded_events_have_default_clock_snapshots(self._ptr) + return native_bt.stream_class_discarded_events_have_default_clock_snapshots( + self._ptr + ) @property def supports_discarded_packets(self): @@ -180,16 +207,24 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): utils._check_bool(with_cs) if supports and not self.supports_packets: - raise ValueError('cannot support discarded packets, but not support packets') + raise ValueError( + 'cannot support discarded packets, but not support packets' + ) if not supports and with_cs: - raise ValueError('cannot not support discarded packets, but have default clock snapshots') + raise ValueError( + 'cannot not support discarded packets, but have default clock snapshots' + ) - native_bt.stream_class_set_supports_discarded_packets(self._ptr, supports, with_cs) + native_bt.stream_class_set_supports_discarded_packets( + self._ptr, supports, with_cs + ) @property def discarded_packets_have_default_clock_snapshots(self): - return native_bt.stream_class_discarded_packets_have_default_clock_snapshots(self._ptr) + return native_bt.stream_class_discarded_packets_have_default_clock_snapshots( + self._ptr + ) @property def id(self): @@ -208,7 +243,9 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): @property def packet_context_field_class(self): - fc_ptr = native_bt.stream_class_borrow_packet_context_field_class_const(self._ptr) + fc_ptr = native_bt.stream_class_borrow_packet_context_field_class_const( + self._ptr + ) if fc_ptr is None: return @@ -217,22 +254,27 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): def _packet_context_field_class(self, packet_context_field_class): if packet_context_field_class is not None: - utils._check_type(packet_context_field_class, - bt2.field_class._StructureFieldClass) + utils._check_type( + packet_context_field_class, bt2.field_class._StructureFieldClass + ) if not self.supports_packets: raise ValueError('stream class does not support packets') - status = native_bt.stream_class_set_packet_context_field_class(self._ptr, - packet_context_field_class._ptr) - utils._handle_func_status(status, - "cannot set stream class' packet context field class") + status = native_bt.stream_class_set_packet_context_field_class( + self._ptr, packet_context_field_class._ptr + ) + utils._handle_func_status( + status, "cannot set stream class' packet context field class" + ) _packet_context_field_class = property(fset=_packet_context_field_class) @property def event_common_context_field_class(self): - fc_ptr = native_bt.stream_class_borrow_event_common_context_field_class_const(self._ptr) + fc_ptr = native_bt.stream_class_borrow_event_common_context_field_class_const( + self._ptr + ) if fc_ptr is None: return @@ -241,13 +283,15 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): def _event_common_context_field_class(self, event_common_context_field_class): if event_common_context_field_class is not None: - utils._check_type(event_common_context_field_class, - bt2.field_class._StructureFieldClass) + utils._check_type( + event_common_context_field_class, bt2.field_class._StructureFieldClass + ) set_context_fn = native_bt.stream_class_set_event_common_context_field_class status = set_context_fn(self._ptr, event_common_context_field_class._ptr) - utils._handle_func_status(status, - "cannot set stream class' event context field type") + utils._handle_func_status( + status, "cannot set stream class' event context field type" + ) _event_common_context_field_class = property(fset=_event_common_context_field_class) @@ -261,7 +305,6 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): def _default_clock_class(self, clock_class): utils._check_type(clock_class, bt2.clock_class._ClockClass) - native_bt.stream_class_set_default_clock_class( - self._ptr, clock_class._ptr) + native_bt.stream_class_set_default_clock_class(self._ptr, clock_class._ptr) _default_clock_class = property(fset=_default_clock_class) diff --git a/src/bindings/python/bt2/bt2/trace.py b/src/bindings/python/bt2/bt2/trace.py index d7f03cb5..5ddcbad2 100644 --- a/src/bindings/python/bt2/bt2/trace.py +++ b/src/bindings/python/bt2/bt2/trace.py @@ -55,8 +55,7 @@ class _TraceEnv(collections.abc.MutableMapping): raise TypeError('expected str or int, got {}'.format(type(value))) status = set_env_entry_fn(self._trace._ptr, key, value) - utils._handle_func_status(status, - "cannot set trace object's environment entry") + utils._handle_func_status(status, "cannot set trace object's environment entry") def __delitem__(self, key): raise NotImplementedError @@ -123,8 +122,7 @@ class _Trace(object._SharedObject, collections.abc.Mapping): def _name(self, name): utils._check_str(name) status = native_bt.trace_set_name(self._ptr, name) - utils._handle_func_status(status, - "cannot set trace class object's name") + utils._handle_func_status(status, "cannot set trace class object's name") _name = property(fset=_name) @@ -151,15 +149,21 @@ class _Trace(object._SharedObject, collections.abc.Mapping): if stream_class.assigns_automatic_stream_id: if id is not None: - raise ValueError("id provided, but stream class assigns automatic stream ids") + raise ValueError( + "id provided, but stream class assigns automatic stream ids" + ) stream_ptr = native_bt.stream_create(stream_class._ptr, self._ptr) else: if id is None: - raise ValueError("id not provided, but stream class does not assign automatic stream ids") + raise ValueError( + "id not provided, but stream class does not assign automatic stream ids" + ) utils._check_uint64(id) - stream_ptr = native_bt.stream_create_with_id(stream_class._ptr, self._ptr, id) + stream_ptr = native_bt.stream_create_with_id( + stream_class._ptr, self._ptr, id + ) if stream_ptr is None: raise bt2.CreationError('cannot create stream object') @@ -177,8 +181,9 @@ class _Trace(object._SharedObject, collections.abc.Mapping): raise TypeError("'listener' parameter is not callable") fn = native_bt.bt2_trace_add_destruction_listener - listener_from_native = functools.partial(_trace_destruction_listener_from_native, - listener) + listener_from_native = functools.partial( + _trace_destruction_listener_from_native, listener + ) listener_id = fn(self._ptr, listener_from_native) if listener_id is None: diff --git a/src/bindings/python/bt2/bt2/trace_class.py b/src/bindings/python/bt2/bt2/trace_class.py index fb0eb543..d480b819 100644 --- a/src/bindings/python/bt2/bt2/trace_class.py +++ b/src/bindings/python/bt2/bt2/trace_class.py @@ -41,7 +41,9 @@ class _StreamClassIterator(collections.abc.Iterator): if self._at == len(self._trace_class): raise StopIteration - borrow_stream_class_fn = native_bt.trace_class_borrow_stream_class_by_index_const + borrow_stream_class_fn = ( + native_bt.trace_class_borrow_stream_class_by_index_const + ) sc_ptr = borrow_stream_class_fn(self._trace_class._ptr, self._at) assert sc_ptr id = native_bt.stream_class_get_id(sc_ptr) @@ -51,7 +53,9 @@ class _StreamClassIterator(collections.abc.Iterator): def _trace_class_destruction_listener_from_native(user_listener, trace_class_ptr): - trace_class = bt2.trace_class._TraceClass._create_from_ptr_and_get_ref(trace_class_ptr) + trace_class = bt2.trace_class._TraceClass._create_from_ptr_and_get_ref( + trace_class_ptr + ) user_listener(trace_class) @@ -101,7 +105,9 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): def __iter__(self): for idx in range(len(self)): - sc_ptr = native_bt.trace_class_borrow_stream_class_by_index_const(self._ptr, idx) + sc_ptr = native_bt.trace_class_borrow_stream_class_by_index_const( + self._ptr, idx + ) assert sc_ptr is not None id = native_bt.stream_class_get_id(sc_ptr) @@ -109,29 +115,36 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): yield id - def create_stream_class(self, id=None, - name=None, - packet_context_field_class=None, - event_common_context_field_class=None, - default_clock_class=None, - assigns_automatic_event_class_id=True, - assigns_automatic_stream_id=True, - supports_packets=False, - packets_have_beginning_default_clock_snapshot=False, - packets_have_end_default_clock_snapshot=False, - supports_discarded_events=False, - discarded_events_have_default_clock_snapshots=False, - supports_discarded_packets=False, - discarded_packets_have_default_clock_snapshots=False): + def create_stream_class( + self, + id=None, + name=None, + packet_context_field_class=None, + event_common_context_field_class=None, + default_clock_class=None, + assigns_automatic_event_class_id=True, + assigns_automatic_stream_id=True, + supports_packets=False, + packets_have_beginning_default_clock_snapshot=False, + packets_have_end_default_clock_snapshot=False, + supports_discarded_events=False, + discarded_events_have_default_clock_snapshots=False, + supports_discarded_packets=False, + discarded_packets_have_default_clock_snapshots=False, + ): if self.assigns_automatic_stream_class_id: if id is not None: - raise ValueError('id provided, but trace class assigns automatic stream class ids') + raise ValueError( + 'id provided, but trace class assigns automatic stream class ids' + ) sc_ptr = native_bt.stream_class_create(self._ptr) else: if id is None: - raise ValueError('id not provided, but trace class does not assign automatic stream class ids') + raise ValueError( + 'id not provided, but trace class does not assign automatic stream class ids' + ) utils._check_uint64(id) sc_ptr = native_bt.stream_class_create_with_id(self._ptr, id) @@ -151,9 +164,11 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): # `packets_have_beginning_default_clock_snapshot` or # `packets_have_end_default_clock_snapshot` is true, then this # stream class needs a default clock class already. - sc._set_supports_packets(supports_packets, - packets_have_beginning_default_clock_snapshot, - packets_have_end_default_clock_snapshot) + sc._set_supports_packets( + supports_packets, + packets_have_beginning_default_clock_snapshot, + packets_have_end_default_clock_snapshot, + ) # call after sc._set_supports_packets() because, if # `packet_context_field_class` is not `None`, then this stream @@ -163,10 +178,12 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): sc._assigns_automatic_event_class_id = assigns_automatic_event_class_id sc._assigns_automatic_stream_id = assigns_automatic_stream_id - sc._set_supports_discarded_events(supports_discarded_events, - discarded_events_have_default_clock_snapshots) - sc._set_supports_discarded_packets(supports_discarded_packets, - discarded_packets_have_default_clock_snapshots) + sc._set_supports_discarded_events( + supports_discarded_events, discarded_events_have_default_clock_snapshots + ) + sc._set_supports_discarded_packets( + supports_discarded_packets, discarded_packets_have_default_clock_snapshots + ) return sc @property @@ -175,18 +192,23 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): def _assigns_automatic_stream_class_id(self, auto_id): utils._check_bool(auto_id) - return native_bt.trace_class_set_assigns_automatic_stream_class_id(self._ptr, auto_id) + return native_bt.trace_class_set_assigns_automatic_stream_class_id( + self._ptr, auto_id + ) - _assigns_automatic_stream_class_id = property(fset=_assigns_automatic_stream_class_id) + _assigns_automatic_stream_class_id = property( + fset=_assigns_automatic_stream_class_id + ) # Field class creation methods. def _check_create_status(self, ptr, type_name): if ptr is None: - raise bt2.CreationError( - 'cannot create {} field class'.format(type_name)) + raise bt2.CreationError('cannot create {} field class'.format(type_name)) - def _create_integer_field_class(self, create_func, py_cls, type_name, field_value_range, preferred_display_base): + def _create_integer_field_class( + self, create_func, py_cls, type_name, field_value_range, preferred_display_base + ): field_class_ptr = create_func(self._ptr) self._check_create_status(field_class_ptr, type_name) @@ -200,25 +222,49 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): return field_class - def create_signed_integer_field_class(self, field_value_range=None, preferred_display_base=None): - return self._create_integer_field_class(native_bt.field_class_signed_integer_create, - bt2.field_class._SignedIntegerFieldClass, - 'signed integer', field_value_range, preferred_display_base) - - def create_unsigned_integer_field_class(self, field_value_range=None, preferred_display_base=None): - return self._create_integer_field_class(native_bt.field_class_unsigned_integer_create, - bt2.field_class._UnsignedIntegerFieldClass, - 'unsigned integer', field_value_range, preferred_display_base) - - def create_signed_enumeration_field_class(self, field_value_range=None, preferred_display_base=None): - return self._create_integer_field_class(native_bt.field_class_signed_enumeration_create, - bt2.field_class._SignedEnumerationFieldClass, - 'signed enumeration', field_value_range, preferred_display_base) - - def create_unsigned_enumeration_field_class(self, field_value_range=None, preferred_display_base=None): - return self._create_integer_field_class(native_bt.field_class_unsigned_enumeration_create, - bt2.field_class._UnsignedEnumerationFieldClass, - 'unsigned enumeration', field_value_range, preferred_display_base) + def create_signed_integer_field_class( + self, field_value_range=None, preferred_display_base=None + ): + return self._create_integer_field_class( + native_bt.field_class_signed_integer_create, + bt2.field_class._SignedIntegerFieldClass, + 'signed integer', + field_value_range, + preferred_display_base, + ) + + def create_unsigned_integer_field_class( + self, field_value_range=None, preferred_display_base=None + ): + return self._create_integer_field_class( + native_bt.field_class_unsigned_integer_create, + bt2.field_class._UnsignedIntegerFieldClass, + 'unsigned integer', + field_value_range, + preferred_display_base, + ) + + def create_signed_enumeration_field_class( + self, field_value_range=None, preferred_display_base=None + ): + return self._create_integer_field_class( + native_bt.field_class_signed_enumeration_create, + bt2.field_class._SignedEnumerationFieldClass, + 'signed enumeration', + field_value_range, + preferred_display_base, + ) + + def create_unsigned_enumeration_field_class( + self, field_value_range=None, preferred_display_base=None + ): + return self._create_integer_field_class( + native_bt.field_class_unsigned_enumeration_create, + bt2.field_class._UnsignedEnumerationFieldClass, + 'unsigned enumeration', + field_value_range, + preferred_display_base, + ) def create_real_field_class(self, is_single_precision=False): field_class_ptr = native_bt.field_class_real_create(self._ptr) @@ -258,7 +304,9 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): utils._check_type(length_fc, bt2.field_class._UnsignedIntegerFieldClass) length_fc_ptr = length_fc._ptr - ptr = native_bt.field_class_dynamic_array_create(self._ptr, elem_fc._ptr, length_fc_ptr) + ptr = native_bt.field_class_dynamic_array_create( + self._ptr, elem_fc._ptr, length_fc_ptr + ) self._check_create_status(ptr, 'dynamic array') return bt2.field_class._DynamicArrayFieldClass._create_from_ptr(ptr) @@ -281,11 +329,14 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): raise TypeError("'listener' parameter is not callable") fn = native_bt.bt2_trace_class_add_destruction_listener - listener_from_native = functools.partial(_trace_class_destruction_listener_from_native, - listener) + listener_from_native = functools.partial( + _trace_class_destruction_listener_from_native, listener + ) listener_id = fn(self._ptr, listener_from_native) if listener_id is None: - utils._raise_bt2_error('cannot add destruction listener to trace class object') + utils._raise_bt2_error( + 'cannot add destruction listener to trace class object' + ) return bt2._ListenerHandle(listener_id, self) diff --git a/src/bindings/python/bt2/bt2/trace_collection_message_iterator.py b/src/bindings/python/bt2/bt2/trace_collection_message_iterator.py index 25778fcc..592c7f15 100644 --- a/src/bindings/python/bt2/bt2/trace_collection_message_iterator.py +++ b/src/bindings/python/bt2/bt2/trace_collection_message_iterator.py @@ -34,8 +34,13 @@ _ComponentAndSpec = namedtuple('_ComponentAndSpec', ['comp', 'spec']) class ComponentSpec: - def __init__(self, plugin_name, class_name, params=None, - logging_level=bt2.logging.LoggingLevel.NONE): + def __init__( + self, + plugin_name, + class_name, + params=None, + logging_level=bt2.logging.LoggingLevel.NONE, + ): utils._check_str(plugin_name) utils._check_str(class_name) utils._check_log_level(logging_level) @@ -77,7 +82,9 @@ def _get_ns(obj): # s -> ns s = obj.timestamp() else: - raise TypeError('"{}" is not an integral number or a datetime.datetime object'.format(obj)) + raise TypeError( + '"{}" is not an integral number or a datetime.datetime object'.format(obj) + ) return int(s * 1e9) @@ -88,8 +95,14 @@ class _CompClsType: class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): - def __init__(self, source_component_specs, filter_component_specs=None, - stream_intersection_mode=False, begin=None, end=None): + def __init__( + self, + source_component_specs, + filter_component_specs=None, + stream_intersection_mode=False, + begin=None, + end=None, + ): utils._check_bool(stream_intersection_mode) self._stream_intersection_mode = stream_intersection_mode self._begin_ns = _get_ns(begin) @@ -119,7 +132,9 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): def _validate_component_specs(self, comp_specs): for comp_spec in comp_specs: if type(comp_spec) is not ComponentSpec: - raise TypeError('"{}" object is not a ComponentSpec'.format(type(comp_spec))) + raise TypeError( + '"{}" object is not a ComponentSpec'.format(type(comp_spec)) + ) def __next__(self): return next(self._msg_iter) @@ -134,7 +149,9 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): try: paths = src_comp_and_spec.spec.params['paths'] except Exception as e: - raise bt2.Error('all source components must be created with a "paths" parameter in stream intersection mode') from e + raise bt2.Error( + 'all source components must be created with a "paths" parameter in stream intersection mode' + ) from e params = {'paths': paths} @@ -142,8 +159,9 @@ 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.cls, - 'trace-info', params) + trace_info_res = query_exec.query( + src_comp_and_spec.comp.cls, 'trace-info', params + ) begin = None end = None @@ -160,7 +178,9 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): pass if begin is None or end is None: - raise bt2.Error('cannot find stream intersection range for port "{}"'.format(port.name)) + raise bt2.Error( + 'cannot find stream intersection range for port "{}"'.format(port.name) + ) name = 'trimmer-{}-{}'.format(src_comp_and_spec.comp.name, port.name) return self._create_trimmer(begin, end, name) @@ -172,7 +192,9 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): raise bt2.Error('cannot find "utils" plugin (needed for the muxer)') if 'muxer' not in plugin.filter_component_classes: - raise bt2.Error('cannot find "muxer" filter component class in "utils" plugin') + raise bt2.Error( + 'cannot find "muxer" filter component class in "utils" plugin' + ) comp_cls = plugin.filter_component_classes['muxer'] return self._graph.add_component(comp_cls, 'muxer') @@ -184,7 +206,9 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): raise bt2.Error('cannot find "utils" plugin (needed for the trimmer)') if 'trimmer' not in plugin.filter_component_classes: - raise bt2.Error('cannot find "trimmer" filter component class in "utils" plugin') + raise bt2.Error( + 'cannot find "trimmer" filter component class in "utils" plugin' + ) params = {} @@ -203,10 +227,10 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): return self._graph.add_component(comp_cls, name, params) def _get_unique_comp_name(self, comp_spec): - name = '{}-{}'.format(comp_spec.plugin_name, - comp_spec.class_name) - comps_and_specs = itertools.chain(self._src_comps_and_specs, - self._flt_comps_and_specs) + name = '{}-{}'.format(comp_spec.plugin_name, comp_spec.class_name) + comps_and_specs = itertools.chain( + self._src_comps_and_specs, self._flt_comps_and_specs + ) if name in [comp_and_spec.comp.name for comp_and_spec in comps_and_specs]: name += '-{}'.format(self._next_suffix) @@ -227,14 +251,17 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): 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.class_name)) + raise bt2.Error( + 'no such {} component class in "{}" plugin: {}'.format( + cc_type, comp_spec.plugin_name, comp_spec.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, - comp_spec.logging_level) + comp = self._graph.add_component( + comp_cls, name, comp_spec.params, comp_spec.logging_level + ) return comp def _get_free_muxer_input_port(self): @@ -279,10 +306,10 @@ class TraceCollectionMessageIterator(bt2.message_iterator._MessageIterator): self._muxer_comp = self._create_muxer() if self._begin_ns is not None or self._end_ns is not None: - trimmer_comp = self._create_trimmer(self._begin_ns, - self._end_ns, 'trimmer') - self._graph.connect_ports(self._muxer_comp.output_ports['out'], - trimmer_comp.input_ports['in']) + trimmer_comp = self._create_trimmer(self._begin_ns, self._end_ns, 'trimmer') + self._graph.connect_ports( + self._muxer_comp.output_ports['out'], trimmer_comp.input_ports['in'] + ) msg_iter_port = trimmer_comp.output_ports['out'] else: msg_iter_port = self._muxer_comp.output_ports['out'] diff --git a/src/bindings/python/bt2/bt2/utils.py b/src/bindings/python/bt2/bt2/utils.py index 6d80fea2..1d983215 100644 --- a/src/bindings/python/bt2/bt2/utils.py +++ b/src/bindings/python/bt2/bt2/utils.py @@ -47,13 +47,14 @@ def _check_str(o): def _check_type(o, expected_type): if not isinstance(o, expected_type): - raise TypeError("'{}' is not a '{}' object".format(o.__class__.__name__, - expected_type)) + raise TypeError( + "'{}' is not a '{}' object".format(o.__class__.__name__, expected_type) + ) def _is_in_int64_range(v): - assert(isinstance(v, int)) - return v >= -(2**63) and v <= (2**63 - 1) + assert isinstance(v, int) + return v >= -(2 ** 63) and v <= (2 ** 63 - 1) def _is_int64(v): @@ -64,8 +65,8 @@ def _is_int64(v): def _is_in_uint64_range(v): - assert(isinstance(v, int)) - return v >= 0 and v <= (2**64 - 1) + assert isinstance(v, int) + return v >= 0 and v <= (2 ** 64 - 1) def _is_uint64(v): @@ -146,7 +147,10 @@ def _handle_func_status(status, msg=None): # no error return - if status == native_bt.__BT_FUNC_STATUS_ERROR or status == native_bt.__BT_FUNC_STATUS_MEMORY_ERROR: + if ( + status == native_bt.__BT_FUNC_STATUS_ERROR + or status == native_bt.__BT_FUNC_STATUS_MEMORY_ERROR + ): if msg is None: raise bt2.Error else: diff --git a/src/bindings/python/bt2/bt2/value.py b/src/bindings/python/bt2/bt2/value.py index 2710d903..3c883f76 100644 --- a/src/bindings/python/bt2/bt2/value.py +++ b/src/bindings/python/bt2/bt2/value.py @@ -78,7 +78,9 @@ def create_value(value): if isinstance(value, collections.abc.Mapping): return MapValue(value) - raise TypeError("cannot create value object from '{}' object".format(value.__class__.__name__)) + raise TypeError( + "cannot create value object from '{}' object".format(value.__class__.__name__) + ) class _Value(object._SharedObject, metaclass=abc.ABCMeta): @@ -91,7 +93,8 @@ class _Value(object._SharedObject, metaclass=abc.ABCMeta): def _check_create_status(self, ptr): if ptr is None: raise bt2.CreationError( - 'cannot create {} value object'.format(self._NAME.lower())) + 'cannot create {} value object'.format(self._NAME.lower()) + ) @functools.total_ordering @@ -110,7 +113,9 @@ class _NumericValue(_Value): if isinstance(other, numbers.Complex): return complex(other) - raise TypeError("'{}' object is not a number object".format(other.__class__.__name__)) + raise TypeError( + "'{}' object is not a number object".format(other.__class__.__name__) + ) def __int__(self): return int(self._value) @@ -253,7 +258,11 @@ class BoolValue(_IntegralValue): value = value._value if not isinstance(value, bool): - raise TypeError("'{}' object is not a 'bool' or 'BoolValue' object".format(value.__class__)) + raise TypeError( + "'{}' object is not a 'bool' or 'BoolValue' object".format( + value.__class__ + ) + ) return value @@ -440,13 +449,17 @@ class ArrayValue(_Container, collections.abc.MutableSequence, _Value): def __len__(self): size = native_bt.value_array_get_size(self._ptr) - assert(size >= 0) + assert size >= 0 return size def _check_index(self, index): # TODO: support slices also if not isinstance(index, numbers.Integral): - raise TypeError("'{}' object is not an integral number object: invalid index".format(index.__class__.__name__)) + raise TypeError( + "'{}' object is not an integral number object: invalid index".format( + index.__class__.__name__ + ) + ) index = int(index) @@ -456,7 +469,7 @@ class ArrayValue(_Container, collections.abc.MutableSequence, _Value): def __getitem__(self, index): self._check_index(index) ptr = native_bt.value_array_borrow_element_by_index(self._ptr, index) - assert(ptr) + assert ptr return _create_from_ptr_and_get_ref(ptr) def __setitem__(self, index, value): @@ -468,8 +481,7 @@ class ArrayValue(_Container, collections.abc.MutableSequence, _Value): else: ptr = value._ptr - status = native_bt.value_array_set_element_by_index( - self._ptr, index, ptr) + status = native_bt.value_array_set_element_by_index(self._ptr, index, ptr) utils._handle_func_status(status) def append(self, value): @@ -554,7 +566,7 @@ class MapValue(_Container, collections.abc.MutableMapping, _Value): def __len__(self): size = native_bt.value_map_get_size(self._ptr) - assert(size >= 0) + assert size >= 0 return size def __contains__(self, key): @@ -571,7 +583,7 @@ class MapValue(_Container, collections.abc.MutableMapping, _Value): def __getitem__(self, key): self._check_key(key) ptr = native_bt.value_map_borrow_entry_value(self._ptr, key) - assert(ptr) + assert ptr return _create_from_ptr_and_get_ref(ptr) def __iter__(self): diff --git a/src/bindings/python/bt2/setup.py.in b/src/bindings/python/bt2/setup.py.in index 0182305d..8172839c 100644 --- a/src/bindings/python/bt2/setup.py.in +++ b/src/bindings/python/bt2/setup.py.in @@ -34,46 +34,46 @@ following command to your .bashrc/.zshrc: -------------------------------------------------------------------------------- """ + def main(): - babeltrace_ext = Extension('bt2._native_bt', - sources=['bt2/native_bt.c', '@srcdir@/bt2/logging.c'], - libraries=['babeltrace2', 'glib-2.0'], - extra_objects=['@top_builddir@/src/logging/.libs/libbabeltrace2-logging.a', - '@top_builddir@/src/common/.libs/libbabeltrace2-common.a', - '@top_builddir@/src/py-common/.libs/libbabeltrace2-py-common.a']) + babeltrace_ext = Extension( + 'bt2._native_bt', + sources=['bt2/native_bt.c', '@srcdir@/bt2/logging.c'], + libraries=['babeltrace2', 'glib-2.0'], + extra_objects=[ + '@top_builddir@/src/logging/.libs/libbabeltrace2-logging.a', + '@top_builddir@/src/common/.libs/libbabeltrace2-common.a', + '@top_builddir@/src/py-common/.libs/libbabeltrace2-py-common.a', + ], + ) - dist = setup(name='bt2', - version='@PACKAGE_VERSION@', - description='Babeltrace 2 Python Bindings', - packages=['bt2'], - package_dir={'bt2': 'bt2'}, - options={'build': - { - 'build_base': 'build', - 'build_lib': 'build/build_lib' - }, - 'build_ext': - { - 'build_lib': 'build/build_lib' - } - }, - url='http://diamon.org/babeltrace', - ext_modules=[babeltrace_ext], - license='MIT', - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: The MIT License', - 'Programming Language :: Python :: 3' - 'Topic :: System :: Logging', - ]) + dist = setup( + name='bt2', + version='@PACKAGE_VERSION@', + description='Babeltrace 2 Python Bindings', + packages=['bt2'], + package_dir={'bt2': 'bt2'}, + options={ + 'build': {'build_base': 'build', 'build_lib': 'build/build_lib'}, + 'build_ext': {'build_lib': 'build/build_lib'}, + }, + url='http://diamon.org/babeltrace', + ext_modules=[babeltrace_ext], + license='MIT', + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: The MIT License', + 'Programming Language :: Python :: 3' 'Topic :: System :: Logging', + ], + ) -# After the installation, we check that the install directory is included in -# the Python search path and we print a warning message when it's not. -# We need to do this because Python search path differs depending on the distro -# and some distros don't include any /usr/local/ in the search path. This is -# also useful for out-of-tree installs and tests. -# It's only relevant to make this check on the `install` command. + # After the installation, we check that the install directory is included in + # the Python search path and we print a warning message when it's not. + # We need to do this because Python search path differs depending on the distro + # and some distros don't include any /usr/local/ in the search path. This is + # also useful for out-of-tree installs and tests. + # It's only relevant to make this check on the `install` command. if 'install' in dist.command_obj: install_dir = dist.command_obj['install'].install_libbase @@ -83,5 +83,6 @@ def main(): # extra configuration is needed to use the bindings print(PY_PATH_WARN_MSG.format(install_dir, install_dir)) + if __name__ == "__main__": main() diff --git a/tests/bindings/python/bt2/test_clock_class.py b/tests/bindings/python/bt2/test_clock_class.py index 53487c65..c8828ebf 100644 --- a/tests/bindings/python/bt2/test_clock_class.py +++ b/tests/bindings/python/bt2/test_clock_class.py @@ -169,7 +169,9 @@ class ClockClassTestCase(unittest.TestCase): def test_cycles_to_ns_from_origin(self): def f(comp_self): - return comp_self._create_clock_class(frequency=10**8, origin_is_unix_epoch=True) + return comp_self._create_clock_class( + frequency=10 ** 8, origin_is_unix_epoch=True + ) cc = run_in_component_init(f) self.assertEqual(cc.cycles_to_ns_from_origin(112), 1120) @@ -180,11 +182,13 @@ class ClockClassTestCase(unittest.TestCase): cc = run_in_component_init(f) with self.assertRaises(bt2.OverflowError): - cc.cycles_to_ns_from_origin(2**63) + cc.cycles_to_ns_from_origin(2 ** 63) def test_create_uuid(self): def f(comp_self): - return comp_self._create_clock_class(uuid=uuid.UUID('b43372c32ef0be28444dfc1c5cdafd33')) + return comp_self._create_clock_class( + uuid=uuid.UUID('b43372c32ef0be28444dfc1c5cdafd33') + ) cc = run_in_component_init(f) self.assertEqual(cc.uuid, uuid.UUID('b43372c32ef0be28444dfc1c5cdafd33')) @@ -199,8 +203,9 @@ class ClockClassTestCase(unittest.TestCase): class ClockSnapshotTestCase(unittest.TestCase): def setUp(self): def f(comp_self): - cc = comp_self._create_clock_class(1000, 'my_cc', - offset=bt2.ClockClassOffset(45, 354)) + cc = comp_self._create_clock_class( + 1000, 'my_cc', offset=bt2.ClockClassOffset(45, 354) + ) tc = comp_self._create_trace_class() return (cc, tc) @@ -224,7 +229,7 @@ class ClockSnapshotTestCase(unittest.TestCase): elif self._at == 1: notif = self._create_event_message(_ec, _stream, 123) elif self._at == 2: - notif = self._create_event_message(_ec, _stream, 2**63) + notif = self._create_event_message(_ec, _stream, 2 ** 63) elif self._at == 3: notif = self._create_stream_end_message(_stream) else: @@ -240,7 +245,8 @@ class ClockSnapshotTestCase(unittest.TestCase): self._graph = bt2.Graph() self._src_comp = self._graph.add_component(MySrc, 'my_source') self._msg_iter = self._graph.create_output_port_message_iterator( - self._src_comp.output_ports['out']) + self._src_comp.output_ports['out'] + ) for i, msg in enumerate(self._msg_iter): if i == 1: @@ -255,18 +261,21 @@ class ClockSnapshotTestCase(unittest.TestCase): def test_create_default(self): self.assertEqual( - self._msg.default_clock_snapshot.clock_class.addr, self._cc.addr) + self._msg.default_clock_snapshot.clock_class.addr, self._cc.addr + ) self.assertEqual(self._msg.default_clock_snapshot.value, 123) def test_clock_class(self): self.assertEqual( - self._msg.default_clock_snapshot.clock_class.addr, self._cc.addr) + self._msg.default_clock_snapshot.clock_class.addr, self._cc.addr + ) def test_ns_from_origin(self): s_from_origin = 45 + ((354 + 123) / 1000) ns_from_origin = int(s_from_origin * 1e9) self.assertEqual( - self._msg.default_clock_snapshot.ns_from_origin, ns_from_origin) + self._msg.default_clock_snapshot.ns_from_origin, ns_from_origin + ) def test_ns_from_origin_overflow(self): with self.assertRaises(bt2.OverflowError): diff --git a/tests/bindings/python/bt2/test_component_class.py b/tests/bindings/python/bt2/test_component_class.py index cece1a56..857d1527 100644 --- a/tests/bindings/python/bt2/test_component_class.py +++ b/tests/bindings/python/bt2/test_component_class.py @@ -31,8 +31,7 @@ class UserComponentClassTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): pass self._test_no_init(MySource) @@ -42,8 +41,7 @@ class UserComponentClassTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): pass self._test_no_init(MyFilter) @@ -63,6 +61,7 @@ class UserComponentClassTestCase(unittest.TestCase): pass with self.assertRaises(bt2.IncompleteUserClass): + class MySource(bt2._UserSourceComponent): pass @@ -71,8 +70,8 @@ class UserComponentClassTestCase(unittest.TestCase): pass with self.assertRaises(bt2.IncompleteUserClass): - class MySource(bt2._UserSourceComponent, - message_iterator_class=int): + + class MySource(bt2._UserSourceComponent, message_iterator_class=int): pass def test_incomplete_filter_no_msg_iter_cls(self): @@ -80,6 +79,7 @@ class UserComponentClassTestCase(unittest.TestCase): pass with self.assertRaises(bt2.IncompleteUserClass): + class MyFilter(bt2._UserFilterComponent): pass @@ -88,6 +88,7 @@ class UserComponentClassTestCase(unittest.TestCase): pass with self.assertRaises(bt2.IncompleteUserClass): + class MySink(bt2._UserSinkComponent): pass @@ -95,16 +96,14 @@ class UserComponentClassTestCase(unittest.TestCase): class MyIter(bt2._UserMessageIterator): pass - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): pass def test_minimal_filter(self): class MyIter(bt2._UserMessageIterator): pass - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): pass def test_minimal_sink(self): @@ -137,6 +136,7 @@ class UserComponentClassTestCase(unittest.TestCase): def test_invalid_custom_name(self): with self.assertRaises(TypeError): + class MySink(bt2._UserSinkComponent, name=23): def _consume(self): pass @@ -282,8 +282,7 @@ class UserComponentClassTestCase(unittest.TestCase): query_log_level = log_level query_log_level = None - res = bt2.QueryExecutor().query(MySink, 'obj', None, - bt2.LoggingLevel.WARNING) + res = bt2.QueryExecutor().query(MySink, 'obj', None, bt2.LoggingLevel.WARNING) self.assertEqual(query_log_level, bt2.LoggingLevel.WARNING) del query_log_level @@ -335,28 +334,18 @@ class UserComponentClassTestCase(unittest.TestCase): def _query(cls, query_exec, obj, params, log_level): nonlocal query_params query_params = params - return { - 'null': None, - 'bt2': 'BT2', - } + return {'null': None, 'bt2': 'BT2'} query_params = None params = { 'array': ['coucou', 23, None], - 'other_map': { - 'yes': 'yeah', - '19': 19, - 'minus 1.5': -1.5, - }, + 'other_map': {'yes': 'yeah', '19': 19, 'minus 1.5': -1.5}, 'null': None, } res = bt2.QueryExecutor().query(MySink, 'obj', params) self.assertEqual(query_params, params) - self.assertEqual(res, { - 'null': None, - 'bt2': 'BT2', - }) + self.assertEqual(res, {'null': None, 'bt2': 'BT2'}) del query_params def test_eq(self): @@ -378,6 +367,7 @@ class GenericComponentClassTestCase(unittest.TestCase): The help. ''' + def _consume(self): pass @@ -392,8 +382,9 @@ class GenericComponentClassTestCase(unittest.TestCase): graph = bt2.Graph() comp = graph.add_component(MySink, 'salut') self._comp_cls = comp.cls - self.assertTrue(issubclass(type(self._comp_cls), - bt2.component._GenericComponentClass)) + self.assertTrue( + issubclass(type(self._comp_cls), bt2.component._GenericComponentClass) + ) def tearDown(self): del self._py_comp_cls @@ -420,7 +411,8 @@ class GenericComponentClassTestCase(unittest.TestCase): self.assertEqual(self._py_comp_cls, self._comp_cls) def test_query(self): - res = bt2.QueryExecutor().query(self._comp_cls, 'an object', - {'yes': 'no', 'book': -17}) + res = bt2.QueryExecutor().query( + self._comp_cls, 'an object', {'yes': 'no', 'book': -17} + ) expected = ['an object', {'yes': 'no', 'book': -17}, 23] self.assertEqual(res, expected) diff --git a/tests/bindings/python/bt2/test_connection.py b/tests/bindings/python/bt2/test_connection.py index 7c1cbe57..686a75f7 100644 --- a/tests/bindings/python/bt2/test_connection.py +++ b/tests/bindings/python/bt2/test_connection.py @@ -26,8 +26,7 @@ class ConnectionTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -44,8 +43,7 @@ class ConnectionTestCase(unittest.TestCase): graph = bt2.Graph() src = graph.add_component(MySource, 'src') sink = graph.add_component(MySink, 'sink') - conn = graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) self.assertIsInstance(conn, bt2._Connection) def test_downstream_port(self): @@ -53,8 +51,7 @@ class ConnectionTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -71,8 +68,7 @@ class ConnectionTestCase(unittest.TestCase): graph = bt2.Graph() src = graph.add_component(MySource, 'src') sink = graph.add_component(MySink, 'sink') - conn = graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) self.assertEqual(conn.downstream_port.addr, sink.input_ports['in'].addr) def test_upstream_port(self): @@ -80,8 +76,7 @@ class ConnectionTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -98,6 +93,5 @@ class ConnectionTestCase(unittest.TestCase): graph = bt2.Graph() src = graph.add_component(MySource, 'src') sink = graph.add_component(MySink, 'sink') - conn = graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) self.assertEqual(conn.upstream_port.addr, src.output_ports['out'].addr) diff --git a/tests/bindings/python/bt2/test_ctf_writer_clock.py b/tests/bindings/python/bt2/test_ctf_writer_clock.py index d666579d..2653d7df 100644 --- a/tests/bindings/python/bt2/test_ctf_writer_clock.py +++ b/tests/bindings/python/bt2/test_ctf_writer_clock.py @@ -39,10 +39,15 @@ class CtfWriterClockTestCase(unittest.TestCase): def test_create_full(self): my_uuid = uuid.uuid1() - cc = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) + cc = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) self.assertEqual(cc.name, 'name') self.assertEqual(cc.description, 'some description') self.assertEqual(cc.frequency, 1001) @@ -122,97 +127,177 @@ class CtfWriterClockTestCase(unittest.TestCase): def test_eq(self): my_uuid = uuid.uuid1() - cc1 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) - cc2 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) + cc1 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) + cc2 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) self.assertEqual(cc1, cc2) def test_ne_name(self): my_uuid = uuid.uuid1() - cc1 = bt2.CtfWriterClock(name='mane', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) - cc2 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) + cc1 = bt2.CtfWriterClock( + name='mane', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) + cc2 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) self.assertNotEqual(cc1, cc2) def test_ne_description(self): my_uuid = uuid.uuid1() - cc1 = bt2.CtfWriterClock(name='name', description='some descripti2', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) - cc2 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) + cc1 = bt2.CtfWriterClock( + name='name', + description='some descripti2', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) + cc2 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) self.assertNotEqual(cc1, cc2) def test_ne_frequency(self): my_uuid = uuid.uuid1() - cc1 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1003, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) - cc2 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) + cc1 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1003, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) + cc2 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) self.assertNotEqual(cc1, cc2) def test_ne_precision(self): my_uuid = uuid.uuid1() - cc1 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=171, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) - cc2 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) + cc1 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=171, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) + cc2 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) self.assertNotEqual(cc1, cc2) def test_ne_offset(self): my_uuid = uuid.uuid1() - cc1 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3001), - is_absolute=True, uuid=my_uuid) - cc2 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) + cc1 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3001), + is_absolute=True, + uuid=my_uuid, + ) + cc2 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) self.assertNotEqual(cc1, cc2) def test_ne_absolute(self): my_uuid = uuid.uuid1() - cc1 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=my_uuid) - cc2 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=False, uuid=my_uuid) + cc1 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=my_uuid, + ) + cc2 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=False, + uuid=my_uuid, + ) self.assertNotEqual(cc1, cc2) def test_ne_uuid(self): - cc1 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=uuid.uuid1()) - cc2 = bt2.CtfWriterClock(name='name', description='some description', - frequency=1001, precision=176, - offset=bt2.ClockClassOffset(45, 3003), - is_absolute=True, uuid=uuid.uuid1()) + cc1 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=uuid.uuid1(), + ) + cc2 = bt2.CtfWriterClock( + name='name', + description='some description', + frequency=1001, + precision=176, + offset=bt2.ClockClassOffset(45, 3003), + is_absolute=True, + uuid=uuid.uuid1(), + ) self.assertNotEqual(cc1, cc2) def test_eq_invalid(self): diff --git a/tests/bindings/python/bt2/test_event.py b/tests/bindings/python/bt2/test_event.py index 77415000..74fe7cff 100644 --- a/tests/bindings/python/bt2/test_event.py +++ b/tests/bindings/python/bt2/test_event.py @@ -22,22 +22,26 @@ import bt2 class EventTestCase(unittest.TestCase): - def _create_test_event_message(self, packet_fields_config=None, - event_fields_config=None, - with_clockclass=False, - with_cc=False, with_sc=False, - with_ep=False, with_packet=False): - + def _create_test_event_message( + self, + packet_fields_config=None, + event_fields_config=None, + with_clockclass=False, + with_cc=False, + with_sc=False, + with_ep=False, + with_packet=False, + ): class MyIter(bt2._UserMessageIterator): def __init__(self, self_output_port): self._at = 0 - self._msgs = [ - self._create_stream_beginning_message(test_obj.stream), - ] + self._msgs = [self._create_stream_beginning_message(test_obj.stream)] if with_packet: assert test_obj.packet - self._msgs.append(self._create_packet_beginning_message(test_obj.packet)) + self._msgs.append( + self._create_packet_beginning_message(test_obj.packet) + ) default_clock_snapshot = 789 if with_clockclass else None @@ -48,7 +52,9 @@ class EventTestCase(unittest.TestCase): assert test_obj.stream ev_parent = test_obj.stream - msg = self._create_event_message(test_obj.event_class, ev_parent, default_clock_snapshot) + msg = self._create_event_message( + test_obj.event_class, ev_parent, default_clock_snapshot + ) if event_fields_config is not None: event_fields_config(msg.event) @@ -96,10 +102,12 @@ class EventTestCase(unittest.TestCase): ('something_else', tc.create_real_field_class()), ] - stream_class = tc.create_stream_class(default_clock_class=clock_class, - event_common_context_field_class=cc, - packet_context_field_class=pc, - supports_packets=with_packet) + stream_class = tc.create_stream_class( + default_clock_class=clock_class, + event_common_context_field_class=cc, + packet_context_field_class=pc, + supports_packets=with_packet, + ) # specific context (event-class-defined) sc = None @@ -120,9 +128,11 @@ class EventTestCase(unittest.TestCase): ('mosquito', tc.create_signed_integer_field_class(8)), ] - event_class = stream_class.create_event_class(name='garou', - specific_context_field_class=sc, - payload_field_class=ep) + event_class = stream_class.create_event_class( + name='garou', + specific_context_field_class=sc, + payload_field_class=ep, + ) trace = tc() stream = trace.create_stream(stream_class) @@ -143,7 +153,9 @@ class EventTestCase(unittest.TestCase): test_obj = self self._graph = bt2.Graph() self._src_comp = self._graph.add_component(MySrc, 'my_source') - self._msg_iter = self._graph.create_output_port_message_iterator(self._src_comp.output_ports['out']) + self._msg_iter = self._graph.create_output_port_message_iterator( + self._src_comp.output_ports['out'] + ) for msg in self._msg_iter: if type(msg) is bt2._EventMessage: @@ -166,7 +178,9 @@ class EventTestCase(unittest.TestCase): event.common_context_field['cpu_id'] = 1 event.common_context_field['stuff'] = 13.194 - msg = self._create_test_event_message(event_fields_config=event_fields_config, with_cc=True) + msg = self._create_test_event_message( + event_fields_config=event_fields_config, with_cc=True + ) self.assertEqual(msg.event.common_context_field['cpu_id'], 1) self.assertEqual(msg.event.common_context_field['stuff'], 13.194) @@ -180,7 +194,9 @@ class EventTestCase(unittest.TestCase): event.specific_context_field['ant'] = -1 event.specific_context_field['msg'] = 'hellooo' - msg = self._create_test_event_message(event_fields_config=event_fields_config, with_sc=True) + msg = self._create_test_event_message( + event_fields_config=event_fields_config, with_sc=True + ) self.assertEqual(msg.event.specific_context_field['ant'], -1) self.assertEqual(msg.event.specific_context_field['msg'], 'hellooo') @@ -195,7 +211,9 @@ class EventTestCase(unittest.TestCase): event.payload_field['gnu'] = 23 event.payload_field['mosquito'] = 42 - msg = self._create_test_event_message(event_fields_config=event_fields_config, with_ep=True) + msg = self._create_test_event_message( + event_fields_config=event_fields_config, with_ep=True + ) self.assertEqual(msg.event.payload_field['giraffe'], 1) self.assertEqual(msg.event.payload_field['gnu'], 23) @@ -232,10 +250,14 @@ class EventTestCase(unittest.TestCase): packet.context_field['something'] = 154 packet.context_field['something_else'] = 17.2 - msg = self._create_test_event_message(packet_fields_config=packet_fields_config, - event_fields_config=event_fields_config, - with_cc=True, with_sc=True, with_ep=True, - with_packet=True) + msg = self._create_test_event_message( + packet_fields_config=packet_fields_config, + event_fields_config=event_fields_config, + with_cc=True, + with_sc=True, + with_ep=True, + with_packet=True, + ) ev = msg.event # Test event fields diff --git a/tests/bindings/python/bt2/test_event_class.py b/tests/bindings/python/bt2/test_event_class.py index beab05cb..10d58a7f 100644 --- a/tests/bindings/python/bt2/test_event_class.py +++ b/tests/bindings/python/bt2/test_event_class.py @@ -27,12 +27,16 @@ class EventClassTestCase(unittest.TestCase): self._context_fc = self._tc.create_structure_field_class() self._context_fc.append_member('allo', self._tc.create_string_field_class()) - self._context_fc.append_member('zola', self._tc.create_signed_integer_field_class(18)) + self._context_fc.append_member( + 'zola', self._tc.create_signed_integer_field_class(18) + ) self._payload_fc = self._tc.create_structure_field_class() self._payload_fc.append_member('zoom', self._tc.create_string_field_class()) - self._stream_class = self._tc.create_stream_class(assigns_automatic_event_class_id=True) + self._stream_class = self._tc.create_stream_class( + assigns_automatic_event_class_id=True + ) def test_create_default(self): ec = self._stream_class.create_event_class() @@ -84,7 +88,9 @@ class EventClassTestCase(unittest.TestCase): self._stream_class.create_event_class(emf_uri=23) def test_create_log_level(self): - ec = self._stream_class.create_event_class(log_level=bt2.EventClassLogLevel.EMERGENCY) + ec = self._stream_class.create_event_class( + log_level=bt2.EventClassLogLevel.EMERGENCY + ) self.assertEqual(ec.log_level, bt2.EventClassLogLevel.EMERGENCY) def test_create_invalid_log_level(self): diff --git a/tests/bindings/python/bt2/test_field.py b/tests/bindings/python/bt2/test_field.py index f92142bc..b17c175b 100644 --- a/tests/bindings/python/bt2/test_field.py +++ b/tests/bindings/python/bt2/test_field.py @@ -27,10 +27,7 @@ import bt2 from utils import get_default_trace_class -_COMP_BINOPS = ( - operator.eq, - operator.ne, -) +_COMP_BINOPS = (operator.eq, operator.ne) # Create and return a stream with the field classes part of its stream packet @@ -38,14 +35,16 @@ _COMP_BINOPS = ( # # The stream is part of a dummy trace created from trace class `tc`. + def _create_stream(tc, ctx_field_classes): packet_context_fc = tc.create_structure_field_class() for name, fc in ctx_field_classes: packet_context_fc.append_member(name, fc) trace = tc() - stream_class = tc.create_stream_class(packet_context_field_class=packet_context_fc, - supports_packets=True) + stream_class = tc.create_stream_class( + packet_context_field_class=packet_context_fc, supports_packets=True + ) stream = trace.create_stream(stream_class) return stream @@ -56,6 +55,7 @@ def _create_stream(tc, ctx_field_classes): # The field is part of a dummy stream, itself part of a dummy trace created # from trace class `tc`. + def _create_field(tc, field_class): field_name = 'field' stream = _create_stream(tc, [(field_name, field_class)]) @@ -68,6 +68,7 @@ def _create_field(tc, field_class): # The field is part of a dummy stream, itself part of a dummy trace created # from trace class `tc`. It is made out of a dummy string field class. + def _create_string_field(tc): field_name = 'string_field' stream = _create_stream(tc, [(field_name, tc.create_string_field_class())]) @@ -81,6 +82,7 @@ def _create_string_field(tc): # from trace class `tc`. It is made out of a dummy static array field class, # with a dummy integer field class as element class. + def _create_int_array_field(tc, length): elem_fc = tc.create_signed_integer_field_class(32) fc = tc.create_static_array_field_class(elem_fc, length) @@ -96,6 +98,7 @@ def _create_int_array_field(tc, length): # from trace class `tc`. It is made out of a dummy static array field class, # with a dummy integer field class as element and length classes. + def _create_dynamic_array(tc): elem_fc = tc.create_signed_integer_field_class(32) len_fc = tc.create_signed_integer_field_class(32) @@ -113,6 +116,7 @@ def _create_dynamic_array(tc): # from trace class `tc`. It is made out of a dummy static array field class, # with a dummy struct field class as element class. + def _create_struct_array_field(tc, length): elem_fc = tc.create_structure_field_class() fc = tc.create_static_array_field_class(elem_fc, length) @@ -354,7 +358,7 @@ class _TestNumericField: test_cb(op, bt2.create_value(0.0)) def _test_binop_rhs_complex(self, test_cb, op): - test_cb(op, -23+19j) + test_cb(op, -23 + 19j) def _test_binop_rhs_zero_complex(self, test_cb, op): test_cb(op, 0j) @@ -570,13 +574,13 @@ class _TestNumericField: # Ignore this lint error: # E711 comparison to None should be 'if cond is None:' # since this is what we want to test (even though not good practice). - self.assertFalse(self._def == None) # noqa: E711 + self.assertFalse(self._def == None) # noqa: E711 def test_ne_none(self): # Ignore this lint error: # E711 comparison to None should be 'if cond is not None:' # since this is what we want to test (even though not good practice). - self.assertTrue(self._def != None) # noqa: E711 + self.assertTrue(self._def != None) # noqa: E711 # This is a list of binary operators used for @@ -662,79 +666,415 @@ def _inject_numeric_testing_methods(cls): # inject testing methods for each binary operation for name, binop in _BINOPS: - setattr(cls, test_binop_name('invalid_unknown'), partialmethod(_TestNumericField._test_binop_invalid_unknown, op=binop)) - setattr(cls, test_binop_name('invalid_none'), partialmethod(_TestNumericField._test_binop_invalid_none, op=binop)) - setattr(cls, test_binop_name('type_true'), partialmethod(_TestNumericField._test_binop_type_true, op=binop)) - setattr(cls, test_binop_name('type_pos_int'), partialmethod(_TestNumericField._test_binop_type_pos_int, op=binop)) - setattr(cls, test_binop_name('type_pos_vint'), partialmethod(_TestNumericField._test_binop_type_pos_vint, op=binop)) - setattr(cls, test_binop_name('value_true'), partialmethod(_TestNumericField._test_binop_value_true, op=binop)) - setattr(cls, test_binop_name('value_pos_int'), partialmethod(_TestNumericField._test_binop_value_pos_int, op=binop)) - setattr(cls, test_binop_name('value_pos_vint'), partialmethod(_TestNumericField._test_binop_value_pos_vint, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_true'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_true, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_int'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_pos_int, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_vint'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_pos_vint, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_true'), partialmethod(_TestNumericField._test_binop_lhs_value_same_true, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_int'), partialmethod(_TestNumericField._test_binop_lhs_value_same_pos_int, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_vint'), partialmethod(_TestNumericField._test_binop_lhs_value_same_pos_vint, op=binop)) - setattr(cls, test_binop_name('type_neg_int'), partialmethod(_TestNumericField._test_binop_type_neg_int, op=binop)) - setattr(cls, test_binop_name('type_neg_vint'), partialmethod(_TestNumericField._test_binop_type_neg_vint, op=binop)) - setattr(cls, test_binop_name('value_neg_int'), partialmethod(_TestNumericField._test_binop_value_neg_int, op=binop)) - setattr(cls, test_binop_name('value_neg_vint'), partialmethod(_TestNumericField._test_binop_value_neg_vint, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_int'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_neg_int, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_vint'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_neg_vint, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_int'), partialmethod(_TestNumericField._test_binop_lhs_value_same_neg_int, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_vint'), partialmethod(_TestNumericField._test_binop_lhs_value_same_neg_vint, op=binop)) - setattr(cls, test_binop_name('type_false'), partialmethod(_TestNumericField._test_binop_type_false, op=binop)) - setattr(cls, test_binop_name('type_zero_int'), partialmethod(_TestNumericField._test_binop_type_zero_int, op=binop)) - setattr(cls, test_binop_name('type_zero_vint'), partialmethod(_TestNumericField._test_binop_type_zero_vint, op=binop)) - setattr(cls, test_binop_name('value_false'), partialmethod(_TestNumericField._test_binop_value_false, op=binop)) - setattr(cls, test_binop_name('value_zero_int'), partialmethod(_TestNumericField._test_binop_value_zero_int, op=binop)) - setattr(cls, test_binop_name('value_zero_vint'), partialmethod(_TestNumericField._test_binop_value_zero_vint, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_false'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_false, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_int'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_int, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_vint'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_vint, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_false'), partialmethod(_TestNumericField._test_binop_lhs_value_same_false, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_int'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_int, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_vint'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_vint, op=binop)) - setattr(cls, test_binop_name('type_pos_float'), partialmethod(_TestNumericField._test_binop_type_pos_float, op=binop)) - setattr(cls, test_binop_name('type_neg_float'), partialmethod(_TestNumericField._test_binop_type_neg_float, op=binop)) - setattr(cls, test_binop_name('type_pos_vfloat'), partialmethod(_TestNumericField._test_binop_type_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('type_neg_vfloat'), partialmethod(_TestNumericField._test_binop_type_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('value_pos_float'), partialmethod(_TestNumericField._test_binop_value_pos_float, op=binop)) - setattr(cls, test_binop_name('value_neg_float'), partialmethod(_TestNumericField._test_binop_value_neg_float, op=binop)) - setattr(cls, test_binop_name('value_pos_vfloat'), partialmethod(_TestNumericField._test_binop_value_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('value_neg_vfloat'), partialmethod(_TestNumericField._test_binop_value_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_float'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_pos_float, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_float'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_neg_float, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_float'), partialmethod(_TestNumericField._test_binop_lhs_value_same_pos_float, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_float'), partialmethod(_TestNumericField._test_binop_lhs_value_same_neg_float, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_value_same_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_value_same_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('type_zero_float'), partialmethod(_TestNumericField._test_binop_type_zero_float, op=binop)) - setattr(cls, test_binop_name('type_zero_vfloat'), partialmethod(_TestNumericField._test_binop_type_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('value_zero_float'), partialmethod(_TestNumericField._test_binop_value_zero_float, op=binop)) - setattr(cls, test_binop_name('value_zero_vfloat'), partialmethod(_TestNumericField._test_binop_value_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_float'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_float, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_float'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_float, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('type_complex'), partialmethod(_TestNumericField._test_binop_type_complex, op=binop)) - setattr(cls, test_binop_name('type_zero_complex'), partialmethod(_TestNumericField._test_binop_type_zero_complex, op=binop)) - setattr(cls, test_binop_name('value_complex'), partialmethod(_TestNumericField._test_binop_value_complex, op=binop)) - setattr(cls, test_binop_name('value_zero_complex'), partialmethod(_TestNumericField._test_binop_value_zero_complex, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_complex'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_complex, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_complex'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_complex, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_complex'), partialmethod(_TestNumericField._test_binop_lhs_value_same_complex, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_complex'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_complex, op=binop)) + setattr( + cls, + test_binop_name('invalid_unknown'), + partialmethod(_TestNumericField._test_binop_invalid_unknown, op=binop), + ) + setattr( + cls, + test_binop_name('invalid_none'), + partialmethod(_TestNumericField._test_binop_invalid_none, op=binop), + ) + setattr( + cls, + test_binop_name('type_true'), + partialmethod(_TestNumericField._test_binop_type_true, op=binop), + ) + setattr( + cls, + test_binop_name('type_pos_int'), + partialmethod(_TestNumericField._test_binop_type_pos_int, op=binop), + ) + setattr( + cls, + test_binop_name('type_pos_vint'), + partialmethod(_TestNumericField._test_binop_type_pos_vint, op=binop), + ) + setattr( + cls, + test_binop_name('value_true'), + partialmethod(_TestNumericField._test_binop_value_true, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_int'), + partialmethod(_TestNumericField._test_binop_value_pos_int, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_vint'), + partialmethod(_TestNumericField._test_binop_value_pos_vint, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_true'), + partialmethod(_TestNumericField._test_binop_lhs_addr_same_true, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_int'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_pos_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_vint'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_pos_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_true'), + partialmethod(_TestNumericField._test_binop_lhs_value_same_true, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_int'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_pos_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_vint'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_pos_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_neg_int'), + partialmethod(_TestNumericField._test_binop_type_neg_int, op=binop), + ) + setattr( + cls, + test_binop_name('type_neg_vint'), + partialmethod(_TestNumericField._test_binop_type_neg_vint, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_int'), + partialmethod(_TestNumericField._test_binop_value_neg_int, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_vint'), + partialmethod(_TestNumericField._test_binop_value_neg_vint, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_int'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_neg_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_vint'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_neg_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_int'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_neg_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_vint'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_neg_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_false'), + partialmethod(_TestNumericField._test_binop_type_false, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_int'), + partialmethod(_TestNumericField._test_binop_type_zero_int, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_vint'), + partialmethod(_TestNumericField._test_binop_type_zero_vint, op=binop), + ) + setattr( + cls, + test_binop_name('value_false'), + partialmethod(_TestNumericField._test_binop_value_false, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_int'), + partialmethod(_TestNumericField._test_binop_value_zero_int, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_vint'), + partialmethod(_TestNumericField._test_binop_value_zero_vint, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_false'), + partialmethod(_TestNumericField._test_binop_lhs_addr_same_false, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_int'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_zero_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_vint'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_zero_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_false'), + partialmethod(_TestNumericField._test_binop_lhs_value_same_false, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_int'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_zero_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_vint'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_zero_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_pos_float'), + partialmethod(_TestNumericField._test_binop_type_pos_float, op=binop), + ) + setattr( + cls, + test_binop_name('type_neg_float'), + partialmethod(_TestNumericField._test_binop_type_neg_float, op=binop), + ) + setattr( + cls, + test_binop_name('type_pos_vfloat'), + partialmethod(_TestNumericField._test_binop_type_pos_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('type_neg_vfloat'), + partialmethod(_TestNumericField._test_binop_type_neg_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_float'), + partialmethod(_TestNumericField._test_binop_value_pos_float, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_float'), + partialmethod(_TestNumericField._test_binop_value_neg_float, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_vfloat'), + partialmethod(_TestNumericField._test_binop_value_pos_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_vfloat'), + partialmethod(_TestNumericField._test_binop_value_neg_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_float'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_pos_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_float'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_neg_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_vfloat'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_pos_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_vfloat'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_neg_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_float'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_pos_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_float'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_neg_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_vfloat'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_pos_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_vfloat'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_neg_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_zero_float'), + partialmethod(_TestNumericField._test_binop_type_zero_float, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_vfloat'), + partialmethod(_TestNumericField._test_binop_type_zero_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_float'), + partialmethod(_TestNumericField._test_binop_value_zero_float, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_vfloat'), + partialmethod(_TestNumericField._test_binop_value_zero_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_float'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_zero_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_vfloat'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_zero_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_float'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_zero_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_vfloat'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_zero_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_complex'), + partialmethod(_TestNumericField._test_binop_type_complex, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_complex'), + partialmethod(_TestNumericField._test_binop_type_zero_complex, op=binop), + ) + setattr( + cls, + test_binop_name('value_complex'), + partialmethod(_TestNumericField._test_binop_value_complex, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_complex'), + partialmethod(_TestNumericField._test_binop_value_zero_complex, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_complex'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_complex, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_complex'), + partialmethod( + _TestNumericField._test_binop_lhs_addr_same_zero_complex, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_complex'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_complex, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_complex'), + partialmethod( + _TestNumericField._test_binop_lhs_value_same_zero_complex, op=binop + ), + ) # inject testing methods for each unary operation for name, unaryop in _UNARYOPS: - setattr(cls, test_unaryop_name('type'), partialmethod(_TestNumericField._test_unaryop_type, op=unaryop)) - setattr(cls, test_unaryop_name('value'), partialmethod(_TestNumericField._test_unaryop_value, op=unaryop)) - setattr(cls, test_unaryop_name('addr_same'), partialmethod(_TestNumericField._test_unaryop_addr_same, op=unaryop)) - setattr(cls, test_unaryop_name('value_same'), partialmethod(_TestNumericField._test_unaryop_value_same, op=unaryop)) + setattr( + cls, + test_unaryop_name('type'), + partialmethod(_TestNumericField._test_unaryop_type, op=unaryop), + ) + setattr( + cls, + test_unaryop_name('value'), + partialmethod(_TestNumericField._test_unaryop_value, op=unaryop), + ) + setattr( + cls, + test_unaryop_name('addr_same'), + partialmethod(_TestNumericField._test_unaryop_addr_same, op=unaryop), + ) + setattr( + cls, + test_unaryop_name('value_same'), + partialmethod(_TestNumericField._test_unaryop_value_same, op=unaryop), + ) class _TestIntegerFieldCommon(_TestNumericField): @@ -781,8 +1121,8 @@ class _TestIntegerFieldCommon(_TestNumericField): field = _create_field(self._tc, uint_fc) # Larger than the IEEE 754 double-precision exact representation of # integers. - raw = (2**53) + 1 - field.value = (2**53) + 1 + raw = (2 ** 53) + 1 + field.value = (2 ** 53) + 1 self.assertEqual(field, raw) def test_assign_uint_invalid_neg(self): @@ -819,7 +1159,9 @@ class SignedEnumerationFieldTestCase(_TestIntegerFieldCommon, unittest.TestCase) fc.add_mapping('something', bt2.SignedIntegerRangeSet([(17, 17)])) fc.add_mapping('speaker', bt2.SignedIntegerRangeSet([(12, 16)])) fc.add_mapping('can', bt2.SignedIntegerRangeSet([(18, 2540)])) - fc.add_mapping('whole range', bt2.SignedIntegerRangeSet([(-(2 ** 31), (2 ** 31) - 1)])) + fc.add_mapping( + 'whole range', bt2.SignedIntegerRangeSet([(-(2 ** 31), (2 ** 31) - 1)]) + ) fc.add_mapping('zip', bt2.SignedIntegerRangeSet([(-45, 1001)])) return fc @@ -838,8 +1180,7 @@ class SignedEnumerationFieldTestCase(_TestIntegerFieldCommon, unittest.TestCase) # Establish all permutations of the three expected matches since # the order in which mappings are enumerated is not explicitly part of # the API. - for p in itertools.permutations(['whole range', 'something', - 'zip']): + for p in itertools.permutations(['whole range', 'something', 'zip']): candidate = '{} ({})'.format(self._def_value, ', '.join(p)) if candidate == s: expected_string_found = True @@ -1147,21 +1488,9 @@ class _TestArrayFieldCommon: array_fc = self._tc.create_static_array_field_class(struct_fc, 3) stream = _create_stream(self._tc, [('array_field', array_fc)]) values = [ - { - 'an_int': 42, - 'a_string': 'hello', - 'another_int': 66 - }, - { - 'an_int': 1, - 'a_string': 'goodbye', - 'another_int': 488 - }, - { - 'an_int': 156, - 'a_string': 'or not', - 'another_int': 4648 - }, + {'an_int': 42, 'a_string': 'hello', 'another_int': 66}, + {'an_int': 1, 'a_string': 'goodbye', 'another_int': 488}, + {'an_int': 156, 'a_string': 'or not', 'another_int': 4648}, ] array = stream.create_packet().context_field['array_field'] @@ -1173,8 +1502,7 @@ class _TestArrayFieldCommon: def test_str_op(self): s = str(self._def) - expected_string = '[{}]'.format(', '.join( - [repr(v) for v in self._def_value])) + expected_string = '[{}]'.format(', '.join([repr(v) for v in self._def_value])) self.assertEqual(expected_string, s) @@ -1254,7 +1582,7 @@ class StructureFieldTestCase(unittest.TestCase): 'C': 17.5, 'D': 16497, 'E': {}, - 'F': {'F_1': 52} + 'F': {'F_1': 52}, } def _modify_def(self): @@ -1280,7 +1608,7 @@ class StructureFieldTestCase(unittest.TestCase): self._def.member_at_index(len(self._def_value)) def test_eq(self): - field = _create_field(self._tc, self._create_fc(self._tc, )) + field = _create_field(self._tc, self._create_fc(self._tc)) field['A'] = -1872 field['B'] = 'salut' field['C'] = 17.5 @@ -1391,7 +1719,7 @@ class StructureFieldTestCase(unittest.TestCase): 'C': 17.5, 'D': 16497, 'E': {}, - 'F': {'F_1': 52} + 'F': {'F_1': 52}, } for vkey, vval in self._def.items(): @@ -1405,7 +1733,7 @@ class StructureFieldTestCase(unittest.TestCase): 'C': 17.5, 'D': 16497, 'E': {}, - 'F': {'F_1': 52} + 'F': {'F_1': 52}, } self.assertEqual(self._def, orig_values) @@ -1417,11 +1745,7 @@ class StructureFieldTestCase(unittest.TestCase): struct_fc.append_member(field_class=int_fc, name='an_int') struct_fc.append_member(field_class=str_fc, name='a_string') struct_fc.append_member(field_class=another_int_fc, name='another_int') - values = { - 'an_int': 42, - 'a_string': 'hello', - 'another_int': 66 - } + values = {'an_int': 42, 'a_string': 'hello', 'another_int': 66} struct = _create_field(self._tc, struct_fc) struct.value = values diff --git a/tests/bindings/python/bt2/test_field_class.py b/tests/bindings/python/bt2/test_field_class.py index 09303363..2b05f009 100644 --- a/tests/bindings/python/bt2/test_field_class.py +++ b/tests/bindings/python/bt2/test_field_class.py @@ -50,7 +50,9 @@ class _TestIntegerFieldClassProps: self._create_func(field_value_range=0) def test_create_base(self): - fc = self._create_func(preferred_display_base=bt2.IntegerDisplayBase.HEXADECIMAL) + fc = self._create_func( + preferred_display_base=bt2.IntegerDisplayBase.HEXADECIMAL + ) self.assertEqual(fc.preferred_display_base, bt2.IntegerDisplayBase.HEXADECIMAL) def test_create_invalid_base_type(self): @@ -94,6 +96,7 @@ class RealFieldClassTestCase(unittest.TestCase): # # [(lower0, upper0), (lower1, upper1), ...] + def enum_mapping_to_set(mapping): return {(x.lower, x.upper) for x in mapping.ranges} @@ -140,10 +143,7 @@ class _EnumerationFieldClassTestCase(_TestIntegerFieldClassProps): def test_iadd(self): self._fc.add_mapping('c', self._ranges1) - self._fc += [ - ('d', self._ranges2), - ('e', self._ranges3), - ] + self._fc += [('d', self._ranges2), ('e', self._ranges3)] self.assertEqual(len(self._fc), 3) self.assertEqual(self._fc['c'].label, 'c') @@ -196,7 +196,9 @@ class _EnumerationFieldClassTestCase(_TestIntegerFieldClassProps): self.assertEqual(labels, expected_labels) -class UnsignedEnumerationFieldClassTestCase(_EnumerationFieldClassTestCase, unittest.TestCase): +class UnsignedEnumerationFieldClassTestCase( + _EnumerationFieldClassTestCase, unittest.TestCase +): def _spec_set_up(self): self._ranges1 = bt2.UnsignedIntegerRangeSet([(1, 4), (18, 47)]) self._ranges2 = bt2.UnsignedIntegerRangeSet([(5, 5)]) @@ -206,7 +208,9 @@ class UnsignedEnumerationFieldClassTestCase(_EnumerationFieldClassTestCase, unit self._create_func = self._tc.create_unsigned_enumeration_field_class -class SignedEnumerationFieldClassTestCase(_EnumerationFieldClassTestCase, unittest.TestCase): +class SignedEnumerationFieldClassTestCase( + _EnumerationFieldClassTestCase, unittest.TestCase +): def _spec_set_up(self): self._ranges1 = bt2.SignedIntegerRangeSet([(-10, -4), (18, 47)]) self._ranges2 = bt2.SignedIntegerRangeSet([(-3, -3)]) @@ -225,7 +229,7 @@ class StringFieldClassTestCase(unittest.TestCase): self.assertIsNotNone(self._fc) -class _TestElementContainer(): +class _TestElementContainer: def setUp(self): self._tc = get_default_trace_class() self._fc = self._create_default_fc() @@ -270,7 +274,9 @@ class _TestElementContainer(): self._append_element_method(self._fc, 'a_float', a_field_class) self._append_element_method(self._fc, 'b_int', b_field_class) c_field_class = self._tc.create_string_field_class() - d_field_class = self._tc.create_signed_enumeration_field_class(field_value_range=32) + d_field_class = self._tc.create_signed_enumeration_field_class( + field_value_range=32 + ) e_field_class = self._tc.create_structure_field_class() self._fc += [ ('c_string', c_field_class), @@ -326,11 +332,7 @@ class _TestElementContainer(): a_fc = self._tc.create_signed_integer_field_class(32) b_fc = self._tc.create_string_field_class() c_fc = self._tc.create_real_field_class() - elements = ( - ('a', a_fc), - ('b', b_fc), - ('c', c_fc), - ) + elements = (('a', a_fc), ('b', b_fc), ('c', c_fc)) for elem in elements: self._append_element_method(self._fc, *elem) @@ -352,29 +354,43 @@ class _TestElementContainer(): self.assertEqual(elem.name, 'a') def test_at_index_invalid(self): - self._append_element_method(self._fc, 'c', self._tc.create_signed_integer_field_class(32)) + self._append_element_method( + self._fc, 'c', self._tc.create_signed_integer_field_class(32) + ) with self.assertRaises(TypeError): self._at_index_method(self._fc, 'yes') def test_at_index_out_of_bounds_after(self): - self._append_element_method(self._fc, 'c', self._tc.create_signed_integer_field_class(32)) + self._append_element_method( + self._fc, 'c', self._tc.create_signed_integer_field_class(32) + ) with self.assertRaises(IndexError): self._at_index_method(self._fc, len(self._fc)) class StructureFieldClassTestCase(_TestElementContainer, unittest.TestCase): - _append_element_method = staticmethod(bt2.field_class._StructureFieldClass.append_member) - _at_index_method = staticmethod(bt2.field_class._StructureFieldClass.member_at_index) + _append_element_method = staticmethod( + bt2.field_class._StructureFieldClass.append_member + ) + _at_index_method = staticmethod( + bt2.field_class._StructureFieldClass.member_at_index + ) def _create_default_fc(self): return self._tc.create_structure_field_class() -class VariantFieldClassWithoutSelectorTestCase(_TestElementContainer, unittest.TestCase): - _append_element_method = staticmethod(bt2.field_class._VariantFieldClassWithoutSelector.append_option) - _at_index_method = staticmethod(bt2.field_class._VariantFieldClassWithoutSelector.option_at_index) +class VariantFieldClassWithoutSelectorTestCase( + _TestElementContainer, unittest.TestCase +): + _append_element_method = staticmethod( + bt2.field_class._VariantFieldClassWithoutSelector.append_option + ) + _at_index_method = staticmethod( + bt2.field_class._VariantFieldClassWithoutSelector.option_at_index + ) def _create_default_fc(self): return self._tc.create_variant_field_class() @@ -402,8 +418,9 @@ class _VariantFieldClassWithSelectorTestCase: def test_append_element_kwargs(self): int_field_class = self._tc.create_signed_integer_field_class(32) - self._fc.append_option(name='int32', field_class=int_field_class, - ranges=self._ranges1) + self._fc.append_option( + name='int32', field_class=int_field_class, ranges=self._ranges1 + ) opt = self._fc['int32'] self.assertEqual(opt.field_class.addr, int_field_class.addr) self.assertEqual(opt.name, 'int32') @@ -444,7 +461,9 @@ class _VariantFieldClassWithSelectorTestCase: a_field_class = self._tc.create_real_field_class() self._fc.append_option('a_float', a_field_class, self._ranges1) c_field_class = self._tc.create_string_field_class() - d_field_class = self._tc.create_signed_enumeration_field_class(field_value_range=32) + d_field_class = self._tc.create_signed_enumeration_field_class( + field_value_range=32 + ) self._fc += [ ('c_string', c_field_class, self._ranges2), ('d_enum', d_field_class, self._ranges3), @@ -525,13 +544,17 @@ class _VariantFieldClassWithSelectorTestCase: self.assertEqual(self._fc.option_at_index(1).ranges.addr, self._ranges2.addr) def test_at_index_invalid(self): - self._fc.append_option('c', self._tc.create_signed_integer_field_class(32), self._ranges3) + self._fc.append_option( + 'c', self._tc.create_signed_integer_field_class(32), self._ranges3 + ) with self.assertRaises(TypeError): self._fc.option_at_index('yes') def test_at_index_out_of_bounds_after(self): - self._fc.append_option('c', self._tc.create_signed_integer_field_class(32), self._ranges3) + self._fc.append_option( + 'c', self._tc.create_signed_integer_field_class(32), self._ranges3 + ) with self.assertRaises(IndexError): self._fc.option_at_index(len(self._fc)) @@ -553,8 +576,12 @@ class _VariantFieldClassWithSelectorTestCase: # } inner_struct[2]; # }; self._fc.append_option('a', self._tc.create_real_field_class(), self._ranges1) - self._fc.append_option('b', self._tc.create_signed_integer_field_class(21), self._ranges2) - self._fc.append_option('c', self._tc.create_unsigned_integer_field_class(34), self._ranges3) + self._fc.append_option( + 'b', self._tc.create_signed_integer_field_class(21), self._ranges2 + ) + self._fc.append_option( + 'c', self._tc.create_unsigned_integer_field_class(34), self._ranges3 + ) foo_fc = self._tc.create_real_field_class() bar_fc = self._tc.create_string_field_class() @@ -566,7 +593,9 @@ class _VariantFieldClassWithSelectorTestCase: inner_struct_fc.append_member('baz', baz_fc) inner_struct_fc.append_member('variant', self._fc) - inner_struct_array_fc = self._tc.create_static_array_field_class(inner_struct_fc, 2) + inner_struct_array_fc = self._tc.create_static_array_field_class( + inner_struct_fc, 2 + ) outer_struct_fc = self._tc.create_structure_field_class() outer_struct_fc.append_member('foo', foo_fc) @@ -574,8 +603,9 @@ class _VariantFieldClassWithSelectorTestCase: # The path to the selector field is resolved when the sequence is # actually used, for example in a packet context. - self._tc.create_stream_class(supports_packets=True, - packet_context_field_class=outer_struct_fc) + self._tc.create_stream_class( + supports_packets=True, packet_context_field_class=outer_struct_fc + ) def test_selector_field_path_length(self): self._fill_default_fc_for_field_path_test() @@ -590,17 +620,23 @@ class _VariantFieldClassWithSelectorTestCase: self.assertIsInstance(path_items[0], bt2.field_path._IndexFieldPathItem) self.assertEqual(path_items[0].index, 1) - self.assertIsInstance(path_items[1], bt2.field_path._CurrentArrayElementFieldPathItem) + self.assertIsInstance( + path_items[1], bt2.field_path._CurrentArrayElementFieldPathItem + ) self.assertIsInstance(path_items[2], bt2.field_path._IndexFieldPathItem) self.assertEqual(path_items[2].index, 0) def test_selector_field_path_root_scope(self): self._fill_default_fc_for_field_path_test() - self.assertEqual(self._fc.selector_field_path.root_scope, bt2.field_path.Scope.PACKET_CONTEXT) + self.assertEqual( + self._fc.selector_field_path.root_scope, bt2.field_path.Scope.PACKET_CONTEXT + ) -class VariantFieldClassWithUnsignedSelectorTestCase(_VariantFieldClassWithSelectorTestCase, unittest.TestCase): +class VariantFieldClassWithUnsignedSelectorTestCase( + _VariantFieldClassWithSelectorTestCase, unittest.TestCase +): def _spec_set_up(self): self._ranges1 = bt2.UnsignedIntegerRangeSet([(1, 4), (18, 47)]) self._ranges2 = bt2.UnsignedIntegerRangeSet([(5, 5)]) @@ -609,7 +645,9 @@ class VariantFieldClassWithUnsignedSelectorTestCase(_VariantFieldClassWithSelect self._selector_fc = self._tc.create_unsigned_integer_field_class() -class VariantFieldClassWithSignedSelectorTestCase(_VariantFieldClassWithSelectorTestCase, unittest.TestCase): +class VariantFieldClassWithSignedSelectorTestCase( + _VariantFieldClassWithSelectorTestCase, unittest.TestCase +): def _spec_set_up(self): self._ranges1 = bt2.SignedIntegerRangeSet([(-10, -4), (18, 47)]) self._ranges2 = bt2.SignedIntegerRangeSet([(-3, -3)]) @@ -634,11 +672,15 @@ class StaticArrayFieldClassTestCase(unittest.TestCase): def test_create_invalid_length(self): with self.assertRaises(ValueError): - self._tc.create_static_array_field_class(self._tc.create_string_field_class(), -17) + self._tc.create_static_array_field_class( + self._tc.create_string_field_class(), -17 + ) def test_create_invalid_length_type(self): with self.assertRaises(TypeError): - self._tc.create_static_array_field_class(self._tc.create_string_field_class(), 'the length') + self._tc.create_static_array_field_class( + self._tc.create_string_field_class(), 'the length' + ) class DynamicArrayFieldClassTestCase(unittest.TestCase): @@ -677,7 +719,9 @@ class DynamicArrayFieldClassTestCase(unittest.TestCase): inner_struct_fc.append_member('len', self._len_fc) inner_struct_fc.append_member('dyn_array', fc) - inner_struct_array_fc = self._tc.create_static_array_field_class(inner_struct_fc, 2) + inner_struct_array_fc = self._tc.create_static_array_field_class( + inner_struct_fc, 2 + ) outer_struct_fc = self._tc.create_structure_field_class() outer_struct_fc.append_member('foo', foo_fc) @@ -685,8 +729,9 @@ class DynamicArrayFieldClassTestCase(unittest.TestCase): # The path to the length field is resolved when the sequence is # actually used, for example in a packet context. - self._tc.create_stream_class(packet_context_field_class=outer_struct_fc, - supports_packets=True) + self._tc.create_stream_class( + packet_context_field_class=outer_struct_fc, supports_packets=True + ) return fc @@ -703,14 +748,18 @@ class DynamicArrayFieldClassTestCase(unittest.TestCase): self.assertIsInstance(path_items[0], bt2.field_path._IndexFieldPathItem) self.assertEqual(path_items[0].index, 1) - self.assertIsInstance(path_items[1], bt2.field_path._CurrentArrayElementFieldPathItem) + self.assertIsInstance( + path_items[1], bt2.field_path._CurrentArrayElementFieldPathItem + ) self.assertIsInstance(path_items[2], bt2.field_path._IndexFieldPathItem) self.assertEqual(path_items[2].index, 2) def test_field_path_root_scope(self): fc = self._create_field_class_for_field_path_test() - self.assertEqual(fc.length_field_path.root_scope, bt2.field_path.Scope.PACKET_CONTEXT) + self.assertEqual( + fc.length_field_path.root_scope, bt2.field_path.Scope.PACKET_CONTEXT + ) def test_create_invalid_field_class(self): with self.assertRaises(TypeError): @@ -718,7 +767,9 @@ class DynamicArrayFieldClassTestCase(unittest.TestCase): def test_create_invalid_length_type(self): with self.assertRaises(TypeError): - self._tc.create_dynamic_array_field_class(self._tc.create_string_field_class(), 17) + self._tc.create_dynamic_array_field_class( + self._tc.create_string_field_class(), 17 + ) if __name__ == "__main__": diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index da9c209f..1c183c9b 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -35,9 +35,7 @@ class _MyIter(bt2._UserMessageIterator): self._ec = self._sc.create_event_class(name='salut') self._my_int_ft = self._tc.create_signed_integer_field_class(32) payload_ft = self._tc.create_structure_field_class() - payload_ft += [ - ('my_int', self._my_int_ft), - ] + payload_ft += [('my_int', self._my_int_ft)] self._ec.payload_field_type = payload_ft self._stream = self._t.create_stream(self._sc) self._packet = self._stream.create_packet() @@ -63,6 +61,7 @@ class GraphTestCase(unittest.TestCase): class MySink(bt2._UserSinkComponent): def _consume(self): pass + def _graph_is_configured(self): pass @@ -73,6 +72,7 @@ class GraphTestCase(unittest.TestCase): class MySink(bt2._UserSinkComponent): def _consume(self): pass + def _graph_is_configured(self): pass @@ -91,6 +91,7 @@ class GraphTestCase(unittest.TestCase): def _consume(self): pass + def _graph_is_configured(self): pass @@ -107,6 +108,7 @@ class GraphTestCase(unittest.TestCase): class MySink(bt2._UserSinkComponent): def _consume(self): pass + def _graph_is_configured(self): pass @@ -117,6 +119,7 @@ class GraphTestCase(unittest.TestCase): class MySink(bt2._UserSinkComponent): def _consume(self): pass + def _graph_is_configured(self): pass @@ -127,11 +130,13 @@ class GraphTestCase(unittest.TestCase): class MySink(bt2._UserSinkComponent): def _consume(self): pass + def _graph_is_configured(self): pass - comp = self._graph.add_component(MySink, 'salut', - logging_level=bt2.LoggingLevel.DEBUG) + comp = self._graph.add_component( + MySink, 'salut', logging_level=bt2.LoggingLevel.DEBUG + ) self.assertEqual(comp.logging_level, bt2.LoggingLevel.DEBUG) def test_connect_ports(self): @@ -139,8 +144,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -157,8 +161,9 @@ class GraphTestCase(unittest.TestCase): src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') - conn = self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = self._graph.connect_ports( + src.output_ports['out'], sink.input_ports['in'] + ) self.assertTrue(src.output_ports['out'].is_connected) self.assertTrue(sink.input_ports['in'].is_connected) self.assertEqual(src.output_ports['out'].connection.addr, conn.addr) @@ -169,8 +174,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -188,8 +192,9 @@ class GraphTestCase(unittest.TestCase): sink = self._graph.add_component(MySink, 'sink') with self.assertRaises(TypeError): - conn = self._graph.connect_ports(sink.input_ports['in'], - src.output_ports['out']) + conn = self._graph.connect_ports( + sink.input_ports['in'], src.output_ports['out'] + ) def test_cancel(self): self.assertFalse(self._graph.is_canceled) @@ -203,8 +208,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): return self._create_stream_beginning_message(self._stream) - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -249,8 +253,7 @@ class GraphTestCase(unittest.TestCase): self._at += 1 return msg - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -281,8 +284,9 @@ class GraphTestCase(unittest.TestCase): src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') - conn = self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = self._graph.connect_ports( + src.output_ports['out'], sink.input_ports['in'] + ) self._graph.run() def test_run_again(self): @@ -301,8 +305,7 @@ class GraphTestCase(unittest.TestCase): self._at += 1 return msg - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -330,8 +333,9 @@ class GraphTestCase(unittest.TestCase): src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') - conn = self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = self._graph.connect_ports( + src.output_ports['out'], sink.input_ports['in'] + ) with self.assertRaises(bt2.TryAgain): self._graph.run() @@ -357,8 +361,7 @@ class GraphTestCase(unittest.TestCase): self._at += 1 return msg - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -387,8 +390,9 @@ class GraphTestCase(unittest.TestCase): src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') - conn = self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = self._graph.connect_ports( + src.output_ports['out'], sink.input_ports['in'] + ) with self.assertRaises(bt2.Error): self._graph.run() @@ -398,8 +402,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') self._add_output_port('zero') @@ -421,20 +424,26 @@ class GraphTestCase(unittest.TestCase): nonlocal calls calls.append((port_added_listener, component, port)) - def ports_connected_listener(upstream_component, upstream_port, - downstream_component, downstream_port): + def ports_connected_listener( + upstream_component, upstream_port, downstream_component, downstream_port + ): nonlocal calls - calls.append((ports_connected_listener, - upstream_component, upstream_port, - downstream_component, downstream_port)) + calls.append( + ( + ports_connected_listener, + upstream_component, + upstream_port, + downstream_component, + downstream_port, + ) + ) calls = [] self._graph.add_port_added_listener(port_added_listener) self._graph.add_ports_connected_listener(ports_connected_listener) src = self._graph.add_component(MySource, 'src') sink = self._graph.add_component(MySink, 'sink') - self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + self._graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) self.assertEqual(len(calls), 5) @@ -465,8 +474,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') self._add_output_port('zero') @@ -530,8 +538,7 @@ class GraphTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -545,8 +552,9 @@ class GraphTestCase(unittest.TestCase): def _graph_is_configured(self): pass - def ports_connected_listener(upstream_component, upstream_port, - downstream_component, downstream_port): + def ports_connected_listener( + upstream_component, upstream_port, downstream_component, downstream_port + ): raise ValueError('oh noes!') graph = bt2.Graph() diff --git a/tests/bindings/python/bt2/test_integer_range_set.py b/tests/bindings/python/bt2/test_integer_range_set.py index 2a9c5f61..9188025a 100644 --- a/tests/bindings/python/bt2/test_integer_range_set.py +++ b/tests/bindings/python/bt2/test_integer_range_set.py @@ -110,11 +110,13 @@ class _IntegerRangeSetTestCase: self.assertIn(self._range3, self._rs) def test_create_tuples(self): - rs = self._CLS(( - (self._range1.lower, self._range1.upper), - (self._range2.lower, self._range2.upper), - (self._range3.lower, self._range3.upper), - )) + rs = self._CLS( + ( + (self._range1.lower, self._range1.upper), + (self._range2.lower, self._range2.upper), + (self._range3.lower, self._range3.upper), + ) + ) self.assertEqual(len(rs), 3) self.assertIn(self._range1, rs) self.assertIn(self._range2, rs) diff --git a/tests/bindings/python/bt2/test_message.py b/tests/bindings/python/bt2/test_message.py index a432ec71..5b513361 100644 --- a/tests/bindings/python/bt2/test_message.py +++ b/tests/bindings/python/bt2/test_message.py @@ -23,34 +23,53 @@ import bt2 class AllMessagesTestCase(unittest.TestCase): def setUp(self): - class MyIter(bt2._UserMessageIterator): def __init__(self, self_port_output): self._at = 0 - self._with_stream_msgs_clock_snapshots = self_port_output.user_data.get('with_stream_msgs_clock_snapshots', False) + self._with_stream_msgs_clock_snapshots = self_port_output.user_data.get( + 'with_stream_msgs_clock_snapshots', False + ) def __next__(self): if test_obj._clock_class: if self._at == 0: if self._with_stream_msgs_clock_snapshots: - msg = self._create_stream_beginning_message(test_obj._stream, default_clock_snapshot=self._at) + msg = self._create_stream_beginning_message( + test_obj._stream, default_clock_snapshot=self._at + ) else: - msg = self._create_stream_beginning_message(test_obj._stream) + msg = self._create_stream_beginning_message( + test_obj._stream + ) elif self._at == 1: - msg = self._create_packet_beginning_message(test_obj._packet, self._at) + msg = self._create_packet_beginning_message( + test_obj._packet, self._at + ) elif self._at == 2: - msg = self._create_event_message(test_obj._event_class, test_obj._packet, self._at) + msg = self._create_event_message( + test_obj._event_class, test_obj._packet, self._at + ) elif self._at == 3: - msg = self._create_message_iterator_inactivity_message(test_obj._clock_class, self._at) + msg = self._create_message_iterator_inactivity_message( + test_obj._clock_class, self._at + ) elif self._at == 4: - msg = self._create_discarded_events_message(test_obj._stream, 890, self._at, self._at) + msg = self._create_discarded_events_message( + test_obj._stream, 890, self._at, self._at + ) elif self._at == 5: - msg = self._create_packet_end_message(test_obj._packet, self._at) + msg = self._create_packet_end_message( + test_obj._packet, self._at + ) elif self._at == 6: - msg = self._create_discarded_packets_message(test_obj._stream, 678, self._at, self._at) + msg = self._create_discarded_packets_message( + test_obj._stream, 678, self._at, self._at + ) elif self._at == 7: if self._with_stream_msgs_clock_snapshots: - msg = self._create_stream_end_message(test_obj._stream, default_clock_snapshot=self._at) + msg = self._create_stream_end_message( + test_obj._stream, default_clock_snapshot=self._at + ) else: msg = self._create_stream_end_message(test_obj._stream) elif self._at >= 8: @@ -61,13 +80,19 @@ class AllMessagesTestCase(unittest.TestCase): elif self._at == 1: msg = self._create_packet_beginning_message(test_obj._packet) elif self._at == 2: - msg = self._create_event_message(test_obj._event_class, test_obj._packet) + msg = self._create_event_message( + test_obj._event_class, test_obj._packet + ) elif self._at == 3: - msg = self._create_discarded_events_message(test_obj._stream, 890) + msg = self._create_discarded_events_message( + test_obj._stream, 890 + ) elif self._at == 4: msg = self._create_packet_end_message(test_obj._packet) elif self._at == 5: - msg = self._create_discarded_packets_message(test_obj._stream, 678) + msg = self._create_discarded_packets_message( + test_obj._stream, 678 + ) elif self._at == 6: msg = self._create_stream_end_message(test_obj._stream) elif self._at >= 7: @@ -87,21 +112,21 @@ class AllMessagesTestCase(unittest.TestCase): else: cc = None - sc = tc.create_stream_class(default_clock_class=cc, - supports_packets=True, - packets_have_beginning_default_clock_snapshot=with_cc, - packets_have_end_default_clock_snapshot=with_cc, - supports_discarded_events=True, - discarded_events_have_default_clock_snapshots=with_cc, - supports_discarded_packets=True, - discarded_packets_have_default_clock_snapshots=with_cc) + sc = tc.create_stream_class( + default_clock_class=cc, + supports_packets=True, + packets_have_beginning_default_clock_snapshot=with_cc, + packets_have_end_default_clock_snapshot=with_cc, + supports_discarded_events=True, + discarded_events_have_default_clock_snapshots=with_cc, + supports_discarded_packets=True, + discarded_packets_have_default_clock_snapshots=with_cc, + ) # 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)] ec = sc.create_event_class(name='salut', payload_field_class=payload_fc) @@ -123,13 +148,17 @@ class AllMessagesTestCase(unittest.TestCase): def test_all_msg_with_cc(self): params = {'with_cc': True} self._src_comp = self._graph.add_component(self._src, 'my_source', params) - self._msg_iter = self._graph.create_output_port_message_iterator(self._src_comp.output_ports['out']) + self._msg_iter = self._graph.create_output_port_message_iterator( + self._src_comp.output_ports['out'] + ) for i, msg in enumerate(self._msg_iter): if i == 0: self.assertIsInstance(msg, bt2.message._StreamBeginningMessage) self.assertEqual(msg.stream.addr, self._stream.addr) - self.assertIsInstance(msg.default_clock_snapshot, bt2.clock_snapshot._UnknownClockSnapshot) + self.assertIsInstance( + msg.default_clock_snapshot, bt2.clock_snapshot._UnknownClockSnapshot + ) elif i == 1: self.assertIsInstance(msg, bt2.message._PacketBeginningMessage) self.assertEqual(msg.packet.addr, self._packet.addr) @@ -139,13 +168,17 @@ class AllMessagesTestCase(unittest.TestCase): self.assertEqual(msg.event.cls.addr, self._event_class.addr) self.assertEqual(msg.default_clock_snapshot.value, i) elif i == 3: - self.assertIsInstance(msg, bt2.message._MessageIteratorInactivityMessage) + self.assertIsInstance( + msg, bt2.message._MessageIteratorInactivityMessage + ) self.assertEqual(msg.default_clock_snapshot.value, i) elif i == 4: self.assertIsInstance(msg, bt2.message._DiscardedEventsMessage) self.assertEqual(msg.stream.addr, self._stream.addr) self.assertEqual(msg.count, 890) - self.assertEqual(msg.stream.cls.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 == 5: @@ -156,20 +189,26 @@ 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.cls.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 == 7: self.assertIsInstance(msg, bt2.message._StreamEndMessage) self.assertEqual(msg.stream.addr, self._stream.addr) - self.assertIsInstance(msg.default_clock_snapshot, bt2.clock_snapshot._UnknownClockSnapshot) + self.assertIsInstance( + msg.default_clock_snapshot, bt2.clock_snapshot._UnknownClockSnapshot + ) else: 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) - self._msg_iter = self._graph.create_output_port_message_iterator(self._src_comp.output_ports['out']) + self._msg_iter = self._graph.create_output_port_message_iterator( + self._src_comp.output_ports['out'] + ) for i, msg in enumerate(self._msg_iter): if i == 0: @@ -215,13 +254,12 @@ class AllMessagesTestCase(unittest.TestCase): 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._msg_iter = self._graph.create_output_port_message_iterator(self._src_comp.output_ports['out']) + self._msg_iter = self._graph.create_output_port_message_iterator( + self._src_comp.output_ports['out'] + ) msgs = list(self._msg_iter) msg_stream_beg = msgs[0] diff --git a/tests/bindings/python/bt2/test_message_iterator.py b/tests/bindings/python/bt2/test_message_iterator.py index 84912983..869c072c 100644 --- a/tests/bindings/python/bt2/test_message_iterator.py +++ b/tests/bindings/python/bt2/test_message_iterator.py @@ -1,4 +1,3 @@ - # # Copyright (C) 2019 EfficiOS Inc. # @@ -40,8 +39,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): graph = bt2.Graph() src_comp = graph.add_component(src_comp_cls, 'src') sink_comp = graph.add_component(MySink, 'sink') - graph.connect_ports(src_comp.output_ports['out'], - sink_comp.input_ports['in']) + graph.connect_ports(src_comp.output_ports['out'], sink_comp.input_ports['in']) return graph def test_init(self): @@ -55,8 +53,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): initialized = True the_output_port_from_iter = self_port_output - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): nonlocal the_output_port_from_source the_output_port_from_source = self._add_output_port('out', 'user data') @@ -65,7 +62,9 @@ class UserMessageIteratorTestCase(unittest.TestCase): graph = self._create_graph(MySource) graph.run() self.assertTrue(initialized) - self.assertEqual(the_output_port_from_source.addr, the_output_port_from_iter.addr) + self.assertEqual( + the_output_port_from_source.addr, the_output_port_from_iter.addr + ) self.assertEqual(the_output_port_from_iter.user_data, 'user data') def test_finalize(self): @@ -74,8 +73,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): nonlocal finalized finalized = True - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -91,8 +89,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): nonlocal salut salut = self._component._salut - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') self._salut = 23 @@ -108,8 +105,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): nonlocal addr addr = self.addr - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -201,8 +197,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): else: raise StopIteration - class MySource(bt2._UserSourceComponent, - message_iterator_class=MySourceIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MySourceIter): def __init__(self, params): tc = self._create_trace_class() sc = tc.create_stream_class(supports_packets=True) @@ -230,7 +225,6 @@ class UserMessageIteratorTestCase(unittest.TestCase): input_port = self._add_input_port('in') self._add_output_port('out', input_port) - graph = bt2.Graph() src = graph.add_component(MySource, 'src') flt = graph.add_component(MyFilter, 'flt') @@ -299,7 +293,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): it, MySourceIter = self._setup_seek_beginning_test() def _seek_beginning_error(self): - raise ValueError('ouch') + raise ValueError('ouch') MySourceIter._seek_beginning = _seek_beginning_error @@ -307,7 +301,6 @@ class UserMessageIteratorTestCase(unittest.TestCase): it.seek_beginning() - class OutputPortMessageIteratorTestCase(unittest.TestCase): def test_component(self): class MyIter(bt2._UserMessageIterator): @@ -327,14 +320,15 @@ class OutputPortMessageIteratorTestCase(unittest.TestCase): elif self._at == 6: msg = self._create_stream_end_message(test_obj._stream) else: - msg = self._create_event_message(test_obj._event_class, test_obj._packet) + msg = self._create_event_message( + test_obj._event_class, test_obj._packet + ) msg.event.payload_field['my_int'] = self._at * 3 self._at += 1 return msg - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, params): self._add_output_port('out') @@ -344,11 +338,11 @@ class OutputPortMessageIteratorTestCase(unittest.TestCase): # Create payload field class my_int_ft = trace_class.create_signed_integer_field_class(32) payload_ft = trace_class.create_structure_field_class() - payload_ft += [ - ('my_int', my_int_ft), - ] + payload_ft += [('my_int', my_int_ft)] - event_class = stream_class.create_event_class(name='salut', payload_field_class=payload_ft) + event_class = stream_class.create_event_class( + name='salut', payload_field_class=payload_ft + ) trace = trace_class() stream = trace.create_stream(stream_class) @@ -378,5 +372,6 @@ class OutputPortMessageIteratorTestCase(unittest.TestCase): field = msg.event.payload_field['my_int'] self.assertEqual(field, at * 3) + if __name__ == '__main__': unittest.main() diff --git a/tests/bindings/python/bt2/test_packet.py b/tests/bindings/python/bt2/test_packet.py index 0b2a85b9..59fa2b45 100644 --- a/tests/bindings/python/bt2/test_packet.py +++ b/tests/bindings/python/bt2/test_packet.py @@ -50,10 +50,12 @@ class PacketTestCase(unittest.TestCase): ] # stream class - sc = tc.create_stream_class(default_clock_class=clock_class, - event_common_context_field_class=sec, - packet_context_field_class=pc, - supports_packets=True) + sc = tc.create_stream_class( + default_clock_class=clock_class, + event_common_context_field_class=sec, + packet_context_field_class=pc, + supports_packets=True, + ) # event context ec = tc.create_structure_field_class() diff --git a/tests/bindings/python/bt2/test_plugin.py b/tests/bindings/python/bt2/test_plugin.py index 2096d84b..e0bf9451 100644 --- a/tests/bindings/python/bt2/test_plugin.py +++ b/tests/bindings/python/bt2/test_plugin.py @@ -50,7 +50,9 @@ class PluginSetTestCase(unittest.TestCase): class FindPluginsTestCase(unittest.TestCase): def test_find_nonexistent_dir(self): with self.assertRaises(bt2.Error): - bt2.find_plugins('/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41') + bt2.find_plugins( + '/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41' + ) def test_find_none_existing_dir(self): plugins = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH, recurse=False) @@ -61,7 +63,9 @@ class FindPluginsTestCase(unittest.TestCase): self.assertTrue(len(pset) >= 3) def test_find_file(self): - extension = _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS.get(os.environ['BT_OS_TYPE'], 'so') + extension = _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS.get( + os.environ['BT_OS_TYPE'], 'so' + ) plugin_name = 'babeltrace-plugin-utils.{}'.format(extension) path = os.path.join(_TEST_PLUGIN_PLUGINS_PATH, 'utils', '.libs', plugin_name) pset = bt2.find_plugins(path) @@ -70,7 +74,9 @@ class FindPluginsTestCase(unittest.TestCase): class FindPluginTestCase(unittest.TestCase): def test_find_none(self): - plugin = bt2.find_plugin('this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41') + plugin = bt2.find_plugin( + 'this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41' + ) self.assertIsNone(plugin) def test_find_existing(self): diff --git a/tests/bindings/python/bt2/test_port.py b/tests/bindings/python/bt2/test_port.py index c94bb920..35d8797e 100644 --- a/tests/bindings/python/bt2/test_port.py +++ b/tests/bindings/python/bt2/test_port.py @@ -35,8 +35,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(comp_self, params): port = comp_self._add_output_port('out') self.assertEqual(port.name, 'out') @@ -49,8 +48,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): port = comp_self._add_output_port('out') self.assertEqual(port.name, 'out') @@ -63,8 +61,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): port = comp_self._add_input_port('in') self.assertEqual(port.name, 'in') @@ -92,8 +89,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(comp_self, params): port1 = comp_self._add_output_port('clear') port2 = comp_self._add_output_port('print') @@ -109,8 +105,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): port1 = comp_self._add_output_port('clear') port2 = comp_self._add_output_port('print') @@ -126,8 +121,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): port1 = comp_self._add_input_port('clear') port2 = comp_self._add_input_port('print') @@ -161,8 +155,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_output_port('clear') comp_self._add_output_port('print') @@ -178,8 +171,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_output_port('clear') comp_self._add_output_port('print') @@ -195,8 +187,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_input_port('clear') comp_self._add_input_port('print') @@ -230,8 +221,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_output_port('clear') comp_self._add_output_port('print') @@ -245,8 +235,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_output_port('clear') comp_self._add_output_port('print') @@ -260,8 +249,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_input_port('clear') comp_self._add_input_port('print') @@ -291,8 +279,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(comp_self, params): port1 = comp_self._add_output_port('clear') port2 = comp_self._add_output_port('print') @@ -316,8 +303,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): port1 = comp_self._add_output_port('clear') port2 = comp_self._add_output_port('print') @@ -341,8 +327,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): port1 = comp_self._add_input_port('clear') port2 = comp_self._add_input_port('print') @@ -396,8 +381,7 @@ class PortTestCase(unittest.TestCase): port2 = None port3 = None - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(comp_self, params): nonlocal port1, port2, port3 port1 = comp_self._add_output_port('clear') @@ -421,8 +405,7 @@ class PortTestCase(unittest.TestCase): port2 = None port3 = None - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): nonlocal port1, port2, port3 port1 = comp_self._add_output_port('clear') @@ -446,8 +429,7 @@ class PortTestCase(unittest.TestCase): port2 = None port3 = None - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): nonlocal port1, port2, port3 port1 = comp_self._add_input_port('clear') @@ -493,8 +475,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_output_port('clear') comp_self._add_output_port('print') @@ -510,8 +491,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_output_port('clear') comp_self._add_output_port('print') @@ -527,8 +507,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_input_port('clear') comp_self._add_input_port('print') @@ -565,8 +544,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_output_port('clear') comp_self._add_output_port('print') @@ -580,8 +558,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_output_port('clear') comp_self._add_output_port('print') @@ -595,8 +572,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): comp_self._add_input_port('clear') comp_self._add_input_port('print') @@ -630,8 +606,7 @@ class PortTestCase(unittest.TestCase): port2 = None port3 = None - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(comp_self, params): nonlocal port1, port2, port3 port1 = comp_self._add_output_port('clear') @@ -663,8 +638,7 @@ class PortTestCase(unittest.TestCase): port2 = None port3 = None - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): nonlocal port1, port2, port3 port1 = comp_self._add_output_port('clear') @@ -696,8 +670,7 @@ class PortTestCase(unittest.TestCase): port2 = None port3 = None - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): nonlocal port1, port2, port3 port1 = comp_self._add_input_port('clear') @@ -843,8 +816,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MySource(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MySource(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): nonlocal user_datas @@ -863,8 +835,7 @@ class PortTestCase(unittest.TestCase): def __next__(self): raise bt2.Stop - class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): nonlocal user_datas @@ -881,16 +852,16 @@ class PortTestCase(unittest.TestCase): user_datas = [] comp = self._create_comp(MyFilter) - self.assertEqual(user_datas, - [None, 'user data string', None, {'user data': 'dict'}]) + self.assertEqual( + user_datas, [None, 'user data string', None, {'user data': 'dict'}] + ) def test_sink_self_port_user_data(self): class MyIter(bt2._UserMessageIterator): def __next__(self): raise bt2.Stop - class MySink(bt2._UserFilterComponent, - message_iterator_class=MyIter): + class MySink(bt2._UserFilterComponent, message_iterator_class=MyIter): def __init__(comp_self, params): nonlocal user_datas diff --git a/tests/bindings/python/bt2/test_query_executor.py b/tests/bindings/python/bt2/test_query_executor.py index 3c4ba62f..f313b173 100644 --- a/tests/bindings/python/bt2/test_query_executor.py +++ b/tests/bindings/python/bt2/test_query_executor.py @@ -35,28 +35,18 @@ class QueryExecutorTestCase(unittest.TestCase): def _query(cls, query_exec, obj, params, log_level): nonlocal query_params query_params = params - return { - 'null': None, - 'bt2': 'BT2', - } + return {'null': None, 'bt2': 'BT2'} query_params = None params = { 'array': ['coucou', 23, None], - 'other_map': { - 'yes': 'yeah', - '19': 19, - 'minus 1.5': -1.5, - }, + 'other_map': {'yes': 'yeah', '19': 19, 'minus 1.5': -1.5}, 'null': None, } res = bt2.QueryExecutor().query(MySink, 'obj', params) self.assertEqual(query_params, params) - self.assertEqual(res, { - 'null': None, - 'bt2': 'BT2', - }) + self.assertEqual(res, {'null': None, 'bt2': 'BT2'}) del query_params def test_query_params_none(self): @@ -91,8 +81,7 @@ class QueryExecutorTestCase(unittest.TestCase): query_log_level = log_level query_log_level = None - res = bt2.QueryExecutor().query(MySink, 'obj', None, - bt2.LoggingLevel.INFO) + res = bt2.QueryExecutor().query(MySink, 'obj', None, bt2.LoggingLevel.INFO) self.assertEqual(query_log_level, bt2.LoggingLevel.INFO) del query_log_level diff --git a/tests/bindings/python/bt2/test_stream_class.py b/tests/bindings/python/bt2/test_stream_class.py index 55cdb310..f8d6446c 100644 --- a/tests/bindings/python/bt2/test_stream_class.py +++ b/tests/bindings/python/bt2/test_stream_class.py @@ -58,8 +58,9 @@ class StreamClassTestCase(unittest.TestCase): def test_create_packet_context_field_class(self): fc = self._tc.create_structure_field_class() - sc = self._tc.create_stream_class(packet_context_field_class=fc, - supports_packets=True) + sc = self._tc.create_stream_class( + packet_context_field_class=fc, supports_packets=True + ) self.assertEqual(sc.packet_context_field_class, fc) def test_create_invalid_packet_context_field_class(self): @@ -146,118 +147,150 @@ class StreamClassTestCase(unittest.TestCase): sc.create_event_class() def test_supports_packets_without_cs(self): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_packets=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, supports_packets=True + ) self.assertTrue(sc.supports_packets) self.assertFalse(sc.packets_have_beginning_default_clock_snapshot) self.assertFalse(sc.packets_have_end_default_clock_snapshot) def test_supports_packets_with_begin_cs(self): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_packets=True, - packets_have_beginning_default_clock_snapshot=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + supports_packets=True, + packets_have_beginning_default_clock_snapshot=True, + ) self.assertTrue(sc.supports_packets) self.assertTrue(sc.packets_have_beginning_default_clock_snapshot) self.assertFalse(sc.packets_have_end_default_clock_snapshot) def test_supports_packets_with_end_cs(self): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_packets=True, - packets_have_end_default_clock_snapshot=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + supports_packets=True, + packets_have_end_default_clock_snapshot=True, + ) self.assertTrue(sc.supports_packets) self.assertFalse(sc.packets_have_beginning_default_clock_snapshot) self.assertTrue(sc.packets_have_end_default_clock_snapshot) def test_supports_packets_raises_type_error(self): with self.assertRaises(TypeError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_packets=23) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, supports_packets=23 + ) def test_packets_have_begin_default_cs_raises_type_error(self): with self.assertRaises(TypeError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - packets_have_beginning_default_clock_snapshot=23) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + packets_have_beginning_default_clock_snapshot=23, + ) def test_packets_have_end_default_cs_raises_type_error(self): with self.assertRaises(TypeError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - packets_have_end_default_clock_snapshot=23) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, packets_have_end_default_clock_snapshot=23 + ) def test_does_not_support_packets_raises_with_begin_cs(self): with self.assertRaises(ValueError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - packets_have_beginning_default_clock_snapshot=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + packets_have_beginning_default_clock_snapshot=True, + ) def test_does_not_support_packets_raises_with_end_cs(self): with self.assertRaises(ValueError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - packets_have_end_default_clock_snapshot=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + packets_have_end_default_clock_snapshot=True, + ) def test_supports_discarded_events_without_cs(self): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_discarded_events=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, supports_discarded_events=True + ) self.assertTrue(sc.supports_discarded_events) self.assertFalse(sc.discarded_events_have_default_clock_snapshots) def test_supports_discarded_events_with_cs(self): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_discarded_events=True, - discarded_events_have_default_clock_snapshots=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + supports_discarded_events=True, + discarded_events_have_default_clock_snapshots=True, + ) self.assertTrue(sc.supports_discarded_events) self.assertTrue(sc.discarded_events_have_default_clock_snapshots) def test_supports_discarded_events_raises_type_error(self): with self.assertRaises(TypeError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_discarded_events=23) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, supports_discarded_events=23 + ) def test_discarded_events_have_default_cs_raises_type_error(self): with self.assertRaises(TypeError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - discarded_events_have_default_clock_snapshots=23) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + discarded_events_have_default_clock_snapshots=23, + ) def test_does_not_support_discarded_events_raises_with_cs(self): with self.assertRaises(ValueError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - discarded_events_have_default_clock_snapshots=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + discarded_events_have_default_clock_snapshots=True, + ) def test_supports_discarded_packets_without_cs(self): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_discarded_packets=True, - supports_packets=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + supports_discarded_packets=True, + supports_packets=True, + ) self.assertTrue(sc.supports_discarded_packets) self.assertFalse(sc.discarded_packets_have_default_clock_snapshots) def test_supports_discarded_packets_with_cs(self): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_discarded_packets=True, - discarded_packets_have_default_clock_snapshots=True, - supports_packets=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + supports_discarded_packets=True, + discarded_packets_have_default_clock_snapshots=True, + supports_packets=True, + ) self.assertTrue(sc.supports_discarded_packets) self.assertTrue(sc.discarded_packets_have_default_clock_snapshots) def test_supports_discarded_packets_raises_without_packet_support(self): with self.assertRaises(ValueError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_discarded_packets=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, supports_discarded_packets=True + ) def test_supports_discarded_packets_raises_type_error(self): with self.assertRaises(TypeError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - supports_discarded_packets=23, - supports_packets=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + supports_discarded_packets=23, + supports_packets=True, + ) def test_discarded_packets_have_default_cs_raises_type_error(self): with self.assertRaises(TypeError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - discarded_packets_have_default_clock_snapshots=23, - supports_packets=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + discarded_packets_have_default_clock_snapshots=23, + supports_packets=True, + ) def test_does_not_support_discarded_packets_raises_with_cs(self): with self.assertRaises(ValueError): - sc = self._tc.create_stream_class(default_clock_class=self._cc, - discarded_packets_have_default_clock_snapshots=True, - supports_packets=True) + sc = self._tc.create_stream_class( + default_clock_class=self._cc, + discarded_packets_have_default_clock_snapshots=True, + supports_packets=True, + ) def test_trace_class(self): sc = self._tc.create_stream_class() diff --git a/tests/bindings/python/bt2/test_trace_class.py b/tests/bindings/python/bt2/test_trace_class.py index 1b4b2a7e..cf286658 100644 --- a/tests/bindings/python/bt2/test_trace_class.py +++ b/tests/bindings/python/bt2/test_trace_class.py @@ -22,7 +22,6 @@ from utils import run_in_component_init, get_default_trace_class class TraceClassTestCase(unittest.TestCase): - def test_create_default(self): def f(comp_self): return comp_self._create_trace_class() @@ -57,7 +56,9 @@ class TraceClassTestCase(unittest.TestCase): def test_no_assigns_automatic_stream_class_id(self): def f(comp_self): - return comp_self._create_trace_class(assigns_automatic_stream_class_id=False) + return comp_self._create_trace_class( + assigns_automatic_stream_class_id=False + ) tc = run_in_component_init(f) self.assertFalse(tc.assigns_automatic_stream_class_id) @@ -67,7 +68,9 @@ class TraceClassTestCase(unittest.TestCase): def test_no_assigns_automatic_stream_class_id_raises(self): def f(comp_self): - return comp_self._create_trace_class(assigns_automatic_stream_class_id=False) + return comp_self._create_trace_class( + assigns_automatic_stream_class_id=False + ) tc = run_in_component_init(f) self.assertFalse(tc.assigns_automatic_stream_class_id) @@ -79,7 +82,9 @@ class TraceClassTestCase(unittest.TestCase): @staticmethod def _create_trace_class_with_some_stream_classes(): def f(comp_self): - return comp_self._create_trace_class(assigns_automatic_stream_class_id=False) + return comp_self._create_trace_class( + assigns_automatic_stream_class_id=False + ) tc = run_in_component_init(f) sc1 = tc.create_stream_class(id=12) diff --git a/tests/bindings/python/bt2/test_trace_collection_message_iterator.py b/tests/bindings/python/bt2/test_trace_collection_message_iterator.py index e804a4f2..f3b33763 100644 --- a/tests/bindings/python/bt2/test_trace_collection_message_iterator.py +++ b/tests/bindings/python/bt2/test_trace_collection_message_iterator.py @@ -24,9 +24,9 @@ import os.path _BT_CTF_TRACES_PATH = os.environ['BT_CTF_TRACES_PATH'] -_3EVENTS_INTERSECT_TRACE_PATH = os.path.join(_BT_CTF_TRACES_PATH, - 'intersection', - '3eventsintersect') +_3EVENTS_INTERSECT_TRACE_PATH = os.path.join( + _BT_CTF_TRACES_PATH, 'intersection', '3eventsintersect' +) class ComponentSpecTestCase(unittest.TestCase): @@ -55,6 +55,7 @@ class ComponentSpecTestCase(unittest.TestCase): # Return a map, msg type -> number of messages of this type. + def _count_msgs_by_type(msgs): res = {} @@ -126,16 +127,16 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): def test_iter_custom_filter(self): src_spec = bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH) - flt_spec = bt2.ComponentSpec('utils', 'trimmer', { - 'end': '13515309.000000075', - }) + flt_spec = bt2.ComponentSpec('utils', 'trimmer', {'end': '13515309.000000075'}) msg_iter = bt2.TraceCollectionMessageIterator(src_spec, flt_spec) hist = _count_msgs_by_type(msg_iter) self.assertEqual(hist[bt2.message._EventMessage], 5) def test_iter_intersection(self): specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)] - msg_iter = bt2.TraceCollectionMessageIterator(specs, stream_intersection_mode=True) + msg_iter = bt2.TraceCollectionMessageIterator( + specs, stream_intersection_mode=True + ) msgs = list(msg_iter) self.assertEqual(len(msgs), 15) hist = _count_msgs_by_type(msgs) diff --git a/tests/bindings/python/bt2/test_value.py b/tests/bindings/python/bt2/test_value.py index 3521eb05..f1bd4949 100644 --- a/tests/bindings/python/bt2/test_value.py +++ b/tests/bindings/python/bt2/test_value.py @@ -39,10 +39,7 @@ class _TestCopySimple: copy.deepcopy(self._def) -_COMP_BINOPS = ( - operator.eq, - operator.ne, -) +_COMP_BINOPS = (operator.eq, operator.ne) # Base class for numeric value test cases. @@ -264,7 +261,7 @@ class _TestNumericValue(_TestCopySimple): test_cb(op, 0.0) def _test_binop_rhs_complex(self, test_cb, op): - test_cb(op, -23+19j) + test_cb(op, -23 + 19j) def _test_binop_rhs_zero_complex(self, test_cb, op): test_cb(op, 0j) @@ -575,79 +572,415 @@ def _inject_numeric_testing_methods(cls): # inject testing methods for each binary operation for name, binop in _BINOPS: - setattr(cls, test_binop_name('invalid_unknown'), partialmethod(_TestNumericValue._test_binop_invalid_unknown, op=binop)) - setattr(cls, test_binop_name('invalid_none'), partialmethod(_TestNumericValue._test_binop_invalid_none, op=binop)) - setattr(cls, test_binop_name('type_true'), partialmethod(_TestNumericValue._test_binop_type_true, op=binop)) - setattr(cls, test_binop_name('type_pos_int'), partialmethod(_TestNumericValue._test_binop_type_pos_int, op=binop)) - setattr(cls, test_binop_name('type_pos_vint'), partialmethod(_TestNumericValue._test_binop_type_pos_vint, op=binop)) - setattr(cls, test_binop_name('value_true'), partialmethod(_TestNumericValue._test_binop_value_true, op=binop)) - setattr(cls, test_binop_name('value_pos_int'), partialmethod(_TestNumericValue._test_binop_value_pos_int, op=binop)) - setattr(cls, test_binop_name('value_pos_vint'), partialmethod(_TestNumericValue._test_binop_value_pos_vint, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_true'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_true, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_int'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_int, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_vint'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_vint, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_true'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_true, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_int, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_vint, op=binop)) - setattr(cls, test_binop_name('type_neg_int'), partialmethod(_TestNumericValue._test_binop_type_neg_int, op=binop)) - setattr(cls, test_binop_name('type_neg_vint'), partialmethod(_TestNumericValue._test_binop_type_neg_vint, op=binop)) - setattr(cls, test_binop_name('value_neg_int'), partialmethod(_TestNumericValue._test_binop_value_neg_int, op=binop)) - setattr(cls, test_binop_name('value_neg_vint'), partialmethod(_TestNumericValue._test_binop_value_neg_vint, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_int, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vint, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_int, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vint, op=binop)) - setattr(cls, test_binop_name('type_false'), partialmethod(_TestNumericValue._test_binop_type_false, op=binop)) - setattr(cls, test_binop_name('type_zero_int'), partialmethod(_TestNumericValue._test_binop_type_zero_int, op=binop)) - setattr(cls, test_binop_name('type_zero_vint'), partialmethod(_TestNumericValue._test_binop_type_zero_vint, op=binop)) - setattr(cls, test_binop_name('value_false'), partialmethod(_TestNumericValue._test_binop_value_false, op=binop)) - setattr(cls, test_binop_name('value_zero_int'), partialmethod(_TestNumericValue._test_binop_value_zero_int, op=binop)) - setattr(cls, test_binop_name('value_zero_vint'), partialmethod(_TestNumericValue._test_binop_value_zero_vint, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_false'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_false, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_int'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_int, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_vint'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_vint, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_false'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_false, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_int, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_vint, op=binop)) - setattr(cls, test_binop_name('type_neg_float'), partialmethod(_TestNumericValue._test_binop_type_neg_float, op=binop)) - setattr(cls, test_binop_name('type_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_type_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('value_neg_float'), partialmethod(_TestNumericValue._test_binop_value_neg_float, op=binop)) - setattr(cls, test_binop_name('value_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_value_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_float, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_float, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('type_pos_float'), partialmethod(_TestNumericValue._test_binop_type_pos_float, op=binop)) - setattr(cls, test_binop_name('type_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_type_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('value_pos_float'), partialmethod(_TestNumericValue._test_binop_value_pos_float, op=binop)) - setattr(cls, test_binop_name('value_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_value_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_float, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_float, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('type_zero_float'), partialmethod(_TestNumericValue._test_binop_type_zero_float, op=binop)) - setattr(cls, test_binop_name('type_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_type_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('value_zero_float'), partialmethod(_TestNumericValue._test_binop_value_zero_float, op=binop)) - setattr(cls, test_binop_name('value_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_value_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_float, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_float, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('type_complex'), partialmethod(_TestNumericValue._test_binop_type_complex, op=binop)) - setattr(cls, test_binop_name('type_zero_complex'), partialmethod(_TestNumericValue._test_binop_type_zero_complex, op=binop)) - setattr(cls, test_binop_name('value_complex'), partialmethod(_TestNumericValue._test_binop_value_complex, op=binop)) - setattr(cls, test_binop_name('value_zero_complex'), partialmethod(_TestNumericValue._test_binop_value_zero_complex, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_complex'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_complex, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_complex'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_complex, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_complex'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_complex, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_complex'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_complex, op=binop)) + setattr( + cls, + test_binop_name('invalid_unknown'), + partialmethod(_TestNumericValue._test_binop_invalid_unknown, op=binop), + ) + setattr( + cls, + test_binop_name('invalid_none'), + partialmethod(_TestNumericValue._test_binop_invalid_none, op=binop), + ) + setattr( + cls, + test_binop_name('type_true'), + partialmethod(_TestNumericValue._test_binop_type_true, op=binop), + ) + setattr( + cls, + test_binop_name('type_pos_int'), + partialmethod(_TestNumericValue._test_binop_type_pos_int, op=binop), + ) + setattr( + cls, + test_binop_name('type_pos_vint'), + partialmethod(_TestNumericValue._test_binop_type_pos_vint, op=binop), + ) + setattr( + cls, + test_binop_name('value_true'), + partialmethod(_TestNumericValue._test_binop_value_true, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_int'), + partialmethod(_TestNumericValue._test_binop_value_pos_int, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_vint'), + partialmethod(_TestNumericValue._test_binop_value_pos_vint, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_true'), + partialmethod(_TestNumericValue._test_binop_lhs_addr_same_true, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_pos_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_pos_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_true'), + partialmethod(_TestNumericValue._test_binop_lhs_value_same_true, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_pos_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_pos_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_neg_int'), + partialmethod(_TestNumericValue._test_binop_type_neg_int, op=binop), + ) + setattr( + cls, + test_binop_name('type_neg_vint'), + partialmethod(_TestNumericValue._test_binop_type_neg_vint, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_int'), + partialmethod(_TestNumericValue._test_binop_value_neg_int, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_vint'), + partialmethod(_TestNumericValue._test_binop_value_neg_vint, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_neg_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_neg_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_neg_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_neg_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_false'), + partialmethod(_TestNumericValue._test_binop_type_false, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_int'), + partialmethod(_TestNumericValue._test_binop_type_zero_int, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_vint'), + partialmethod(_TestNumericValue._test_binop_type_zero_vint, op=binop), + ) + setattr( + cls, + test_binop_name('value_false'), + partialmethod(_TestNumericValue._test_binop_value_false, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_int'), + partialmethod(_TestNumericValue._test_binop_value_zero_int, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_vint'), + partialmethod(_TestNumericValue._test_binop_value_zero_vint, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_false'), + partialmethod(_TestNumericValue._test_binop_lhs_addr_same_false, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_zero_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_zero_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_false'), + partialmethod(_TestNumericValue._test_binop_lhs_value_same_false, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_zero_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_zero_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_neg_float'), + partialmethod(_TestNumericValue._test_binop_type_neg_float, op=binop), + ) + setattr( + cls, + test_binop_name('type_neg_vfloat'), + partialmethod(_TestNumericValue._test_binop_type_neg_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_float'), + partialmethod(_TestNumericValue._test_binop_value_neg_float, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_vfloat'), + partialmethod(_TestNumericValue._test_binop_value_neg_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_neg_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_neg_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_neg_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_neg_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_pos_float'), + partialmethod(_TestNumericValue._test_binop_type_pos_float, op=binop), + ) + setattr( + cls, + test_binop_name('type_pos_vfloat'), + partialmethod(_TestNumericValue._test_binop_type_pos_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_float'), + partialmethod(_TestNumericValue._test_binop_value_pos_float, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_vfloat'), + partialmethod(_TestNumericValue._test_binop_value_pos_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_pos_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_pos_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_pos_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_pos_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_zero_float'), + partialmethod(_TestNumericValue._test_binop_type_zero_float, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_vfloat'), + partialmethod(_TestNumericValue._test_binop_type_zero_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_float'), + partialmethod(_TestNumericValue._test_binop_value_zero_float, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_vfloat'), + partialmethod(_TestNumericValue._test_binop_value_zero_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_zero_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_zero_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_zero_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_zero_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_complex'), + partialmethod(_TestNumericValue._test_binop_type_complex, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_complex'), + partialmethod(_TestNumericValue._test_binop_type_zero_complex, op=binop), + ) + setattr( + cls, + test_binop_name('value_complex'), + partialmethod(_TestNumericValue._test_binop_value_complex, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_complex'), + partialmethod(_TestNumericValue._test_binop_value_zero_complex, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_complex'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_complex, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_complex'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_zero_complex, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_complex'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_complex, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_complex'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_zero_complex, op=binop + ), + ) # inject testing methods for each unary operation for name, unaryop in _UNARYOPS: - setattr(cls, test_unaryop_name('type'), partialmethod(_TestNumericValue._test_unaryop_type, op=unaryop)) - setattr(cls, test_unaryop_name('value'), partialmethod(_TestNumericValue._test_unaryop_value, op=unaryop)) - setattr(cls, test_unaryop_name('addr_same'), partialmethod(_TestNumericValue._test_unaryop_addr_same, op=unaryop)) - setattr(cls, test_unaryop_name('value_same'), partialmethod(_TestNumericValue._test_unaryop_value_same, op=unaryop)) + setattr( + cls, + test_unaryop_name('type'), + partialmethod(_TestNumericValue._test_unaryop_type, op=unaryop), + ) + setattr( + cls, + test_unaryop_name('value'), + partialmethod(_TestNumericValue._test_unaryop_value, op=unaryop), + ) + setattr( + cls, + test_unaryop_name('addr_same'), + partialmethod(_TestNumericValue._test_unaryop_addr_same, op=unaryop), + ) + setattr( + cls, + test_unaryop_name('value_same'), + partialmethod(_TestNumericValue._test_unaryop_value_same, op=unaryop), + ) class CreateValueFuncTestCase(unittest.TestCase): @@ -748,7 +1081,9 @@ class CreateValueFuncTestCase(unittest.TestCase): a = A() - with self.assertRaisesRegex(TypeError, "cannot create value object from 'A' object") as cm: + with self.assertRaisesRegex( + TypeError, "cannot create value object from 'A' object" + ) as cm: v = bt2.create_value(a) @@ -864,10 +1199,14 @@ class _TestIntegerValue(_TestNumericValue): return self.assertRaisesRegex(TypeError, r'expecting an integral number object') def _assert_expecting_int64(self): - return self.assertRaisesRegex(ValueError, r"expecting a signed 64-bit integral value") + return self.assertRaisesRegex( + ValueError, r"expecting a signed 64-bit integral value" + ) def _assert_expecting_uint64(self): - return self.assertRaisesRegex(ValueError, r"expecting an unsigned 64-bit integral value") + return self.assertRaisesRegex( + ValueError, r"expecting an unsigned 64-bit integral value" + ) def test_create_default(self): i = self._CLS() @@ -955,7 +1294,7 @@ class SignedIntegerValueTestCase(_TestIntegerValue, unittest.TestCase): def test_compare_big_int(self): # Larger than the IEEE 754 double-precision exact representation of # integers. - raw = (2**53) + 1 + raw = (2 ** 53) + 1 v = bt2.create_value(raw) self.assertEqual(v, raw) @@ -1378,7 +1717,7 @@ class MapValueTestCase(_TestCopySimple, unittest.TestCase): 'pos-int': 42, 'neg-float': -42.4, 'pos-float': 23.17, - 'str': 'yes' + 'str': 'yes', } self._def = bt2.MapValue(copy.deepcopy(self._def_value)) @@ -1435,11 +1774,7 @@ class MapValueTestCase(_TestCopySimple, unittest.TestCase): self.assertNotEqual(a1, a2) def test_eq_same_content_same_len(self): - raw = { - '3': 3, - 'True': True, - 'array': [1, 2.5, None, {'a': 17.6, 'b': None}] - } + raw = {'3': 3, 'True': True, 'array': [1, 2.5, None, {'a': 17.6, 'b': None}]} a1 = bt2.MapValue(raw) a2 = bt2.MapValue(copy.deepcopy(raw)) self.assertEqual(a1, a2) diff --git a/tests/bindings/python/bt2/utils.py b/tests/bindings/python/bt2/utils.py index 873a6514..fb4003a3 100644 --- a/tests/bindings/python/bt2/utils.py +++ b/tests/bindings/python/bt2/utils.py @@ -23,6 +23,7 @@ import bt2 # # The value returned by the callable is returned by run_in_component_init. + def run_in_component_init(func): class MySink(bt2._UserSinkComponent): def __init__(self, params): @@ -52,8 +53,10 @@ def run_in_component_init(func): del res_bound return res + # Create an empty trace class with default values. + def get_default_trace_class(): def f(comp_self): return comp_self._create_trace_class() diff --git a/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py b/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py index e1db25ed..0fdb78f9 100644 --- a/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py +++ b/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py @@ -44,9 +44,11 @@ class TheIteratorOfAllEvil(bt2._UserMessageIterator): else: raise StopIteration + @bt2.plugin_component_class -class TheSourceOfAllEvil(bt2._UserSourceComponent, - message_iterator_class=TheIteratorOfAllEvil): +class TheSourceOfAllEvil( + bt2._UserSourceComponent, message_iterator_class=TheIteratorOfAllEvil +): def __init__(self, params): tc = self._create_trace_class() @@ -54,10 +56,12 @@ class TheSourceOfAllEvil(bt2._UserSourceComponent, # smaller than this offset (in other words, a time that it's not # possible to represent with this clock class). cc = self._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(10000)) - sc = tc.create_stream_class(default_clock_class=cc, - supports_packets=True, - packets_have_beginning_default_clock_snapshot=True, - packets_have_end_default_clock_snapshot=True) + sc = tc.create_stream_class( + default_clock_class=cc, + supports_packets=True, + packets_have_beginning_default_clock_snapshot=True, + packets_have_end_default_clock_snapshot=True, + ) ec1 = sc.create_event_class(name='event 1') ec2 = sc.create_event_class(name='event 2') self._add_output_port('out', (tc, sc, ec1, ec2, params)) diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info.py b/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info.py index 31bd4ecd..a79ca479 100644 --- a/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info.py +++ b/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info.py @@ -29,11 +29,10 @@ class LttngUtilsDebugInfoTestCase(unittest.TestCase): trace_path = os.path.join(debug_info_data_path, 'trace') target_prefix = os.path.join(debug_info_data_path, '..', '..') src = bt2.ComponentSpec('ctf', 'fs', trace_path) - flt = bt2.ComponentSpec('lttng-utils', 'debug-info', { - 'target-prefix': target_prefix, - }) - it = bt2.TraceCollectionNotificationIterator(src, flt, - [bt2.EventNotification]) + flt = bt2.ComponentSpec( + 'lttng-utils', 'debug-info', {'target-prefix': target_prefix} + ) + it = bt2.TraceCollectionNotificationIterator(src, flt, [bt2.EventNotification]) notifs = list(it) debug_info = notifs[2].event['debug_info'] self.assertEqual(debug_info['bin'], 'libhello_so+0x14d4') diff --git a/tests/plugins/src.ctf.fs/query/test_query_trace_info.py b/tests/plugins/src.ctf.fs/query/test_query_trace_info.py index 0698975a..c1e87e39 100644 --- a/tests/plugins/src.ctf.fs/query/test_query_trace_info.py +++ b/tests/plugins/src.ctf.fs/query/test_query_trace_info.py @@ -32,19 +32,24 @@ def sort_predictably(stream): class QueryTraceInfoClockOffsetTestCase(unittest.TestCase): - def setUp(self): ctf = bt2.find_plugin('ctf') self._fs = ctf.source_component_classes['fs'] - self._paths = [os.path.join(test_ctf_traces_path, 'intersection', '3eventsintersect')] + self._paths = [ + os.path.join(test_ctf_traces_path, 'intersection', '3eventsintersect') + ] self._executor = bt2.QueryExecutor() def _check(self, trace, offset): self.assertEqual(trace['range-ns']['begin'], 13515309000000000 + offset) self.assertEqual(trace['range-ns']['end'], 13515309000000120 + offset) - self.assertEqual(trace['intersection-range-ns']['begin'], 13515309000000070 + offset) - self.assertEqual(trace['intersection-range-ns']['end'], 13515309000000100 + offset) + self.assertEqual( + trace['intersection-range-ns']['begin'], 13515309000000070 + offset + ) + self.assertEqual( + trace['intersection-range-ns']['end'], 13515309000000100 + offset + ) streams = sorted(trace['streams'], key=sort_predictably) self.assertEqual(streams[0]['range-ns']['begin'], 13515309000000000 + offset) @@ -58,70 +63,74 @@ class QueryTraceInfoClockOffsetTestCase(unittest.TestCase): # Without clock class offset def test_no_clock_class_offset(self): - res = self._executor.query(self._fs, 'trace-info', { - 'paths': self._paths, - }) + res = self._executor.query(self._fs, 'trace-info', {'paths': self._paths}) trace = res[0] self._check(trace, 0) # With clock-class-offset-s def test_clock_class_offset_s(self): - res = self._executor.query(self._fs, 'trace-info', { - 'paths': self._paths, - 'clock-class-offset-s': 2, - }) + res = self._executor.query( + self._fs, 'trace-info', {'paths': self._paths, 'clock-class-offset-s': 2} + ) trace = res[0] self._check(trace, 2000000000) # With clock-class-offset-ns def test_clock_class_offset_ns(self): - res = self._executor.query(self._fs, 'trace-info', { - 'paths': self._paths, - 'clock-class-offset-ns': 2, - }) + res = self._executor.query( + self._fs, 'trace-info', {'paths': self._paths, 'clock-class-offset-ns': 2} + ) trace = res[0] self._check(trace, 2) # With both, negative def test_clock_class_offset_both(self): - res = self._executor.query(self._fs, 'trace-info', { - 'paths': self._paths, - 'clock-class-offset-s': -2, - 'clock-class-offset-ns': -2, - }) + res = self._executor.query( + self._fs, + 'trace-info', + { + 'paths': self._paths, + 'clock-class-offset-s': -2, + 'clock-class-offset-ns': -2, + }, + ) trace = res[0] self._check(trace, -2000000002) def test_clock_class_offset_s_wrong_type(self): with self.assertRaises(bt2.InvalidParams): - self._executor.query(self._fs, 'trace-info', { - 'paths': self._paths, - 'clock-class-offset-s': "2", - }) + self._executor.query( + self._fs, + 'trace-info', + {'paths': self._paths, 'clock-class-offset-s': "2"}, + ) def test_clock_class_offset_s_wrong_type_none(self): with self.assertRaises(bt2.InvalidParams): - self._executor.query(self._fs, 'trace-info', { - 'paths': self._paths, - 'clock-class-offset-s': None, - }) + self._executor.query( + self._fs, + 'trace-info', + {'paths': self._paths, 'clock-class-offset-s': None}, + ) def test_clock_class_offset_ns_wrong_type(self): with self.assertRaises(bt2.InvalidParams): - self._executor.query(self._fs, 'trace-info', { - 'paths': self._paths, - 'clock-class-offset-ns': "2", - }) + self._executor.query( + self._fs, + 'trace-info', + {'paths': self._paths, 'clock-class-offset-ns': "2"}, + ) def test_clock_class_offset_ns_wrong_type_none(self): with self.assertRaises(bt2.InvalidParams): - self._executor.query(self._fs, 'trace-info', { - 'paths': self._paths, - 'clock-class-offset-ns': None, - }) + self._executor.query( + self._fs, + 'trace-info', + {'paths': self._paths, 'clock-class-offset-ns': None}, + ) class QueryTraceInfoPortNameTestCase(unittest.TestCase): diff --git a/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py b/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py index d5274ae4..77bf3613 100644 --- a/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py +++ b/tests/python-plugin-provider/bt_plugin_test_python_plugin_provider.py @@ -24,14 +24,12 @@ class MyIter(bt2._UserMessageIterator): @bt2.plugin_component_class -class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): +class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): pass @bt2.plugin_component_class -class MyFilter(bt2._UserFilterComponent, - message_iterator_class=MyIter): +class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): pass @@ -44,7 +42,11 @@ class MySink(bt2._UserSinkComponent): pass -bt2.register_plugin(__name__, 'sparkling', author='Philippe Proulx', - description='A delicious plugin.', - version=(1, 2, 3, 'EXTRA'), - license='MIT') +bt2.register_plugin( + __name__, + 'sparkling', + author='Philippe Proulx', + description='A delicious plugin.', + version=(1, 2, 3, 'EXTRA'), + license='MIT', +) diff --git a/tests/utils/python/testrunner.py b/tests/utils/python/testrunner.py index d3879b6a..6606246a 100644 --- a/tests/utils/python/testrunner.py +++ b/tests/utils/python/testrunner.py @@ -28,27 +28,31 @@ import argparse if __name__ == '__main__': argparser = argparse.ArgumentParser() - argparser.add_argument('-f', '--failfast', - help='Stop on first fail or error', - action='store_true') + argparser.add_argument( + '-f', '--failfast', help='Stop on first fail or error', action='store_true' + ) - argparser.add_argument('start_dir', - help='Base directory where to search for tests', - type=str) + argparser.add_argument( + 'start_dir', help='Base directory where to search for tests', type=str + ) mut_exclu_group = argparser.add_mutually_exclusive_group(required=True) - mut_exclu_group.add_argument('-p', '--pattern', - help='Glob-style pattern of test files to run ' - '(e.g. test_event*.py)', - type=str) - - mut_exclu_group.add_argument('-t', '--test-case', - help='Run a specfic test module name, test class ' - 'name, or test method name ' - '(e.g. test_event.EventTestCase.test_clock_value)', - type=str) + mut_exclu_group.add_argument( + '-p', + '--pattern', + help='Glob-style pattern of test files to run ' '(e.g. test_event*.py)', + type=str, + ) + mut_exclu_group.add_argument( + '-t', + '--test-case', + help='Run a specfic test module name, test class ' + 'name, or test method name ' + '(e.g. test_event.EventTestCase.test_clock_value)', + type=str, + ) args = argparser.parse_args() @@ -70,7 +74,6 @@ if __name__ == '__main__': # else it will fail to parse. sys.exit(1) - if tests.countTestCases() < 1: print("No tests matching '%s' found in '%s'" % (pattern, start_dir)) sys.exit(1) -- 2.34.1