Remove unused variables in tests

This commit removes or marks unused variables as "expected to be unused"
by using '_' prefix.

Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
This commit is contained in:
Martin Basti committed 2016-09-27 13:35:58 +02:00
1 parent 0f88f8fe88
commit 9d83be3647
42 files changed
+93 -111

No files matched your search

@@ -90,13 +90,13 @@ class CertManipCmdTestBase(XMLRPC_test):
# list of certificates to add to entry
cls.certs = [
get_testcert(DN(('CN', cls.entity_subject)), cls.entity_principal)
for i in range(3)
for _i in range(3)
]
# list of certificates for testing of removal of non-existent certs
cls.nonexistent_certs = [
get_testcert(DN(('CN', cls.entity_subject)), cls.entity_principal)
for j in range(2)
for _j in range(2)
]
# cert subset to remove from entry
@@ -184,7 +184,8 @@ class test_automount(AutomountTest):
"""
Test adding a duplicate key using `xmlrpc.automountkey_add` method.
"""
res = api.Command['automountkey_add'](self.locname, self.mapname, **self.key_kw)
api.Command['automountkey_add'](
self.locname, self.mapname, **self.key_kw)
def test_5_automountmap_show(self):
"""
@@ -368,7 +369,8 @@ class test_automount_direct(AutomountTest):
"""
Test adding a duplicate direct map.
"""
res = api.Command['automountmap_add_indirect'](self.locname, self.mapname, **self.direct_kw)['result']
api.Command['automountmap_add_indirect'](
self.locname, self.mapname, **self.direct_kw)
def test_2a_automountmap_tofiles(self):
"""Test the `automountmap_tofiles` command"""
+6 -3
View File
@@ -53,7 +53,8 @@ def test_exc_wrapper():
# Test with one callback first
@test_callback.register_exc_callback
def handle_exception(self, keys, options, e, call_func, *args, **kwargs):
def handle_exception( # pylint: disable=unused-variable
self, keys, options, e, call_func, *args, **kwargs):
assert args == (1, 2)
assert kwargs == dict(a=1, b=2)
handled_exceptions.append(type(e))
@@ -150,7 +151,8 @@ def test_exc_callback_registration():
pass
@callbacktest_subclass.register_exc_callback
def exc_callback(self, keys, options, exc, call_func, *args, **kwargs):
def exc_callback( # pylint: disable=unused-variable
self, keys, options, exc, call_func, *args, **kwargs):
"""Subclass's private exception callback"""
messages.append('Subclass registered callback')
raise exc
@@ -163,7 +165,8 @@ def test_exc_callback_registration():
@callbacktest_base.register_exc_callback
def exc_callback_2(self, keys, options, exc, call_func, *args, **kwargs):
def exc_callback_2( # pylint: disable=unused-variable
self, keys, options, exc, call_func, *args, **kwargs):
"""Callback on super class; doesn't affect the subclass"""
messages.append('Superclass registered callback')
raise exc
+5 -5
View File
@@ -141,11 +141,11 @@ class test_cert(XMLRPC_test):
This should fail because the service principal doesn't exist
"""
# First create the host that will use this policy
res = api.Command['host_add'](self.host_fqdn, force= True)['result']
assert 'result' in api.Command['host_add'](self.host_fqdn, force=True)
csr = unicode(self.generateCSR(str(self.subject)))
with assert_raises(errors.NotFound):
res = api.Command['cert_request'](csr, principal=self.service_princ)
api.Command['cert_request'](csr, principal=self.service_princ)
def test_0002_cert_add(self):
"""
@@ -267,7 +267,7 @@ class test_cert_find(XMLRPC_test):
"""
Search for the OCSP certificate.
"""
res = api.Command['cert_find'](subject=u'OCSP Subsystem')
api.Command['cert_find'](subject=u'OCSP Subsystem')
def test_0004_find_this_host(self):
"""
@@ -458,7 +458,7 @@ class test_cert_find(XMLRPC_test):
"""
Search with a negative sizelimit
"""
res = api.Command['cert_find'](sizelimit=-100)
api.Command['cert_find'](sizelimit=-100)
def test_0029_search_for_notfound(self):
"""
@@ -479,4 +479,4 @@ class test_cert_find(XMLRPC_test):
"""
Search using invalid date format
"""
res = api.Command['cert_find'](issuedon_from=u'xyz')
api.Command['cert_find'](issuedon_from=u'xyz')
+3 -3
View File
@@ -268,7 +268,7 @@ class test_hbac(XMLRPC_test):
"""
Test deprecated command hbacrule_add_sourcehost.
"""
ret = api.Command['hbacrule_add_sourcehost'](
api.Command['hbacrule_add_sourcehost'](
self.rule_name, host=self.test_host, hostgroup=self.test_hostgroup
)
@@ -307,7 +307,7 @@ class test_hbac(XMLRPC_test):
"""
Test deprecated command hbacrule_remove_sourcehost.
"""
ret = api.Command['hbacrule_remove_sourcehost'](
api.Command['hbacrule_remove_sourcehost'](
self.rule_name, host=self.test_host, hostgroup=self.test_hostgroup
)
@@ -316,7 +316,7 @@ class test_hbac(XMLRPC_test):
"""
Test adding the same external host using `xmlrpc.hbacrule_add_host`.
"""
ret = api.Command['hbacrule_mod'](
api.Command['hbacrule_mod'](
self.rule_name, setattr=self.test_invalid_sourcehost
)
+4 -4
View File
@@ -91,20 +91,20 @@ class test_hbactest(XMLRPC_test):
self.rule_names[i], accessruletype=self.rule_type, description=self.rule_descs[i],
)
ret = api.Command['hbacrule_add_user'](
api.Command['hbacrule_add_user'](
self.rule_names[i], user=self.test_user, group=self.test_group
)
ret = api.Command['hbacrule_add_host'](
api.Command['hbacrule_add_host'](
self.rule_names[i], host=self.test_host, hostgroup=self.test_hostgroup
)
ret = api.Command['hbacrule_add_service'](
api.Command['hbacrule_add_service'](
self.rule_names[i], hbacsvc=self.test_service
)
if i & 1:
ret = api.Command['hbacrule_disable'](self.rule_names[i])
api.Command['hbacrule_disable'](self.rule_names[i])
def test_a_hbactest_check_rules_detail(self):
"""
+9 -10
View File
@@ -619,9 +619,9 @@ class TestHostDNS(XMLRPC_test):
try:
ipv6only_host.create(force=False)
finally:
command = ipv6only_host.run_command('dnsrecord_del', dnszone,
ipv6only_host.shortname,
aaaarecord=aaaarec)
ipv6only_host.run_command(
'dnsrecord_del', dnszone, ipv6only_host.shortname,
aaaarecord=aaaarec)
def test_add_ipv4only_host(self, dns_setup, ipv4only_host):
ipv4only_host.run_command('dnsrecord_add', dnszone,
@@ -629,9 +629,9 @@ class TestHostDNS(XMLRPC_test):
try:
ipv4only_host.create(force=False)
finally:
command = ipv4only_host.run_command('dnsrecord_del', dnszone,
ipv4only_host.shortname,
arecord=arec)
ipv4only_host.run_command(
'dnsrecord_del', dnszone, ipv4only_host.shortname,
arecord=arec)
def test_add_ipv46both_host(self, dns_setup, ipv46both_host):
ipv46both_host.run_command('dnsrecord_add', dnszone,
@@ -640,10 +640,9 @@ class TestHostDNS(XMLRPC_test):
try:
ipv46both_host.create(force=False)
finally:
command = ipv46both_host.run_command('dnsrecord_del', dnszone,
ipv46both_host.shortname,
arecord=arec2,
aaaarecord=aaaarec2)
ipv46both_host.run_command(
'dnsrecord_del', dnszone, ipv46both_host.shortname,
arecord=arec2, aaaarecord=aaaarec2)
def test_add_ipv4_host_from_ip(self, dns_setup, ipv4_fromip_host):
ipv4_fromip_host.ensure_missing()
@@ -138,7 +138,7 @@ def lineinfo(level):
# Including this info in the test name makes it possible
# to locate failing tests.
frame = inspect.currentframe()
for i in range(level):
for _i in range(level):
frame = frame.f_back
lineno = frame.f_lineno
filename = os.path.basename(frame.f_code.co_filename)
@@ -3455,9 +3455,8 @@ class test_managed_permissions(Declarative):
ldap = ldap2(api)
ldap.connect()
result = api.Command.permission_add(permission1, type=u'user',
ipapermright=u'write',
attrs=[u'cn'])
api.Command.permission_add(
permission1, type=u'user', ipapermright=u'write', attrs=[u'cn'])
# TODO: This hack relies on the permission internals.
# Change as necessary.
@@ -3468,8 +3467,7 @@ class test_managed_permissions(Declarative):
ldap.update_entry(entry)
# Update the ACI via the API
result = api.Command.permission_mod(permission1,
attrs=[u'l', u'o', u'cn'])
api.Command.permission_mod(permission1, attrs=[u'l', u'o', u'cn'])
# Set the permission type to MANAGED
entry = ldap.get_entry(permission1_dn)
+2 -1
View File
@@ -163,7 +163,8 @@ class test_pwpolicy(XMLRPC_test):
Test adding password policy to a managed group.
"""
try:
entry = api.Command['pwpolicy_add'](self.user, krbminpwdlife=50, cospriority=2)['result']
api.Command['pwpolicy_add'](
self.user, krbminpwdlife=50, cospriority=2)
except errors.ManagedPolicyError:
pass
else:
-4
View File
@@ -93,10 +93,6 @@ def makecert(reqdir, subject, principal):
# Generate NSS cert database to store the private key for our CSR
run_certutil(reqdir, ["-N", "-f", pwname])
res = api.Command['config_show']()
subject_base = res['result']['ipacertificatesubjectbase'][0]
cert = None
csr = unicode(generate_csr(reqdir, pwname, str(subject)))
res = api.Command['cert_request'](csr, principal=principal, add=True)
@@ -110,7 +110,7 @@ class AutomemberTracker(Tracker):
try:
self.attrs[u'group'] =\
self.attrs[u'group'] + [options[u'group']]
except KeyError as ex:
except KeyError:
self.attrs[u'group'] = [options[u'group']]
# search for hosts in the target automember and
# add them as memberindirect hosts
@@ -118,7 +118,7 @@ class AutomemberTracker(Tracker):
try:
self.attrs[u'hostgroup'] =\
self.attrs[u'hostgroup'] + [options[u'hostgroup']]
except KeyError as ex:
except KeyError:
self.attrs[u'hostgroup'] = [options[u'hostgroup']]
command = self.make_add_member_command(options)
@@ -135,12 +135,12 @@ class AutomemberTracker(Tracker):
try:
if not self.attrs[u'member_host']:
del self.attrs[u'member_host']
except KeyError as ex:
except KeyError:
pass
try:
if not self.attrs[u'member_automember']:
del self.attrs[u'member_automember']
except KeyError as ex:
except KeyError:
pass
command = self.make_remove_member_command(options)
+4 -4
View File
@@ -117,13 +117,13 @@ class GroupTracker(Tracker):
try:
self.attrs[u'member_user'] =\
self.attrs[u'member_user'] + [options[u'user']]
except KeyError as ex:
except KeyError:
self.attrs[u'member_user'] = [options[u'user']]
elif u'group' in options:
try:
self.attrs[u'member_group'] =\
self.attrs[u'member_group'] + [options[u'group']]
except KeyError as ex:
except KeyError:
self.attrs[u'member_group'] = [options[u'group']]
command = self.make_add_member_command(options)
@@ -140,12 +140,12 @@ class GroupTracker(Tracker):
try:
if not self.attrs[u'member_user']:
del self.attrs[u'member_user']
except KeyError as ex:
except KeyError:
pass
try:
if not self.attrs[u'member_group']:
del self.attrs[u'member_group']
except KeyError as ex:
except KeyError:
pass
command = self.make_remove_member_command(options)
@@ -91,7 +91,7 @@ class HostGroupTracker(Tracker):
try:
self.attrs[u'member_host'] =\
self.attrs[u'member_host'] + [options[u'host']]
except KeyError as ex:
except KeyError:
self.attrs[u'member_host'] = [options[u'host']]
# search for hosts in the target hostgroup and
# add them as memberindirect hosts
@@ -99,7 +99,7 @@ class HostGroupTracker(Tracker):
try:
self.attrs[u'member_hostgroup'] =\
self.attrs[u'member_hostgroup'] + [options[u'hostgroup']]
except KeyError as ex:
except KeyError:
self.attrs[u'member_hostgroup'] = [options[u'hostgroup']]
command = self.make_add_member_command(options)
@@ -116,12 +116,12 @@ class HostGroupTracker(Tracker):
try:
if not self.attrs[u'member_host']:
del self.attrs[u'member_host']
except KeyError as ex:
except KeyError:
pass
try:
if not self.attrs[u'member_hostgroup']:
del self.attrs[u'member_hostgroup']
except KeyError as ex:
except KeyError:
pass
command = self.make_remove_member_command(options)
@@ -88,7 +88,7 @@ class SudoCmdGroupTracker(Tracker):
try:
self.attrs[u'member_sudocmd'] =\
self.attrs[u'member_sudocmd'] + [options[u'sudocmd']]
except KeyError as ex:
except KeyError:
self.attrs[u'member_sudocmd'] = [options[u'sudocmd']]
command = self.make_add_member_command(options)
@@ -102,7 +102,7 @@ class SudoCmdGroupTracker(Tracker):
try:
if not self.attrs[u'member_sudocmd']:
del self.attrs[u'member_sudocmd']
except KeyError as ex:
except KeyError:
pass
command = self.make_remove_member_command(options)
+1 -1
View File
@@ -165,7 +165,7 @@ class UserTracker(KerberosAliasMixin, Tracker):
(self.kwargs[key].split('@'))[0].lower(),
(self.kwargs[key].split('@'))[1]
)]
except IndexError as ex:
except IndexError:
# we can provide just principal part
self.attrs[key] = [u'%s@%s' % (
(self.kwargs[key].lower(),