From 082db6480d4f3686922269ec24c2ecc7b2c28bce Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 27 Aug 2019 00:50:06 -0400 Subject: [PATCH] python: fix all 'is assigned to but never used' warnings Fix all instances of this warning (code F841) found in the repo by flake8. In one instance (in test_plugin.py), I added an assertion to use the variable. In all others, I considered the variable not useful and removed it. Change-Id: I95c282a610d0e3b8adf7cee40ce5229744e8ebc0 Signed-off-by: Simon Marchi Reported-by: flake8 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1978 Tested-by: jenkins --- tests/bindings/python/bt2/test_component.py | 6 ++-- tests/bindings/python/bt2/test_connection.py | 2 +- tests/bindings/python/bt2/test_error.py | 2 +- tests/bindings/python/bt2/test_field_class.py | 2 -- tests/bindings/python/bt2/test_graph.py | 34 ++++++------------- .../python/bt2/test_integer_range_set.py | 10 +++--- tests/bindings/python/bt2/test_plugin.py | 1 + tests/bindings/python/bt2/test_port.py | 6 ++-- .../python/bt2/test_query_executor.py | 14 ++++---- .../bindings/python/bt2/test_stream_class.py | 24 ++++++------- tests/bindings/python/bt2/test_trace_class.py | 2 +- tests/bindings/python/bt2/test_value.py | 32 ++++++++--------- .../flt.utils.muxer/bt_plugin_muxer_test.py | 2 -- 13 files changed, 60 insertions(+), 77 deletions(-) diff --git a/tests/bindings/python/bt2/test_component.py b/tests/bindings/python/bt2/test_component.py index 65338c19..5a4d026d 100644 --- a/tests/bindings/python/bt2/test_component.py +++ b/tests/bindings/python/bt2/test_component.py @@ -38,7 +38,7 @@ class UserComponentTestCase(unittest.TestCase): def _user_consume(self): pass - comp = self._create_comp(MySink, 'yaes') + self._create_comp(MySink, 'yaes') def test_logging_level(self): class MySink(bt2._UserSinkComponent): @@ -48,7 +48,7 @@ class UserComponentTestCase(unittest.TestCase): def _user_consume(self): pass - comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO) + self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO) def test_graph_mip_version(self): class MySink(bt2._UserSinkComponent): @@ -58,7 +58,7 @@ class UserComponentTestCase(unittest.TestCase): def _user_consume(self): pass - comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO) + self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO) def test_class(self): class MySink(bt2._UserSinkComponent): diff --git a/tests/bindings/python/bt2/test_connection.py b/tests/bindings/python/bt2/test_connection.py index 131e1d75..127fd2e8 100644 --- a/tests/bindings/python/bt2/test_connection.py +++ b/tests/bindings/python/bt2/test_connection.py @@ -40,7 +40,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']) + graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) def test_downstream_port(self): class MyIter(bt2._UserMessageIterator): diff --git a/tests/bindings/python/bt2/test_error.py b/tests/bindings/python/bt2/test_error.py index 11328db7..2a2703b6 100644 --- a/tests/bindings/python/bt2/test_error.py +++ b/tests/bindings/python/bt2/test_error.py @@ -88,7 +88,7 @@ class ErrorTestCase(unittest.TestCase): def test_current_thread_error_none(self): # When a bt2._Error is raised, it steals the current thread's error. # Verify that it is now NULL. - exc = self._run_failing_graph(SourceWithFailingInit, WorkingSink) + self._run_failing_graph(SourceWithFailingInit, WorkingSink) self.assertIsNone(native_bt.current_thread_take_error()) def test_len(self): diff --git a/tests/bindings/python/bt2/test_field_class.py b/tests/bindings/python/bt2/test_field_class.py index 45255e67..b1dbd38a 100644 --- a/tests/bindings/python/bt2/test_field_class.py +++ b/tests/bindings/python/bt2/test_field_class.py @@ -361,7 +361,6 @@ class _TestElementContainer: self._append_element_method(self._fc, 'yes', sub_fc2) def test_iadd(self): - other_fc = self._create_default_field_class() a_field_class = self._tc.create_real_field_class() b_field_class = self._tc.create_signed_integer_field_class(17) self._append_element_method(self._fc, 'a_float', a_field_class) @@ -685,7 +684,6 @@ class _VariantFieldClassWithSelectorTestCase: ) def test_iadd(self): - other_fc = self._create_default_field_class() 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() diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index b719d9ca..1d3f9da2 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -95,7 +95,7 @@ class GraphTestCase(unittest.TestCase): pass params = {'hello': 23, 'path': '/path/to/stuff'} - comp = self._graph.add_component(MySink, 'salut', params) + self._graph.add_component(MySink, 'salut', params) self.assertEqual(params, comp_params) del comp_params @@ -111,7 +111,7 @@ class GraphTestCase(unittest.TestCase): pass obj = object() - comp = self._graph.add_component(MySink, 'salut', obj=obj) + self._graph.add_component(MySink, 'salut', obj=obj) self.assertIs(comp_obj, obj) del comp_obj @@ -126,20 +126,18 @@ class GraphTestCase(unittest.TestCase): def _user_consume(self): pass - comp = self._graph.add_component(MySink, 'salut') + self._graph.add_component(MySink, 'salut') self.assertIsNone(comp_obj) del comp_obj def test_add_component_obj_non_python_comp_cls(self): - comp_obj = None - plugin = bt2.find_plugin('text', find_in_user_dir=False, find_in_sys_dir=False) assert plugin is not None cc = plugin.source_component_classes['dmesg'] assert cc is not None with self.assertRaises(ValueError): - comp = self._graph.add_component(cc, 'salut', obj=57) + self._graph.add_component(cc, 'salut', obj=57) def test_add_component_invalid_cls_type(self): with self.assertRaises(TypeError): @@ -218,9 +216,7 @@ 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'] - ) + self._graph.connect_ports(sink.input_ports['in'], src.output_ports['out']) def test_add_interrupter(self): class MyIter(bt2._UserMessageIterator): @@ -352,9 +348,7 @@ 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'] - ) + self._graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) self._graph.run() def test_run_once(self): @@ -377,9 +371,7 @@ class GraphTestCase(unittest.TestCase): run_count = 0 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'] - ) + self._graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) with self.assertRaises(bt2.TryAgain): self._graph.run_once() @@ -403,9 +395,7 @@ 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'] - ) + self._graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) with self.assertRaises(bt2.Stop): self._graph.run_once() @@ -456,9 +446,7 @@ 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'] - ) + self._graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) with self.assertRaises(bt2.TryAgain): self._graph.run() @@ -515,9 +503,7 @@ 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'] - ) + self._graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) with self.assertRaises(bt2._Error): self._graph.run() diff --git a/tests/bindings/python/bt2/test_integer_range_set.py b/tests/bindings/python/bt2/test_integer_range_set.py index 0e6940e5..877ca6ed 100644 --- a/tests/bindings/python/bt2/test_integer_range_set.py +++ b/tests/bindings/python/bt2/test_integer_range_set.py @@ -40,23 +40,23 @@ class _IntegerRangeTestCase: def test_create_wrong_type_lower(self): with self.assertRaises(TypeError): - rg = self._CLS(19.3, self._def_upper) + self._CLS(19.3, self._def_upper) def test_create_wrong_type_lower(self): with self.assertRaises(TypeError): - rg = self._CLS(self._def_lower, 19.3) + self._CLS(self._def_lower, 19.3) def test_create_out_of_bound_lower(self): with self.assertRaises(ValueError): - rg = self._CLS(self._oob_lower, self._def_upper) + self._CLS(self._oob_lower, self._def_upper) def test_create_out_of_bound_upper(self): with self.assertRaises(ValueError): - rg = self._CLS(self._def_lower, self._oob_upper) + self._CLS(self._def_lower, self._oob_upper) def test_create_lower_gt_upper(self): with self.assertRaises(ValueError): - rg = self._CLS(self._def_lower, self._def_lower - 1) + self._CLS(self._def_lower, self._def_lower - 1) def test_contains_lower(self): self.assertTrue(self._rg.contains(self._def_lower)) diff --git a/tests/bindings/python/bt2/test_plugin.py b/tests/bindings/python/bt2/test_plugin.py index 9e04b401..9b744cf6 100644 --- a/tests/bindings/python/bt2/test_plugin.py +++ b/tests/bindings/python/bt2/test_plugin.py @@ -80,6 +80,7 @@ class FindPluginTestCase(unittest.TestCase): def test_find_existing(self): plugin = bt2.find_plugin('ctf', find_in_user_dir=False, find_in_sys_dir=False) + self.assertIsNotNone(plugin) class PluginTestCase(unittest.TestCase): diff --git a/tests/bindings/python/bt2/test_port.py b/tests/bindings/python/bt2/test_port.py index 7e489d32..7db49fb2 100644 --- a/tests/bindings/python/bt2/test_port.py +++ b/tests/bindings/python/bt2/test_port.py @@ -782,7 +782,7 @@ class PortTestCase(unittest.TestCase): user_datas = [] - comp = self._create_comp(MySource) + self._create_comp(MySource) self.assertEqual(user_datas, [None, 2]) def test_filter_self_port_user_data(self): @@ -806,7 +806,7 @@ class PortTestCase(unittest.TestCase): user_datas = [] - comp = self._create_comp(MyFilter) + self._create_comp(MyFilter) self.assertEqual( user_datas, [None, 'user data string', None, {'user data': 'dict'}] ) @@ -827,5 +827,5 @@ class PortTestCase(unittest.TestCase): user_datas = [] - comp = self._create_comp(MySink) + self._create_comp(MySink) self.assertEqual(user_datas, [None, set()]) diff --git a/tests/bindings/python/bt2/test_query_executor.py b/tests/bindings/python/bt2/test_query_executor.py index 62f84d4a..1ed63f1a 100644 --- a/tests/bindings/python/bt2/test_query_executor.py +++ b/tests/bindings/python/bt2/test_query_executor.py @@ -56,7 +56,7 @@ class QueryExecutorTestCase(unittest.TestCase): query_params = params query_params = 23 - res = bt2.QueryExecutor(MySink, 'obj', None).query() + bt2.QueryExecutor(MySink, 'obj', None).query() self.assertIs(query_params, None) del query_params @@ -71,7 +71,7 @@ class QueryExecutorTestCase(unittest.TestCase): query_params = params query_params = 23 - res = bt2.QueryExecutor(MySink, 'obj').query() + bt2.QueryExecutor(MySink, 'obj').query() self.assertIs(query_params, None) del query_params @@ -87,7 +87,7 @@ class QueryExecutorTestCase(unittest.TestCase): query_method_obj = None method_obj = object() - res = bt2.QueryExecutor(MySink, 'obj', method_obj=method_obj).query() + bt2.QueryExecutor(MySink, 'obj', method_obj=method_obj).query() self.assertIs(query_method_obj, method_obj) del query_method_obj @@ -125,7 +125,7 @@ class QueryExecutorTestCase(unittest.TestCase): query_method_obj = method_obj query_method_obj = object() - res = bt2.QueryExecutor(MySink, 'obj').query() + bt2.QueryExecutor(MySink, 'obj').query() self.assertIsNone(query_method_obj) del query_method_obj @@ -168,7 +168,7 @@ class QueryExecutorTestCase(unittest.TestCase): raise ValueError with self.assertRaises(bt2._Error) as ctx: - res = bt2.QueryExecutor(MySink, 'obj', [17, 23]).query() + bt2.QueryExecutor(MySink, 'obj', [17, 23]).query() exc = ctx.exception self.assertEqual(len(exc), 3) @@ -188,7 +188,7 @@ class QueryExecutorTestCase(unittest.TestCase): raise bt2.UnknownObject with self.assertRaises(bt2.UnknownObject): - res = bt2.QueryExecutor(MySink, 'obj', [17, 23]).query() + bt2.QueryExecutor(MySink, 'obj', [17, 23]).query() def test_query_logging_level_invalid_type(self): class MySink(bt2._UserSinkComponent): @@ -228,7 +228,7 @@ class QueryExecutorTestCase(unittest.TestCase): raise bt2.TryAgain with self.assertRaises(bt2.TryAgain): - res = bt2.QueryExecutor(MySink, 'obj', [17, 23]).query() + bt2.QueryExecutor(MySink, 'obj', [17, 23]).query() def test_query_add_interrupter(self): class MySink(bt2._UserSinkComponent): diff --git a/tests/bindings/python/bt2/test_stream_class.py b/tests/bindings/python/bt2/test_stream_class.py index 60b86883..f94be029 100644 --- a/tests/bindings/python/bt2/test_stream_class.py +++ b/tests/bindings/python/bt2/test_stream_class.py @@ -188,33 +188,33 @@ class StreamClassTestCase(unittest.TestCase): def test_supports_packets_raises_type_error(self): with self.assertRaises(TypeError): - sc = self._tc.create_stream_class( + 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( + 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( + 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( + 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( + self._tc.create_stream_class( default_clock_class=self._cc, packets_have_end_default_clock_snapshot=True, ) @@ -237,20 +237,20 @@ class StreamClassTestCase(unittest.TestCase): def test_supports_discarded_events_raises_type_error(self): with self.assertRaises(TypeError): - sc = self._tc.create_stream_class( + 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( + 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( + self._tc.create_stream_class( default_clock_class=self._cc, discarded_events_have_default_clock_snapshots=True, ) @@ -276,13 +276,13 @@ class StreamClassTestCase(unittest.TestCase): def test_supports_discarded_packets_raises_without_packet_support(self): with self.assertRaises(ValueError): - sc = self._tc.create_stream_class( + 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( + self._tc.create_stream_class( default_clock_class=self._cc, supports_discarded_packets=23, supports_packets=True, @@ -290,7 +290,7 @@ class StreamClassTestCase(unittest.TestCase): def test_discarded_packets_have_default_cs_raises_type_error(self): with self.assertRaises(TypeError): - sc = self._tc.create_stream_class( + self._tc.create_stream_class( default_clock_class=self._cc, discarded_packets_have_default_clock_snapshots=23, supports_packets=True, @@ -298,7 +298,7 @@ class StreamClassTestCase(unittest.TestCase): def test_does_not_support_discarded_packets_raises_with_cs(self): with self.assertRaises(ValueError): - sc = self._tc.create_stream_class( + self._tc.create_stream_class( default_clock_class=self._cc, discarded_packets_have_default_clock_snapshots=True, supports_packets=True, diff --git a/tests/bindings/python/bt2/test_trace_class.py b/tests/bindings/python/bt2/test_trace_class.py index d8f60143..168ae863 100644 --- a/tests/bindings/python/bt2/test_trace_class.py +++ b/tests/bindings/python/bt2/test_trace_class.py @@ -82,7 +82,7 @@ class TraceClassTestCase(unittest.TestCase): self.assertTrue(tc.assigns_automatic_stream_class_id) with self.assertRaises(ValueError): - sc1 = tc.create_stream_class(23) + tc.create_stream_class(23) def test_no_assigns_automatic_stream_class_id(self): def f(comp_self): diff --git a/tests/bindings/python/bt2/test_value.py b/tests/bindings/python/bt2/test_value.py index c73e397d..fea749fc 100644 --- a/tests/bindings/python/bt2/test_value.py +++ b/tests/bindings/python/bt2/test_value.py @@ -1082,8 +1082,8 @@ class CreateValueFuncTestCase(unittest.TestCase): with self.assertRaisesRegex( TypeError, "cannot create value object from 'A' object" - ) as cm: - v = bt2.create_value(a) + ): + bt2.create_value(a) class BoolValueTestCase(_TestNumericValue, unittest.TestCase): @@ -1122,11 +1122,11 @@ class BoolValueTestCase(_TestNumericValue, unittest.TestCase): def test_create_from_int_non_zero(self): with self.assertRaises(TypeError): - b = bt2.BoolValue(23) + bt2.BoolValue(23) def test_create_from_int_zero(self): with self.assertRaises(TypeError): - b = bt2.BoolValue(0) + bt2.BoolValue(0) def test_assign_true(self): b = bt2.BoolValue() @@ -1234,11 +1234,11 @@ class _TestIntegerValue(_TestNumericValue): pass with self._assert_expecting_int(): - i = self._CLS(A()) + self._CLS(A()) def test_create_from_varray(self): with self._assert_expecting_int(): - i = self._CLS(bt2.ArrayValue()) + self._CLS(bt2.ArrayValue()) def test_assign_true(self): raw = True @@ -1279,11 +1279,11 @@ class SignedIntegerValueTestCase(_TestIntegerValue, unittest.TestCase): def test_create_pos_too_big(self): with self._assert_expecting_int64(): - i = self._CLS(2 ** 63) + self._CLS(2 ** 63) def test_create_neg_too_big(self): with self._assert_expecting_int64(): - i = self._CLS(-(2 ** 63) - 1) + self._CLS(-(2 ** 63) - 1) def test_assign_neg_int(self): raw = -13 @@ -1306,11 +1306,11 @@ class UnsignedIntegerValueTestCase(_TestIntegerValue, unittest.TestCase): def test_create_pos_too_big(self): with self._assert_expecting_uint64(): - i = self._CLS(2 ** 64) + self._CLS(2 ** 64) def test_create_neg(self): with self._assert_expecting_uint64(): - i = self._CLS(-1) + self._CLS(-1) _inject_numeric_testing_methods(UnsignedIntegerValueTestCase) @@ -1381,11 +1381,11 @@ class RealValueTestCase(_TestNumericValue, unittest.TestCase): pass with self._assert_expecting_float(): - f = bt2.RealValue(A()) + bt2.RealValue(A()) def test_create_from_varray(self): with self._assert_expecting_float(): - f = bt2.RealValue(bt2.ArrayValue()) + bt2.RealValue(bt2.ArrayValue()) def test_assign_true(self): self._def.value = True @@ -1473,11 +1473,11 @@ class StringValueTestCase(_TestCopySimple, unittest.TestCase): pass with self._assert_expecting_str(): - i = bt2.StringValue(A()) + bt2.StringValue(A()) def test_create_from_varray(self): with self._assert_expecting_str(): - i = bt2.StringValue(bt2.ArrayValue()) + bt2.StringValue(bt2.ArrayValue()) def test_assign_int(self): with self._assert_expecting_str(): @@ -1605,7 +1605,7 @@ class ArrayValueTestCase(_TestCopySimple, unittest.TestCase): pass with self._assert_type_error(): - a = bt2.ArrayValue(A()) + bt2.ArrayValue(A()) def test_bool_op_true(self): self.assertTrue(bool(self._def)) @@ -1752,7 +1752,7 @@ class MapValueTestCase(_TestCopySimple, unittest.TestCase): pass with self.assertRaises(AttributeError): - m = bt2.MapValue(A()) + bt2.MapValue(A()) def test_bool_op_true(self): self.assertTrue(bool(self._def)) diff --git a/tests/data/plugins/flt.utils.muxer/bt_plugin_muxer_test.py b/tests/data/plugins/flt.utils.muxer/bt_plugin_muxer_test.py index f8135fc6..29aa065a 100644 --- a/tests/data/plugins/flt.utils.muxer/bt_plugin_muxer_test.py +++ b/tests/data/plugins/flt.utils.muxer/bt_plugin_muxer_test.py @@ -20,8 +20,6 @@ class TheSourceOfConfusion( bt2._UserSourceComponent, message_iterator_class=TheIteratorOfConfusion ): def __init__(self, params, obj): - tc = self._create_trace_class() - test_name = str(params['test-name']) TEST_CASES[test_name].source_setup(self, test_name) -- 2.34.1