tests: Use PEP8-compliant setup/teardown method names

The setUp/dearDown names are used in the unittest module, but there is no reason
to use them in non-`unittest` test cases.
Nose supports both styles (but mixing them can cause trouble when
calling super()'s methods).
Pytest only supports the new ones.

https://fedorahosted.org/freeipa/ticket/4610

Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
Petr Viktorin 2014-10-07 12:48:22 +02:00 committed by Tomas Babej
parent 7de424f425
commit 375e9f7c4b
21 changed files with 56 additions and 62 deletions

View File

@ -52,7 +52,7 @@ class cmdline_test(XMLRPC_test):
# some reasonable default command # some reasonable default command
command = paths.LS command = paths.LS
def setUp(self): def setup(self):
# Find the executable in $PATH # Find the executable in $PATH
# This is neded because ipautil.run resets the PATH to # This is neded because ipautil.run resets the PATH to
# a system default. # a system default.
@ -65,14 +65,14 @@ class cmdline_test(XMLRPC_test):
raise AssertionError( raise AssertionError(
'Command %r not available' % original_command 'Command %r not available' % original_command
) )
super(cmdline_test, self).setUp() super(cmdline_test, self).setup()
if not server_available: if not server_available:
raise nose.SkipTest( raise nose.SkipTest(
'Server not available: %r' % api.env.xmlrpc_uri 'Server not available: %r' % api.env.xmlrpc_uri
) )
def tearDown(self): def teardown(self):
""" """
nose tear-down fixture. nose tear-down fixture.
""" """
super(cmdline_test, self).tearDown() super(cmdline_test, self).teardown()

View File

@ -340,7 +340,7 @@ class CALessBase(IntegrationTest):
class TestServerInstall(CALessBase): class TestServerInstall(CALessBase):
num_replicas = 0 num_replicas = 0
def tearDown(self): def teardown(self):
self.uninstall_server() self.uninstall_server()
# Remove CA cert in /etc/pki/nssdb, in case of failed (un)install # Remove CA cert in /etc/pki/nssdb, in case of failed (un)install
@ -750,7 +750,7 @@ class TestServerInstall(CALessBase):
class TestReplicaInstall(CALessBase): class TestReplicaInstall(CALessBase):
num_replicas = 1 num_replicas = 1
def setUp(self): def setup(self):
# Install the master for every test # Install the master for every test
self.export_pkcs12('ca1/server') self.export_pkcs12('ca1/server')
with open(self.pem_filename, 'w') as f: with open(self.pem_filename, 'w') as f:
@ -759,7 +759,7 @@ class TestReplicaInstall(CALessBase):
result = self.install_server() result = self.install_server()
assert result.returncode == 0 assert result.returncode == 0
def tearDown(self): def teardown(self):
# Uninstall both master and replica # Uninstall both master and replica
replica = self.replicas[0] replica = self.replicas[0]
tasks.kinit_admin(self.master) tasks.kinit_admin(self.master)

View File

@ -44,11 +44,11 @@ class TestForcedClientReenrollment(IntegrationTest):
'krb5.keytab' 'krb5.keytab'
) )
def setUp(self): def setup(self):
tasks.prepare_host(self.clients[0]) tasks.prepare_host(self.clients[0])
tasks.install_client(self.master, self.clients[0]) tasks.install_client(self.master, self.clients[0])
def tearDown(self): def teardown(self):
tasks.uninstall_client(self.clients[0]) tasks.uninstall_client(self.clients[0])
self.delete_client_host_entry() self.delete_client_host_entry()

View File

@ -248,7 +248,7 @@ class test_xmlclient(PluginTester):
class test_xml_introspection(object): class test_xml_introspection(object):
@classmethod @classmethod
def setUpClass(self): def setup_class(self):
try: try:
api.Backend.xmlclient.connect(fallback=False) api.Backend.xmlclient.connect(fallback=False)
except (errors.NetworkError, IOError): except (errors.NetworkError, IOError):
@ -256,7 +256,7 @@ class test_xml_introspection(object):
(__name__, api.env.xmlrpc_uri)) (__name__, api.env.xmlrpc_uri))
@classmethod @classmethod
def tearDownClass(self): def teardown_class(self):
request.destroy_context() request.destroy_context()
def test_list_methods(self): def test_list_methods(self):

View File

