From 49b29591aa979560068449b78fd547915420ff08 Mon Sep 17 00:00:00 2001 From: Martin Basti Date: Oct 11 2016 14:50:32 +0000 Subject: Pylint: remove unused variables in tests Reviewed-By: Pavel Vomacka --- diff --git a/ipatests/pytest_plugins/integration.py b/ipatests/pytest_plugins/integration.py index ab10548..f946a07 100644 --- a/ipatests/pytest_plugins/integration.py +++ b/ipatests/pytest_plugins/integration.py @@ -34,8 +34,6 @@ from ipatests.test_integration import tasks from ipatests.test_integration.config import Config from ipatests.test_integration.env_config import get_global_config -# pylint: disable=unused-variable - log = log_mgr.get_logger(__name__) @@ -117,7 +115,7 @@ def collect_logs(name, logs_dict, logfile_dir=None, beakerlib_plugin=None): # $HOSTNAME-$FILENAME (with '/' replaced by '-') beakerlib_plugin.run_beakerlib_command(['pushd', topdirname]) try: - for dirpath, dirnames, filenames in os.walk(topdirname): + for dirpath, _dirnames, filenames in os.walk(topdirname): for filename in filenames: fullname = os.path.relpath( os.path.join(dirpath, filename), topdirname) @@ -171,7 +169,7 @@ def mh(request, class_integration_logs): {role: 1 for role in cls.required_extra_roles}) domain_descriptions = [domain_description] - for i in range(cls.num_ad_domains): + for _i in range(cls.num_ad_domains): domain_descriptions.append({ 'type': 'AD', 'hosts': {'ad': 1, 'ad_subdomain': 1}, diff --git a/ipatests/test_install/test_updates.py b/ipatests/test_install/test_updates.py index e6761ad..4053d35 100644 --- a/ipatests/test_install/test_updates.py +++ b/ipatests/test_install/test_updates.py @@ -34,8 +34,6 @@ from ipapython import ipautil, ipaldap from ipaplatform.paths import paths from ipapython.dn import DN -# pylint: disable=unused-variable - """ The updater works through files only so this is just a thin-wrapper controlling which file we test at any given point. @@ -93,11 +91,11 @@ class test_update(unittest.TestCase): self.assertTrue(modified) with self.assertRaises(errors.NotFound): - entries = self.ld.get_entries( + self.ld.get_entries( self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*']) with self.assertRaises(errors.NotFound): - entries = self.ld.get_entries( + self.ld.get_entries( self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*']) def test_1_add(self): @@ -233,11 +231,11 @@ class test_update(unittest.TestCase): self.assertTrue(modified) with self.assertRaises(errors.NotFound): - entries = self.ld.get_entries( + self.ld.get_entries( self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*']) with self.assertRaises(errors.NotFound): - entries = self.ld.get_entries( + self.ld.get_entries( self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*']) def test_8_badsyntax(self): @@ -245,7 +243,7 @@ class test_update(unittest.TestCase): Test the updater with an unknown keyword (test_8_badsyntax) """ with self.assertRaises(BadSyntax): - modified = self.updater.update( + self.updater.update( [os.path.join(self.testdir, "8_badsyntax.update")]) def test_9_badsyntax(self): @@ -253,5 +251,5 @@ class test_update(unittest.TestCase): Test the updater with an incomplete line (test_9_badsyntax) """ with self.assertRaises(BadSyntax): - modified = self.updater.update( + self.updater.update( [os.path.join(self.testdir, "9_badsyntax.update")]) diff --git a/ipatests/test_integration/tasks.py b/ipatests/test_integration/tasks.py index 6c26626..7c96227 100644 --- a/ipatests/test_integration/tasks.py +++ b/ipatests/test_integration/tasks.py @@ -44,8 +44,6 @@ from ipalib.util import get_reverse_zone_default, verify_host_resolvable from ipalib.constants import DOMAIN_SUFFIX_NAME from ipalib.constants import DOMAIN_LEVEL_0 -# pylint: disable=unused-variable - log = log_mgr.get_logger(__name__) @@ -156,7 +154,6 @@ def backup_file(host, filename): host.run_command('echo %s >> %s' % ( ipautil.shell_quote(filename), ipautil.shell_quote(rmname))) - contents = host.get_file_contents(rmname) host.transport.mkdir_recursive(os.path.dirname(rmname)) return False @@ -980,7 +977,7 @@ def double_circle_topo(master, replicas, site_size=6): yield a, b # create agreement to one server in two next sites - for (c, d, _ignore) in [sites[(i+n) % num_sites] for n in [1, 2]]: + for c, _d, _ignore in [sites[(i+n) % num_sites] for n in [1, 2]]: yield b, c if site_size > 2: @@ -1023,7 +1020,6 @@ def install_clients(servers, clients): def _entries_to_ldif(entries): """Format LDAP entries as LDIF""" - lines = [] io = StringIO() writer = LDIFWriter(io) for entry in entries: diff --git a/ipatests/test_ipalib/test_frontend.py b/ipatests/test_ipalib/test_frontend.py index f160b7f..7413408 100644 --- a/ipatests/test_ipalib/test_frontend.py +++ b/ipatests/test_ipalib/test_frontend.py @@ -36,8 +36,6 @@ from ipalib import output, messages from ipalib.parameters import Str from ipapython.version import API_VERSION -# pylint: disable=unused-variable - if six.PY3: unicode = str @@ -459,7 +457,7 @@ class test_Command(ClassChecker): kw = dict(option0=u'some value') - (api, home) = create_test_api() + api, _home = create_test_api() api.finalize() o = my_cmd(api) o.finalize() @@ -583,7 +581,7 @@ class test_Command(ClassChecker): args = ('one', 'two') kw = dict(three=('three1', 'three2'), four='four') - (api, home) = create_test_api() + api, _home = create_test_api() api.finalize() o = my_cmd(api) o.finalize() @@ -622,7 +620,7 @@ class test_Command(ClassChecker): kw = dict(how_are='you', on_this='fine day?', version=API_VERSION) # Test in server context: - (api, home) = create_test_api(in_server=True) + api, _home = create_test_api(in_server=True) api.finalize() o = my_cmd(api) if six.PY2: @@ -633,7 +631,7 @@ class test_Command(ClassChecker): assert ('execute', args, kw) == out # Test in non-server context - (api, home) = create_test_api(in_server=False) + api, _home = create_test_api(in_server=False) api.finalize() o = my_cmd(api) if six.PY2: @@ -668,7 +666,7 @@ class test_Command(ClassChecker): expected = [TestMessage().to_dict()] # Test in server context: - (api, home) = create_test_api(in_server=True) + api, _home = create_test_api(in_server=True) api.finalize() o = my_cmd(api) if six.PY2: @@ -678,7 +676,7 @@ class test_Command(ClassChecker): assert {'name': 'execute', 'messages': expected} == o.run(*args, **kw) # Test in non-server context - (api, home) = create_test_api(in_server=False) + api, _home = create_test_api(in_server=False) api.finalize() o = my_cmd(api) if six.PY2: @@ -859,7 +857,7 @@ class test_LocalOrRemote(ClassChecker): return dict(result=('execute', args, options)) # Test when in_server=False: - (api, home) = create_test_api(in_server=False) + api, _home = create_test_api(in_server=False) api.add_plugin(example) api.finalize() cmd = api.Command.example @@ -877,7 +875,7 @@ class test_LocalOrRemote(ClassChecker): ) # Test when in_server=True (should always call execute): - (api, home) = create_test_api(in_server=True) + api, _home = create_test_api(in_server=True) api.add_plugin(example) api.finalize() cmd = api.Command.example @@ -1001,7 +999,7 @@ class test_Object(ClassChecker): """ Test the `ipalib.frontend.Object.primary_key` attribute. """ - (api, home) = create_test_api() + api, _home = create_test_api() api.finalize() # Test with no primary keys: @@ -1047,7 +1045,7 @@ class test_Object(ClassChecker): """ Test the `ipalib.frontend.Object.backend` attribute. """ - (api, home) = create_test_api() + api, _home = create_test_api() class ldap(backend.Backend): whatever = 'It worked!' api.add_plugin(ldap) @@ -1079,7 +1077,7 @@ class test_Object(ClassChecker): """ class example(self.cls): takes_params = ('one', 'two', 'three', 'four') - (api, home) = create_test_api() + api, _home = create_test_api() api.finalize() o = example(api) p = o.params @@ -1137,7 +1135,7 @@ class test_Method(ClassChecker): """ Return a finalized `ipalib.plugable.API` instance. """ - (api, home) = create_test_api() + api, _home = create_test_api() class user(frontend.Object): takes_params = ( 'givenname', diff --git a/ipatests/test_ipalib/test_parameters.py b/ipatests/test_ipalib/test_parameters.py index 64259d1..a23f97d 100644 --- a/ipatests/test_ipalib/test_parameters.py +++ b/ipatests/test_ipalib/test_parameters.py @@ -43,8 +43,6 @@ from ipalib.constants import TYPE_ERROR, CALLABLE_ERROR from ipalib.errors import ValidationError, ConversionError from ipalib import _ -# pylint: disable=unused-variable - if six.PY3: unicode = str long = int @@ -253,7 +251,7 @@ class test_Param(ClassChecker): ('extra4', callable, lambda whatever: whatever + 7), ) o = Subclass('my_param') # Test with no **kw: - for (key, kind, default) in o.kwargs: + for key, kind, _default in o.kwargs: # Test with a type invalid for all: value = object() kw = {key: value} @@ -353,7 +351,7 @@ class test_Param(ClassChecker): assert clone is not orig assert type(clone) is self.cls assert clone.name is orig.name - for (key, kind, default) in self.cls.kwargs: + for key, _kind, _default in self.cls.kwargs: assert getattr(clone, key) == getattr(orig, key) # Test with a param spec: @@ -363,7 +361,7 @@ class test_Param(ClassChecker): assert clone.param_spec == 'my_param*' assert clone is not orig assert type(clone) is self.cls - for (key, kind, default) in self.cls.kwargs: + for key, _kind, _default in self.cls.kwargs: assert getattr(clone, key) == getattr(orig, key) # Test with overrides: @@ -390,7 +388,7 @@ class test_Param(ClassChecker): assert clone is not orig assert type(clone) is self.cls assert clone.name == new_name - for (key, kind, default) in self.cls.kwargs: + for key, _kind, _default in self.cls.kwargs: if key in ('cli_name', 'label', 'doc', 'cli_metavar'): continue assert getattr(clone, key) is getattr(orig, key) @@ -449,7 +447,7 @@ class test_Param(ClassChecker): assert o._convert_scalar(None) is None assert dummy.called() is False # Test with incorrect type - e = raises(errors.ConversionError, o._convert_scalar, 'hello') + raises(errors.ConversionError, o._convert_scalar, 'hello') def test_validate(self): """ @@ -1511,7 +1509,7 @@ class test_AccessTime(ClassChecker): u'periodical yearly month 4 day 1-31 0800-1400', u'periodic weekly day 8 0800-1400', ): - e = raises(ValidationError, o._rule_required, None, value) + raises(ValidationError, o._rule_required, None, value) def test_create_param(): """ diff --git a/ipatests/test_ipalib/test_rpc.py b/ipatests/test_ipalib/test_rpc.py index de63b2a..cfa1515 100644 --- a/ipatests/test_ipalib/test_rpc.py +++ b/ipatests/test_ipalib/test_rpc.py @@ -34,8 +34,6 @@ from ipalib.request import context, Connection from ipalib import rpc, errors, api, request from ipapython.version import API_VERSION -# pylint: disable=unused-variable - if six.PY3: unicode = str @@ -44,7 +42,7 @@ std_compound = (binary_bytes, utf8_bytes, unicode_str) def dump_n_load(value): - (param, method) = loads( + param, _method = loads( dumps((value,), allow_none=True) ) return param[0] @@ -115,7 +113,7 @@ def test_xml_wrap(): u = f(u'hello', API_VERSION) assert type(u) is unicode assert u == u'hello' - value = f([dict(one=False, two=u'hello'), None, b'hello'], API_VERSION) + f([dict(one=False, two=u'hello'), None, b'hello'], API_VERSION) def test_xml_unwrap(): @@ -211,7 +209,7 @@ class test_xmlclient(PluginTester): class user_add(Command): pass - (o, api, home) = self.instance('Backend', user_add, in_server=False) + o, _api, _home = self.instance('Backend', user_add, in_server=False) args = (binary_bytes, utf8_bytes, unicode_str) kw = dict(one=binary_bytes, two=utf8_bytes, three=unicode_str) params = [args, kw] @@ -281,7 +279,7 @@ class test_xml_introspection(object): def test_list_methods_many_params(self): try: - result = api.Backend.xmlclient.conn.system.listMethods('foo') + api.Backend.xmlclient.conn.system.listMethods('foo') except Fault as f: print(f) assert f.faultCode == 3003 @@ -301,7 +299,7 @@ class test_xml_introspection(object): def test_signature_no_params(self): try: - result = api.Backend.xmlclient.conn.system.methodSignature() + api.Backend.xmlclient.conn.system.methodSignature() except Fault as f: print(f) assert f.faultCode == 3007 @@ -311,7 +309,7 @@ class test_xml_introspection(object): def test_signature_many_params(self): try: - result = api.Backend.xmlclient.conn.system.methodSignature('a', 'b') + api.Backend.xmlclient.conn.system.methodSignature('a', 'b') except Fault as f: print(f) assert f.faultCode == 3004 @@ -322,7 +320,7 @@ class test_xml_introspection(object): def test_help_no_params(self): try: - result = api.Backend.xmlclient.conn.system.methodHelp() + api.Backend.xmlclient.conn.system.methodHelp() except Fault as f: print(f) assert f.faultCode == 3007 @@ -332,7 +330,7 @@ class test_xml_introspection(object): def test_help_many_params(self): try: - result = api.Backend.xmlclient.conn.system.methodHelp('a', 'b') + api.Backend.xmlclient.conn.system.methodHelp('a', 'b') except Fault as f: print(f) assert f.faultCode == 3004 diff --git a/ipatests/test_ipaserver/test_rpcserver.py b/ipatests/test_ipaserver/test_rpcserver.py index 858264e..6cc2472 100644 --- a/ipatests/test_ipaserver/test_rpcserver.py +++ b/ipatests/test_ipaserver/test_rpcserver.py @@ -30,8 +30,6 @@ from ipatests.util import assert_equal, raises, PluginTester from ipalib import errors from ipaserver import rpcserver -# pylint: disable=unused-variable - if six.PY3: unicode = str @@ -196,7 +194,7 @@ class test_xmlserver(PluginTester): _plugin = rpcserver.xmlserver def test_marshaled_dispatch(self): # FIXME - (o, api, home) = self.instance('Backend', in_server=True) + self.instance('Backend', in_server=True) class test_jsonserver(PluginTester): @@ -210,7 +208,7 @@ class test_jsonserver(PluginTester): """ Test the `ipaserver.rpcserver.jsonserver.unmarshal` method. """ - (o, api, home) = self.instance('Backend', in_server=True) + o, _api, _home = self.instance('Backend', in_server=True) # Test with invalid JSON-data: e = raises(errors.JSONError, o.unmarshal, 'this wont work') diff --git a/ipatests/test_ipaserver/test_serverroles.py b/ipatests/test_ipaserver/test_serverroles.py index 63ed5f8..0118105 100644 --- a/ipatests/test_ipaserver/test_serverroles.py +++ b/ipatests/test_ipaserver/test_serverroles.py @@ -15,7 +15,6 @@ from ipalib import api, create_api, errors from ipapython.dn import DN from ipatests.util import MockLDAP -# pylint: disable=unused-variable def _make_service_entry_mods(enabled=True, other_config=None): mods = { @@ -308,7 +307,7 @@ class MockMasterTopology(object): if entries: entries.sort(key=lambda x: len(x[0]), reverse=True) - for entry_dn, attrs in entries: + for entry_dn, _attrs in entries: self.ldap.del_entry(str(entry_dn)) def _add_ipamaster_services(self, master_dn): @@ -320,7 +319,7 @@ class MockMasterTopology(object): self.ldap.add_entry(str(svc_dn), _make_service_entry_mods()) def _add_members(self, dn, fqdn, member_attrs): - entry, attrs = self.ldap.connection.search_s( + _entry, attrs = self.ldap.connection.search_s( str(dn), ldap.SCOPE_SUBTREE)[0] mods = [] value = attrs.get('member', []) @@ -344,7 +343,7 @@ class MockMasterTopology(object): self.ldap.connection.modify_s(str(dn), mods) def _remove_members(self, dn, fqdn, member_attrs): - entry, attrs = self.ldap.connection.search_s( + _entry, attrs = self.ldap.connection.search_s( str(dn), ldap.SCOPE_SUBTREE)[0] mods = [] for a in member_attrs: @@ -574,7 +573,7 @@ def configured_role(request): @pytest.fixture(params=list(role_provider_iter(master_data)), ids=['{} providers'.format(role_name) - for role_name, m in + for role_name, _m in role_provider_iter(master_data)]) def role_providers(request): return request.param