python: fix all 'is assigned to but never used' warnings
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 27 Aug 2019 04:50:06 +0000 (00:50 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 27 Aug 2019 20:23:29 +0000 (16:23 -0400)
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 <simon.marchi@efficios.com>
Reported-by: flake8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1978
Tested-by: jenkins <jenkins@lttng.org>
13 files changed:
tests/bindings/python/bt2/test_component.py
tests/bindings/python/bt2/test_connection.py
tests/bindings/python/bt2/test_error.py
tests/bindings/python/bt2/test_field_class.py
tests/bindings/python/bt2/test_graph.py
tests/bindings/python/bt2/test_integer_range_set.py
tests/bindings/python/bt2/test_plugin.py
tests/bindings/python/bt2/test_port.py
tests/bindings/python/bt2/test_query_executor.py
tests/bindings/python/bt2/test_stream_class.py
tests/bindings/python/bt2/test_trace_class.py
tests/bindings/python/bt2/test_value.py
tests/data/plugins/flt.utils.muxer/bt_plugin_muxer_test.py

index 65338c199b5946b5e7da0ce586dea54d281527d4..5a4d026d3030eb40e2aeee3f1aaa8c3ea6947424 100644 (file)
@@ -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):
index 131e1d75f9618e0322be40ca448efc07082bedb9..127fd2e8fd36c7e08239e88f107ea006ce9f9081 100644 (file)
@@ -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):
index 11328db7b1814e427dd56b3123028e4baa866866..2a2703b6f591aa4fc46a2795999d67b4581ef9e6 100644 (file)
@@ -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):
index 45255e6710c845d63726ade8c247d92f41fbda40..b1dbd38af9b7ed33cc5b442d7f05dcb96f3a5132 100644 (file)
@@ -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()
index b719d9ca133e7b6956e7bbdb72a0bfc257f4ae01..1d3f9da27be726606de2f635ebc2056faa0ba8a2 100644 (file)
@@ -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()
index 0e6940e5238be95aac72f828a443aca4b8fb1338..877ca6edb939ae7e998444bee92b7e7cf514792c 100644 (file)
@@ -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))
index 9e04b401b690bdae1480212f10ae23a84dcdcb4d..9b744cf64bf71e6e35e523f5b6a0edbe69a8d81c 100644 (file)
@@ -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):
index 7e489d32c9ca350a754360f6446ac66b3a27a1f6..7db49fb27011d36391a3a4ac24237cd5996f07f0 100644 (file)
@@ -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()])
index 62f84d4a50712fbcdff3e82ecb2a61f6e6f350cc..1ed63f1a4749c9bbf682404cb867ae7722addf8a 100644 (file)
@@ -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):
index 60b86883439319d6fb30ce78607ddb839d05410e..f94be02992e6a7ad1c9a563468d6f532e4f46488 100644 (file)
@@ -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,
index d8f60143fb01c18e3f65ebc98d833c8f4e59b2cb..168ae86367992d7a61a7ea5837ce7ad0cc0eeb0c 100644 (file)
@@ -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):
index c73e397d9cd1433d20d050a607f48753c34d0cfc..fea749fc5b9234975d7f1abb7bb738ff85ccc747 100644 (file)
@@ -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))
index f8135fc6fdaf6c32fa320d8c59e91cfda9da8c2e..29aa065ace7b0d0d86e270eff0c97967457caa19 100644 (file)
@@ -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)
This page took 0.036521 seconds and 4 git commands to generate.