@ -46,7 +46,7 @@ def test_create_translation():
class test_TestLang(object): class test_TestLang(object):
def setUp(self): def setup(self):
self.tmp_dir = None self.tmp_dir = None
self.saved_lang = None self.saved_lang = None
@ -85,7 +85,7 @@ class test_TestLang(object):
self.po_file_iterate = po_file_iterate self.po_file_iterate = po_file_iterate
def tearDown(self): def teardown(self):
if self.saved_lang is not None: if self.saved_lang is not None:
os.environ['LANG'] = self.saved_lang os.environ['LANG'] = self.saved_lang

View File

@ -25,12 +25,6 @@ import unittest
from ipapython import ipavalidate from ipapython import ipavalidate
class TestValidate(unittest.TestCase): class TestValidate(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_validEmail(self): def test_validEmail(self):
self.assertEqual(True, ipavalidate.Email("test@freeipa.org")) self.assertEqual(True, ipavalidate.Email("test@freeipa.org"))
self.assertEqual(True, ipavalidate.Email("", notEmpty=False)) self.assertEqual(True, ipavalidate.Email("", notEmpty=False))

View File

@ -36,7 +36,7 @@ class test_keyring(object):
Test the kernel keyring interface Test the kernel keyring interface
""" """
def setUp(self): def setup(self):
try: try:
kernel_keyring.del_key(TEST_KEY) kernel_keyring.del_key(TEST_KEY)
except ValueError: except ValueError:

View File

@ -33,8 +33,8 @@ new_password = u'new_password'
class test_changepw(XMLRPC_test, Unauthorized_HTTP_test): class test_changepw(XMLRPC_test, Unauthorized_HTTP_test):
app_uri = '/ipa/session/change_password' app_uri = '/ipa/session/change_password'
def setUp(self): def setup(self):
super(test_changepw, self).setUp() super(test_changepw, self).setup()
try: try:
api.Command['user_add'](uid=testuser, givenname=u'Test', sn=u'User') api.Command['user_add'](uid=testuser, givenname=u'Test', sn=u'User')
api.Command['passwd'](testuser, password=u'old_password') api.Command['passwd'](testuser, password=u'old_password')
@ -43,12 +43,12 @@ class test_changepw(XMLRPC_test, Unauthorized_HTTP_test):
'Cannot set up test user: %s' % e 'Cannot set up test user: %s' % e
) )
def tearDown(self): def teardown(self):
try: try:
api.Command['user_del']([testuser]) api.Command['user_del']([testuser])
except errors.NotFound: except errors.NotFound:
pass pass
super(test_changepw, self).tearDown() super(test_changepw, self).teardown()
def _changepw(self, user, old_password, new_password): def _changepw(self, user, old_password, new_password):
return self.send_request(params={'user': str(user), return self.send_request(params={'user': str(user),

View File

@ -44,7 +44,7 @@ class test_ldap(object):
Test various LDAP client bind methods. Test various LDAP client bind methods.
""" """
def setUp(self): def setup(self):
self.conn = None self.conn = None
self.ldapuri = 'ldap://%s' % ipautil.format_netloc(api.env.host) self.ldapuri = 'ldap://%s' % ipautil.format_netloc(api.env.host)
self.ccache = paths.TMP_KRB5CC % os.getuid() self.ccache = paths.TMP_KRB5CC % os.getuid()
@ -52,7 +52,7 @@ class test_ldap(object):
self.dn = DN(('krbprincipalname','ldap/%s@%s' % (api.env.host, api.env.realm)), self.dn = DN(('krbprincipalname','ldap/%s@%s' % (api.env.host, api.env.realm)),
('cn','services'),('cn','accounts'),api.env.basedn) ('cn','services'),('cn','accounts'),api.env.basedn)
def tearDown(self): def teardown(self):
if self.conn and self.conn.isconnected(): if self.conn and self.conn.isconnected():
self.conn.disconnect() self.conn.disconnect()
@ -158,14 +158,14 @@ class test_LDAPEntry(object):
dn1 = DN(('cn', cn1[0])) dn1 = DN(('cn', cn1[0]))
dn2 = DN(('cn', cn2[0])) dn2 = DN(('cn', cn2[0]))
def setUp(self): def setup(self):
self.ldapuri = 'ldap://%s' % ipautil.format_netloc(api.env.host) self.ldapuri = 'ldap://%s' % ipautil.format_netloc(api.env.host)
self.conn = ldap2(shared_instance=False, ldap_uri=self.ldapuri) self.conn = ldap2(shared_instance=False, ldap_uri=self.ldapuri)
self.conn.connect() self.conn.connect()
self.entry = self.conn.make_entry(self.dn1, cn=self.cn1) self.entry = self.conn.make_entry(self.dn1, cn=self.cn1)
def tearDown(self): def teardown(self):
if self.conn and self.conn.isconnected(): if self.conn and self.conn.isconnected():
self.conn.disconnect() self.conn.disconnect()

View File

@ -34,7 +34,7 @@ class test_update(object):
Test the PKCS#10 Parser. Test the PKCS#10 Parser.
""" """
def setUp(self): def setup(self):
nss.nss_init_nodb() nss.nss_init_nodb()
if ipautil.file_exists("test0.csr"): if ipautil.file_exists("test0.csr"):
self.testdir="./" self.testdir="./"

View File

@ -113,7 +113,7 @@ class UI_driver(object):
""" """
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
if NO_SELENIUM: if NO_SELENIUM:
raise nose.SkipTest('Selenium not installed') raise nose.SkipTest('Selenium not installed')
@ -161,7 +161,7 @@ class UI_driver(object):
if 'type' not in c: if 'type' not in c:
c['type'] = DEFAULT_TYPE c['type'] = DEFAULT_TYPE
def setUp(self): def setup(self):
""" """
Test setup Test setup
""" """
@ -169,7 +169,7 @@ class UI_driver(object):
self.driver = self.get_driver() self.driver = self.get_driver()
self.driver.maximize_window() self.driver.maximize_window()
def tearDown(self): def teardown(self):
""" """
Test clean up Test clean up
""" """

View File

@ -70,8 +70,8 @@ def is_db_configured():
class test_cert(XMLRPC_test): class test_cert(XMLRPC_test):
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
super(test_cert, cls).setUpClass() super(test_cert, cls).setup_class()
if 'cert_request' not in api.Command: if 'cert_request' not in api.Command:
raise nose.SkipTest('cert_request not registered') raise nose.SkipTest('cert_request not registered')
@ -83,8 +83,8 @@ class test_cert(XMLRPC_test):
new_args = new_args + args new_args = new_args + args
return ipautil.run(new_args, stdin) return ipautil.run(new_args, stdin)
def setUp(self): def setup(self):
super(test_cert, self).setUp() super(test_cert, self).setup()
self.reqdir = tempfile.mkdtemp(prefix = "tmp-") self.reqdir = tempfile.mkdtemp(prefix = "tmp-")
self.reqfile = self.reqdir + "/test.csr" self.reqfile = self.reqdir + "/test.csr"
self.pwname = self.reqdir + "/pwd" self.pwname = self.reqdir + "/pwd"
@ -99,8 +99,8 @@ class test_cert(XMLRPC_test):
self.subject = DN(('CN', self.host_fqdn), x509.subject_base()) self.subject = DN(('CN', self.host_fqdn), x509.subject_base())
def tearDown(self): def teardown(self):
super(test_cert, self).tearDown() super(test_cert, self).teardown()
shutil.rmtree(self.reqdir, ignore_errors=True) shutil.rmtree(self.reqdir, ignore_errors=True)
def generateCSR(self, subject): def generateCSR(self, subject):
@ -204,8 +204,8 @@ class test_cert(XMLRPC_test):
class test_cert_find(XMLRPC_test): class test_cert_find(XMLRPC_test):
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
super(test_cert_find, cls).setUpClass() super(test_cert_find, cls).setup_class()
if 'cert_find' not in api.Command: if 'cert_find' not in api.Command:
raise nose.SkipTest('cert_find not registered') raise nose.SkipTest('cert_find not registered')

View File

@ -334,8 +334,8 @@ if have_ldap2:
class test_dns(Declarative): class test_dns(Declarative):
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
super(test_dns, cls).setUpClass() super(test_dns, cls).setup_class()
if not api.Backend.rpcclient.isconnected(): if not api.Backend.rpcclient.isconnected():
api.Backend.rpcclient.connect(fallback=False) api.Backend.rpcclient.connect(fallback=False)
@ -3726,8 +3726,8 @@ zone_root_permission_dn = DN(('cn', zone_root_permission),
class test_root_zone(Declarative): class test_root_zone(Declarative):
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
super(test_root_zone, cls).setUpClass() super(test_root_zone, cls).setup_class()
if not api.Backend.rpcclient.isconnected(): if not api.Backend.rpcclient.isconnected():
api.Backend.rpcclient.connect(fallback=False) api.Backend.rpcclient.connect(fallback=False)

View File

@ -43,8 +43,8 @@ def get_trusted_group_name():
class test_external_members(Declarative): class test_external_members(Declarative):
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
super(test_external_members, cls).setUpClass() super(test_external_members, cls).setup_class()
if not api.Backend.rpcclient.isconnected(): if not api.Backend.rpcclient.isconnected():
api.Backend.rpcclient.connect(fallback=False) api.Backend.rpcclient.connect(fallback=False)

View File

@ -980,7 +980,7 @@ class test_host_false_pwd_change(XMLRPC_test):
command = "ipa-client/ipa-join" command = "ipa-client/ipa-join"
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
[cls.keytabfd,cls.keytabname] = tempfile.mkstemp() [cls.keytabfd,cls.keytabname] = tempfile.mkstemp()
os.close(cls.keytabfd) os.close(cls.keytabfd)

View File

@ -3164,8 +3164,8 @@ class test_managed_permissions(Declarative):
] ]
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
super(test_managed_permissions, cls).setUpClass() super(test_managed_permissions, cls).setup_class()
if not have_ldap2: if not have_ldap2:
raise nose.SkipTest('server plugin not available') raise nose.SkipTest('server plugin not available')

View File

@ -385,9 +385,9 @@ group1_gid = id_shift + 900100
class test_range(Declarative): class test_range(Declarative):
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
super(test_range, cls).setUpClass() super(test_range, cls).setup_class()
cls.tearDownClass() cls.teardown_class()
cls.mockldap = MockLDAP() cls.mockldap = MockLDAP()
cls.mockldap.add_entry(trust_container_dn, trust_container_add) cls.mockldap.add_entry(trust_container_dn, trust_container_add)
cls.mockldap.add_entry(smb_cont_dn, smb_cont_add) cls.mockldap.add_entry(smb_cont_dn, smb_cont_add)
@ -412,7 +412,7 @@ class test_range(Declarative):
cls.mockldap.unbind() cls.mockldap.unbind()
@classmethod @classmethod
def tearDownClass(cls): def teardown_class(cls):
cls.mockldap = MockLDAP() cls.mockldap = MockLDAP()
cls.mockldap.del_entry(domain2_dn) cls.mockldap.del_entry(domain2_dn)

View File

@ -39,8 +39,8 @@ default_group_dn = DN(('cn', default_group), api.env.container_group, api.env.ba
class test_trustconfig(Declarative): class test_trustconfig(Declarative):
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
super(test_trustconfig, cls).setUpClass() super(test_trustconfig, cls).setup_class()
if not api.Backend.rpcclient.isconnected(): if not api.Backend.rpcclient.isconnected():
api.Backend.rpcclient.connect(fallback=False) api.Backend.rpcclient.connect(fallback=False)
try: try:

View File

@ -1607,8 +1607,8 @@ class test_denied_bind_with_expired_principal(XMLRPC_test):
password = u'random' password = u'random'
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
super(test_denied_bind_with_expired_principal, cls).setUpClass() super(test_denied_bind_with_expired_principal, cls).setup_class()
cls.connection = ldap.initialize('ldap://{host}' cls.connection = ldap.initialize('ldap://{host}'
.format(host=api.env.host)) .format(host=api.env.host))

View File

@ -168,16 +168,16 @@ class XMLRPC_test(object):
""" """
@classmethod @classmethod
def setUpClass(cls): def setup_class(cls):
if not server_available: if not server_available:
raise nose.SkipTest('%r: Server not available: %r' % raise nose.SkipTest('%r: Server not available: %r' %
(cls.__module__, api.env.xmlrpc_uri)) (cls.__module__, api.env.xmlrpc_uri))
def setUp(self): def setup(self):
if not api.Backend.rpcclient.isconnected(): if not api.Backend.rpcclient.isconnected():
api.Backend.rpcclient.connect(fallback=False) api.Backend.rpcclient.connect(fallback=False)
def tearDown(self): def teardown(self):
""" """
nose tear-down fixture. nose tear-down fixture.
""" """

View File

@ -448,7 +448,7 @@ class ClassChecker(object):
'get_subcls()' 'get_subcls()'
) )
def tearDown(self): def teardown(self):
""" """
nose tear-down fixture. nose tear-down fixture.
""" """
@ -533,7 +533,7 @@ class PluginTester(object):
o = api[namespace][self.plugin.__name__] o = api[namespace][self.plugin.__name__]
return (o, api, home) return (o, api, home)
def tearDown(self): def teardown(self):
""" """
nose tear-down fixture. nose tear-down fixture.
""" """