Pylint: remove unused variables in tests

Reviewed-By: Pavel Vomacka <pvomacka@redhat.com>
This commit is contained in:
Martin Basti
2016-10-06 20:28:59 +02:00
parent 51af7a1598
commit 49b29591aa
8 changed files with 41 additions and 58 deletions

View File

@@ -34,8 +34,6 @@ from ipatests.test_integration import tasks
from ipatests.test_integration.config import Config from ipatests.test_integration.config import Config
from ipatests.test_integration.env_config import get_global_config from ipatests.test_integration.env_config import get_global_config
# pylint: disable=unused-variable
log = log_mgr.get_logger(__name__) 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 '-') # $HOSTNAME-$FILENAME (with '/' replaced by '-')
beakerlib_plugin.run_beakerlib_command(['pushd', topdirname]) beakerlib_plugin.run_beakerlib_command(['pushd', topdirname])
try: try:
for dirpath, dirnames, filenames in os.walk(topdirname): for dirpath, _dirnames, filenames in os.walk(topdirname):
for filename in filenames: for filename in filenames:
fullname = os.path.relpath( fullname = os.path.relpath(
os.path.join(dirpath, filename), topdirname) 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}) {role: 1 for role in cls.required_extra_roles})
domain_descriptions = [domain_description] domain_descriptions = [domain_description]
for i in range(cls.num_ad_domains): for _i in range(cls.num_ad_domains):
domain_descriptions.append({ domain_descriptions.append({
'type': 'AD', 'type': 'AD',
'hosts': {'ad': 1, 'ad_subdomain': 1}, 'hosts': {'ad': 1, 'ad_subdomain': 1},

View File

@@ -34,8 +34,6 @@ from ipapython import ipautil, ipaldap
from ipaplatform.paths import paths from ipaplatform.paths import paths
from ipapython.dn import DN from ipapython.dn import DN
# pylint: disable=unused-variable
""" """
The updater works through files only so this is just a thin-wrapper controlling The updater works through files only so this is just a thin-wrapper controlling
which file we test at any given point. which file we test at any given point.
@@ -93,11 +91,11 @@ class test_update(unittest.TestCase):
self.assertTrue(modified) self.assertTrue(modified)
with self.assertRaises(errors.NotFound): with self.assertRaises(errors.NotFound):
entries = self.ld.get_entries( self.ld.get_entries(
self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*']) self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
with self.assertRaises(errors.NotFound): with self.assertRaises(errors.NotFound):
entries = self.ld.get_entries( self.ld.get_entries(
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*']) self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
def test_1_add(self): def test_1_add(self):
@@ -233,11 +231,11 @@ class test_update(unittest.TestCase):
self.assertTrue(modified) self.assertTrue(modified)
with self.assertRaises(errors.NotFound): with self.assertRaises(errors.NotFound):
entries = self.ld.get_entries( self.ld.get_entries(
self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*']) self.container_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
with self.assertRaises(errors.NotFound): with self.assertRaises(errors.NotFound):
entries = self.ld.get_entries( self.ld.get_entries(
self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*']) self.user_dn, self.ld.SCOPE_BASE, 'objectclass=*', ['*'])
def test_8_badsyntax(self): def test_8_badsyntax(self):
@@ -245,7 +243,7 @@ class test_update(unittest.TestCase):
Test the updater with an unknown keyword (test_8_badsyntax) Test the updater with an unknown keyword (test_8_badsyntax)
""" """
with self.assertRaises(BadSyntax): with self.assertRaises(BadSyntax):
modified = self.updater.update( self.updater.update(
[os.path.join(self.testdir, "8_badsyntax.update")]) [os.path.join(self.testdir, "8_badsyntax.update")])
def test_9_badsyntax(self): def test_9_badsyntax(self):
@@ -253,5 +251,5 @@ class test_update(unittest.TestCase):
Test the updater with an incomplete line (test_9_badsyntax) Test the updater with an incomplete line (test_9_badsyntax)
""" """
with self.assertRaises(BadSyntax): with self.assertRaises(BadSyntax):
modified = self.updater.update( self.updater.update(
[os.path.join(self.testdir, "9_badsyntax.update")]) [os.path.join(self.testdir, "9_badsyntax.update")])

View File

@@ -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_SUFFIX_NAME
from ipalib.constants import DOMAIN_LEVEL_0 from ipalib.constants import DOMAIN_LEVEL_0
# pylint: disable=unused-variable
log = log_mgr.get_logger(__name__) log = log_mgr.get_logger(__name__)
@@ -156,7 +154,6 @@ def backup_file(host, filename):
host.run_command('echo %s >> %s' % ( host.run_command('echo %s >> %s' % (
ipautil.shell_quote(filename), ipautil.shell_quote(filename),
ipautil.shell_quote(rmname))) ipautil.shell_quote(rmname)))
contents = host.get_file_contents(rmname)
host.transport.mkdir_recursive(os.path.dirname(rmname)) host.transport.mkdir_recursive(os.path.dirname(rmname))
return False return False
@@ -980,7 +977,7 @@ def double_circle_topo(master, replicas, site_size=6):
yield a, b yield a, b
# create agreement to one server in two next sites # 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 yield b, c
if site_size > 2: if site_size > 2:
@@ -1023,7 +1020,6 @@ def install_clients(servers, clients):
def _entries_to_ldif(entries): def _entries_to_ldif(entries):
"""Format LDAP entries as LDIF""" """Format LDAP entries as LDIF"""
lines = []
io = StringIO() io = StringIO()
writer = LDIFWriter(io) writer = LDIFWriter(io)
for entry in entries: for entry in entries:

View File

@@ -36,8 +36,6 @@ from ipalib import output, messages
from ipalib.parameters import Str from ipalib.parameters import Str
from ipapython.version import API_VERSION from ipapython.version import API_VERSION
# pylint: disable=unused-variable
if six.PY3: if six.PY3:
unicode = str unicode = str
@@ -459,7 +457,7 @@ class test_Command(ClassChecker):
kw = dict(option0=u'some value') kw = dict(option0=u'some value')
(api, home) = create_test_api() api, _home = create_test_api()
api.finalize() api.finalize()
o = my_cmd(api) o = my_cmd(api)
o.finalize() o.finalize()
@@ -583,7 +581,7 @@ class test_Command(ClassChecker):
args = ('one', 'two') args = ('one', 'two')
kw = dict(three=('three1', 'three2'), four='four') kw = dict(three=('three1', 'three2'), four='four')
(api, home) = create_test_api() api, _home = create_test_api()
api.finalize() api.finalize()
o = my_cmd(api) o = my_cmd(api)
o.finalize() o.finalize()
@@ -622,7 +620,7 @@ class test_Command(ClassChecker):
kw = dict(how_are='you', on_this='fine day?', version=API_VERSION) kw = dict(how_are='you', on_this='fine day?', version=API_VERSION)
# Test in server context: # Test in server context:
(api, home) = create_test_api(in_server=True) api, _home = create_test_api(in_server=True)
api.finalize() api.finalize()
o = my_cmd(api) o = my_cmd(api)
if six.PY2: if six.PY2:
@@ -633,7 +631,7 @@ class test_Command(ClassChecker):
assert ('execute', args, kw) == out assert ('execute', args, kw) == out
# Test in non-server context # Test in non-server context
(api, home) = create_test_api(in_server=False) api, _home = create_test_api(in_server=False)
api.finalize() api.finalize()
o = my_cmd(api) o = my_cmd(api)
if six.PY2: if six.PY2:
@@ -668,7 +666,7 @@ class test_Command(ClassChecker):
expected = [TestMessage().to_dict()] expected = [TestMessage().to_dict()]
# Test in server context: # Test in server context:
(api, home) = create_test_api(in_server=True) api, _home = create_test_api(in_server=True)
api.finalize() api.finalize()
o = my_cmd(api) o = my_cmd(api)
if six.PY2: if six.PY2:
@@ -678,7 +676,7 @@ class test_Command(ClassChecker):
assert {'name': 'execute', 'messages': expected} == o.run(*args, **kw) assert {'name': 'execute', 'messages': expected} == o.run(*args, **kw)
# Test in non-server context # Test in non-server context
(api, home) = create_test_api(in_server=False) api, _home = create_test_api(in_server=False)
api.finalize() api.finalize()
o = my_cmd(api) o = my_cmd(api)
if six.PY2: if six.PY2:
@@ -859,7 +857,7 @@ class test_LocalOrRemote(ClassChecker):
return dict(result=('execute', args, options)) return dict(result=('execute', args, options))
# Test when in_server=False: # 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.add_plugin(example)
api.finalize() api.finalize()
cmd = api.Command.example cmd = api.Command.example
@@ -877,7 +875,7 @@ class test_LocalOrRemote(ClassChecker):
) )
# Test when in_server=True (should always call execute): # 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.add_plugin(example)
api.finalize() api.finalize()
cmd = api.Command.example cmd = api.Command.example
@@ -1001,7 +999,7 @@ class test_Object(ClassChecker):
""" """
Test the `ipalib.frontend.Object.primary_key` attribute. Test the `ipalib.frontend.Object.primary_key` attribute.
""" """
(api, home) = create_test_api() api, _home = create_test_api()
api.finalize() api.finalize()
# Test with no primary keys: # Test with no primary keys:
@@ -1047,7 +1045,7 @@ class test_Object(ClassChecker):
""" """
Test the `ipalib.frontend.Object.backend` attribute. Test the `ipalib.frontend.Object.backend` attribute.
""" """
(api, home) = create_test_api() api, _home = create_test_api()
class ldap(backend.Backend): class ldap(backend.Backend):
whatever = 'It worked!' whatever = 'It worked!'
api.add_plugin(ldap) api.add_plugin(ldap)
@@ -1079,7 +1077,7 @@ class test_Object(ClassChecker):
""" """
class example(self.cls): class example(self.cls):
takes_params = ('one', 'two', 'three', 'four') takes_params = ('one', 'two', 'three', 'four')
(api, home) = create_test_api() api, _home = create_test_api()
api.finalize() api.finalize()
o = example(api) o = example(api)
p = o.params p = o.params
@@ -1137,7 +1135,7 @@ class test_Method(ClassChecker):
""" """
Return a finalized `ipalib.plugable.API` instance. Return a finalized `ipalib.plugable.API` instance.
""" """
(api, home) = create_test_api() api, _home = create_test_api()
class user(frontend.Object): class user(frontend.Object):
takes_params = ( takes_params = (
'givenname', 'givenname',

View File

@@ -43,8 +43,6 @@ from ipalib.constants import TYPE_ERROR, CALLABLE_ERROR
from ipalib.errors import ValidationError, ConversionError from ipalib.errors import ValidationError, ConversionError
from ipalib import _ from ipalib import _
# pylint: disable=unused-variable
if six.PY3: if six.PY3:
unicode = str unicode = str
long = int long = int
@@ -253,7 +251,7 @@ class test_Param(ClassChecker):
('extra4', callable, lambda whatever: whatever + 7), ('extra4', callable, lambda whatever: whatever + 7),
) )
o = Subclass('my_param') # Test with no **kw: 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: # Test with a type invalid for all:
value = object() value = object()
kw = {key: value} kw = {key: value}
@@ -353,7 +351,7 @@ class test_Param(ClassChecker):
assert clone is not orig assert clone is not orig
assert type(clone) is self.cls assert type(clone) is self.cls
assert clone.name is orig.name 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) assert getattr(clone, key) == getattr(orig, key)
# Test with a param spec: # Test with a param spec:
@@ -363,7 +361,7 @@ class test_Param(ClassChecker):
assert clone.param_spec == 'my_param*' assert clone.param_spec == 'my_param*'
assert clone is not orig assert clone is not orig
assert type(clone) is self.cls 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) assert getattr(clone, key) == getattr(orig, key)
# Test with overrides: # Test with overrides:
@@ -390,7 +388,7 @@ class test_Param(ClassChecker):
assert clone is not orig assert clone is not orig
assert type(clone) is self.cls assert type(clone) is self.cls
assert clone.name == new_name 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'): if key in ('cli_name', 'label', 'doc', 'cli_metavar'):
continue continue
assert getattr(clone, key) is getattr(orig, key) assert getattr(clone, key) is getattr(orig, key)
@@ -449,7 +447,7 @@ class test_Param(ClassChecker):
assert o._convert_scalar(None) is None assert o._convert_scalar(None) is None
assert dummy.called() is False assert dummy.called() is False
# Test with incorrect type # Test with incorrect type
e = raises(errors.ConversionError, o._convert_scalar, 'hello') raises(errors.ConversionError, o._convert_scalar, 'hello')
def test_validate(self): def test_validate(self):
""" """
@@ -1511,7 +1509,7 @@ class test_AccessTime(ClassChecker):
u'periodical yearly month 4 day 1-31 0800-1400', u'periodical yearly month 4 day 1-31 0800-1400',
u'periodic weekly day 8 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(): def test_create_param():
""" """

View File

@@ -34,8 +34,6 @@ from ipalib.request import context, Connection
from ipalib import rpc, errors, api, request from ipalib import rpc, errors, api, request
from ipapython.version import API_VERSION from ipapython.version import API_VERSION
# pylint: disable=unused-variable
if six.PY3: if six.PY3:
unicode = str unicode = str
@@ -44,7 +42,7 @@ std_compound = (binary_bytes, utf8_bytes, unicode_str)
def dump_n_load(value): def dump_n_load(value):
(param, method) = loads( param, _method = loads(
dumps((value,), allow_none=True) dumps((value,), allow_none=True)
) )
return param[0] return param[0]
@@ -115,7 +113,7 @@ def test_xml_wrap():
u = f(u'hello', API_VERSION) u = f(u'hello', API_VERSION)
assert type(u) is unicode assert type(u) is unicode
assert u == u'hello' 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(): def test_xml_unwrap():
@@ -211,7 +209,7 @@ class test_xmlclient(PluginTester):
class user_add(Command): class user_add(Command):
pass 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) args = (binary_bytes, utf8_bytes, unicode_str)
kw = dict(one=binary_bytes, two=utf8_bytes, three=unicode_str) kw = dict(one=binary_bytes, two=utf8_bytes, three=unicode_str)
params = [args, kw] params = [args, kw]
@@ -281,7 +279,7 @@ class test_xml_introspection(object):
def test_list_methods_many_params(self): def test_list_methods_many_params(self):
try: try:
result = api.Backend.xmlclient.conn.system.listMethods('foo') api.Backend.xmlclient.conn.system.listMethods('foo')
except Fault as f: except Fault as f:
print(f) print(f)
assert f.faultCode == 3003 assert f.faultCode == 3003
@@ -301,7 +299,7 @@ class test_xml_introspection(object):
def test_signature_no_params(self): def test_signature_no_params(self):
try: try:
result = api.Backend.xmlclient.conn.system.methodSignature() api.Backend.xmlclient.conn.system.methodSignature()
except Fault as f: except Fault as f:
print(f) print(f)
assert f.faultCode == 3007 assert f.faultCode == 3007
@@ -311,7 +309,7 @@ class test_xml_introspection(object):
def test_signature_many_params(self): def test_signature_many_params(self):
try: try:
result = api.Backend.xmlclient.conn.system.methodSignature('a', 'b') api.Backend.xmlclient.conn.system.methodSignature('a', 'b')
except Fault as f: except Fault as f:
print(f) print(f)
assert f.faultCode == 3004 assert f.faultCode == 3004
@@ -322,7 +320,7 @@ class test_xml_introspection(object):
def test_help_no_params(self): def test_help_no_params(self):
try: try:
result = api.Backend.xmlclient.conn.system.methodHelp() api.Backend.xmlclient.conn.system.methodHelp()
except Fault as f: except Fault as f:
print(f) print(f)
assert f.faultCode == 3007 assert f.faultCode == 3007
@@ -332,7 +330,7 @@ class test_xml_introspection(object):
def test_help_many_params(self): def test_help_many_params(self):
try: try:
result = api.Backend.xmlclient.conn.system.methodHelp('a', 'b') api.Backend.xmlclient.conn.system.methodHelp('a', 'b')
except Fault as f: except Fault as f:
print(f) print(f)
assert f.faultCode == 3004 assert f.faultCode == 3004

View File

@@ -30,8 +30,6 @@ from ipatests.util import assert_equal, raises, PluginTester
from ipalib import errors from ipalib import errors
from ipaserver import rpcserver from ipaserver import rpcserver
# pylint: disable=unused-variable
if six.PY3: if six.PY3:
unicode = str unicode = str
@@ -196,7 +194,7 @@ class test_xmlserver(PluginTester):
_plugin = rpcserver.xmlserver _plugin = rpcserver.xmlserver
def test_marshaled_dispatch(self): # FIXME 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): class test_jsonserver(PluginTester):
@@ -210,7 +208,7 @@ class test_jsonserver(PluginTester):
""" """
Test the `ipaserver.rpcserver.jsonserver.unmarshal` method. 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: # Test with invalid JSON-data:
e = raises(errors.JSONError, o.unmarshal, 'this wont work') e = raises(errors.JSONError, o.unmarshal, 'this wont work')

View File

@@ -15,7 +15,6 @@ from ipalib import api, create_api, errors
from ipapython.dn import DN from ipapython.dn import DN
from ipatests.util import MockLDAP from ipatests.util import MockLDAP
# pylint: disable=unused-variable
def _make_service_entry_mods(enabled=True, other_config=None): def _make_service_entry_mods(enabled=True, other_config=None):
mods = { mods = {
@@ -308,7 +307,7 @@ class MockMasterTopology(object):
if entries: if entries:
entries.sort(key=lambda x: len(x[0]), reverse=True) 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)) self.ldap.del_entry(str(entry_dn))
def _add_ipamaster_services(self, master_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()) self.ldap.add_entry(str(svc_dn), _make_service_entry_mods())
def _add_members(self, dn, fqdn, member_attrs): 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] str(dn), ldap.SCOPE_SUBTREE)[0]
mods = [] mods = []
value = attrs.get('member', []) value = attrs.get('member', [])
@@ -344,7 +343,7 @@ class MockMasterTopology(object):
self.ldap.connection.modify_s(str(dn), mods) self.ldap.connection.modify_s(str(dn), mods)
def _remove_members(self, dn, fqdn, member_attrs): 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] str(dn), ldap.SCOPE_SUBTREE)[0]
mods = [] mods = []
for a in member_attrs: for a in member_attrs:
@@ -574,7 +573,7 @@ def configured_role(request):
@pytest.fixture(params=list(role_provider_iter(master_data)), @pytest.fixture(params=list(role_provider_iter(master_data)),
ids=['{} providers'.format(role_name) ids=['{} providers'.format(role_name)
for role_name, m in for role_name, _m in
role_provider_iter(master_data)]) role_provider_iter(master_data)])
def role_providers(request): def role_providers(request):
return request.param return request.param