From 338537eb2bd09cc30b7c0802ead438208a81332d Mon Sep 17 00:00:00 2001 From: Johanna England Date: Wed, 25 Sep 2024 14:47:37 +0200 Subject: [PATCH 1/2] Remove unused variables in tests --- tests/unittests/django/templatetags/info_test.py | 1 - tests/unittests/ipdevpoll/prefix_test.py | 2 +- tests/unittests/models/fields_test.py | 2 +- tests/unittests/netmap/metadata_nx_test.py | 4 ++-- .../unittests/netmap/topology_layer2_testcase.py | 3 --- .../unittests/netmap/topology_layer3_testcase.py | 16 ++++++++-------- tests/unittests/web/ldapauth_test.py | 4 ++-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/tests/unittests/django/templatetags/info_test.py b/tests/unittests/django/templatetags/info_test.py index 4296cef02d..41437a8192 100644 --- a/tests/unittests/django/templatetags/info_test.py +++ b/tests/unittests/django/templatetags/info_test.py @@ -30,7 +30,6 @@ def timestamp_calc(*args, **kwargs): return datetime.now() - timedelta(*args, **kwargs) minute = 60 - hour = minute * 60 self.assertEqual(time_since(None), "Never") self.assertEqual( diff --git a/tests/unittests/ipdevpoll/prefix_test.py b/tests/unittests/ipdevpoll/prefix_test.py index dd7382d98c..43873532c6 100644 --- a/tests/unittests/ipdevpoll/prefix_test.py +++ b/tests/unittests/ipdevpoll/prefix_test.py @@ -78,7 +78,7 @@ class PrefixPluginTest(TestCase): def test_instantiation(self): netbox = Mock('Netbox') netbox.sysname = 'foo-sw.example.org' - plugin = prefix.Prefix(netbox, None, None) + prefix.Prefix(netbox, None, None) class VlanPatternTest(TestCase): diff --git a/tests/unittests/models/fields_test.py b/tests/unittests/models/fields_test.py index 8abc02d593..abb7efb5c2 100644 --- a/tests/unittests/models/fields_test.py +++ b/tests/unittests/models/fields_test.py @@ -60,7 +60,7 @@ def test_to_python_seemingly_valid(self): field = CIDRField() ip6 = u'1234:dead:beef::63/23' with pytest.raises(exceptions.ValidationError): - result6 = field.to_python(ip6) + field.to_python(ip6) class TestDateTimeInfinityField(object): diff --git a/tests/unittests/netmap/metadata_nx_test.py b/tests/unittests/netmap/metadata_nx_test.py index 0319d688f8..6af10cd2f7 100644 --- a/tests/unittests/netmap/metadata_nx_test.py +++ b/tests/unittests/netmap/metadata_nx_test.py @@ -8,7 +8,7 @@ class MetaClassesTests(MetaClassTestCase): def test_group_does_not_raise_exception_when_interface_is_none(self): - foo = Group(Mock(name='netbox', spec=Netbox), None) + Group(Mock(name='netbox', spec=Netbox), None) def test_edge_allows_both_interface_linkspeed_in_group_to_be_none(self): netbox_a = Mock(name='netbox a', sepc=Netbox) @@ -21,7 +21,7 @@ def test_edge_allows_both_interface_linkspeed_in_group_to_be_none(self): b = Mock(name='interface b', spec=Interface) b.speed = None - foo = Edge((netbox_a, netbox_b), (a, b)) + Edge((netbox_a, netbox_b), (a, b)) class Layer2NetworkXMetadataTests(TopologyLayer2TestCase): diff --git a/tests/unittests/netmap/topology_layer2_testcase.py b/tests/unittests/netmap/topology_layer2_testcase.py index 40d8256050..ef2a2848f3 100644 --- a/tests/unittests/netmap/topology_layer2_testcase.py +++ b/tests/unittests/netmap/topology_layer2_testcase.py @@ -64,9 +64,6 @@ def setUp(self): ) self.build_l2.start() - bar = vlan.build_layer2_graph() - # foo = topology._get_vlans_map_layer2(bar) - vlan_by_interfaces, vlan_by_netbox = topology._get_vlans_map_layer2( self.nav_graph ) diff --git a/tests/unittests/netmap/topology_layer3_testcase.py b/tests/unittests/netmap/topology_layer3_testcase.py index 2550d54881..d016b460f9 100644 --- a/tests/unittests/netmap/topology_layer3_testcase.py +++ b/tests/unittests/netmap/topology_layer3_testcase.py @@ -36,19 +36,19 @@ def setUp(self): self.e = e = self._netbox_factory('e') self.f = f = self._netbox_factory('f') - self.a1 = a1 = self._interface_factory('a1', a) - self.a3 = a3 = self._interface_factory('a3', a) + self.a1 = self._interface_factory('a1', a) + self.a3 = self._interface_factory('a3', a) - self.b1 = b1 = self._interface_factory('b1', b) - self.b4 = b4 = self._interface_factory('b4', b) + self.b1 = self._interface_factory('b1', b) + self.b4 = self._interface_factory('b4', b) - self.c3 = c3 = self._interface_factory('c3', c) + self.c3 = self._interface_factory('c3', c) - self.d4 = d4 = self._interface_factory('d4', d) + self.d4 = self._interface_factory('d4', d) - self.e4 = e4 = self._interface_factory('e4', e) + self.e4 = self._interface_factory('e4', e) - self.f5 = f5 = self._interface_factory('f5', f) + self.f5 = self._interface_factory('f5', f) self.prefix_foo = Prefix( id=1111, diff --git a/tests/unittests/web/ldapauth_test.py b/tests/unittests/web/ldapauth_test.py index 070140e999..e19c973cd5 100644 --- a/tests/unittests/web/ldapauth_test.py +++ b/tests/unittests/web/ldapauth_test.py @@ -56,7 +56,7 @@ class LdapOpenTestConfig(NAVConfigParser): @patch('nav.web.auth.ldap._config', LdapOpenTestConfig()) def test_open_ldap_should_run_without_error(): - with patch('ldap.initialize') as initialize: + with patch('ldap.initialize'): assert open_ldap() @@ -74,5 +74,5 @@ class LdapOpenTestInvalidEncryptionConfig(NAVConfigParser): @patch('nav.web.auth.ldap._config', LdapOpenTestInvalidEncryptionConfig()) def test_when_encryption_setting_is_invalid_open_ldap_should_run_without_encryption(): - with patch('ldap.initialize') as initialize: + with patch('ldap.initialize'): assert open_ldap() From fddb5476be22796bd3af90a6acd29d1420989ac0 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Wed, 25 Sep 2024 14:48:37 +0200 Subject: [PATCH 2/2] Show that generator needs to be consumed --- tests/unittests/general/bulkparse_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/unittests/general/bulkparse_test.py b/tests/unittests/general/bulkparse_test.py index 2fcba55a93..1af775a793 100644 --- a/tests/unittests/general/bulkparse_test.py +++ b/tests/unittests/general/bulkparse_test.py @@ -1,7 +1,6 @@ """Tests for bulkparse""" # pylint: disable=C0111, C0103, W0614 - import pytest from nav import bulkparse @@ -84,7 +83,7 @@ def test_three_lines_with_two_rows_should_be_counted_as_three(self): b"room1:10.0.0.187:myorg:OTHER:SNMP v2c read profile::\n" ) b = bulkparse.NetboxBulkParser(data) - out_data = list(b) + list(b) # Generator needs to be consumed for this test to succeed assert b.line_num == 3 def test_short_line_should_raise_error(self):