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
command = paths.LS
def setUp(self):
def setup(self):
# Find the executable in $PATH
# This is neded because ipautil.run resets the PATH to
# a system default.
@ -65,14 +65,14 @@ class cmdline_test(XMLRPC_test):
raise AssertionError(
'Command %r not available' % original_command
)
super(cmdline_test, self).setUp()
super(cmdline_test, self).setup()
if not server_available:
raise nose.SkipTest(
'Server not available: %r' % api.env.xmlrpc_uri
)
def tearDown(self):
def teardown(self):
"""
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):
num_replicas = 0
def tearDown(self):
def teardown(self):
self.uninstall_server()
# Remove CA cert in /etc/pki/nssdb, in case of failed (un)install
@ -750,7 +750,7 @@ class TestServerInstall(CALessBase):
class TestReplicaInstall(CALessBase):
num_replicas = 1
def setUp(self):
def setup(self):
# Install the master for every test
self.export_pkcs12('ca1/server')
with open(self.pem_filename, 'w') as f:
@ -759,7 +759,7 @@ class TestReplicaInstall(CALessBase):
result = self.install_server()
assert result.returncode == 0
def tearDown(self):
def teardown(self):
# Uninstall both master and replica
replica = self.replicas[0]
tasks.kinit_admin(self.master)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,8 +33,8 @@ new_password = u'new_password'
class test_changepw(XMLRPC_test, Unauthorized_HTTP_test):
app_uri = '/ipa/session/change_password'
def setUp(self):
super(test_changepw, self).setUp()
def setup(self):
super(test_changepw, self).setup()
try:
api.Command['user_add'](uid=testuser, givenname=u'Test', sn=u'User')
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
)
def tearDown(self):
def teardown(self):
try:
api.Command['user_del']([testuser])
except errors.NotFound:
pass
super(test_changepw, self).tearDown()
super(test_changepw, self).teardown()
def _changepw(self, user, old_password, new_password):
return self.send_request(params={'user': str(user),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -43,8 +43,8 @@ def get_trusted_group_name():
class test_external_members(Declarative):
@classmethod
def setUpClass(cls):
super(test_external_members, cls).setUpClass()
def setup_class(cls):
super(test_external_members, cls).setup_class()
if not api.Backend.rpcclient.isconnected():
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"
@classmethod
def setUpClass(cls):
def setup_class(cls):
[cls.keytabfd,cls.keytabname] = tempfile.mkstemp()
os.close(cls.keytabfd)

View File

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

View File

@ -385,9 +385,9 @@ group1_gid = id_shift + 900100
class test_range(Declarative):
@classmethod
def setUpClass(cls):
super(test_range, cls).setUpClass()
cls.tearDownClass()
def setup_class(cls):
super(test_range, cls).setup_class()
cls.teardown_class()
cls.mockldap = MockLDAP()
cls.mockldap.add_entry(trust_container_dn, trust_container_add)
cls.mockldap.add_entry(smb_cont_dn, smb_cont_add)
@ -412,7 +412,7 @@ class test_range(Declarative):
cls.mockldap.unbind()
@classmethod
def tearDownClass(cls):
def teardown_class(cls):
cls.mockldap = MockLDAP()
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):
@classmethod
def setUpClass(cls):
super(test_trustconfig, cls).setUpClass()
def setup_class(cls):
super(test_trustconfig, cls).setup_class()
if not api.Backend.rpcclient.isconnected():
api.Backend.rpcclient.connect(fallback=False)
try:

View File

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

View File

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

View File

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