test_ipapython: Use functions instead of classes in test generators

pytest's support for Nose-style test generators is not bulletproof;
use a real function to please it.

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

Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
Petr Viktorin 2014-10-23 13:31:45 +02:00 committed by Tomas Babej
parent 82e41dc7a4
commit 387b8b46b8
2 changed files with 11 additions and 11 deletions

View File

@ -24,16 +24,17 @@ import nose
from ipapython import ipautil from ipapython import ipautil
class CheckIPAddress:
def __init__(self, addr):
self.description = "Test IP address parsing and verification (%s)" % addr
def __call__(self, addr, words=None, prefixlen=None): def make_ipaddress_checker(addr, words=None, prefixlen=None):
def check_ipaddress():
try: try:
ip = ipautil.CheckedIPAddress(addr, match_local=False) ip = ipautil.CheckedIPAddress(addr, match_local=False)
assert ip.words == words and ip.prefixlen == prefixlen assert ip.words == words and ip.prefixlen == prefixlen
except: except:
assert words is None and prefixlen is None assert words is None and prefixlen is None
check_ipaddress.description = "Test IP address parsing and verification (%s)" % addr
return check_ipaddress
def test_ip_address(): def test_ip_address():
addrs = [ addrs = [
@ -66,7 +67,7 @@ def test_ip_address():
] ]
for addr in addrs: for addr in addrs:
yield (CheckIPAddress(addr[0]),) + addr yield make_ipaddress_checker(*addr)
class TestCIDict(object): class TestCIDict(object):

View File

@ -25,16 +25,15 @@ import nose
from ipapython import ssh from ipapython import ssh
class CheckPublicKey: def make_public_key_checker(pk, out):
def __init__(self, pk): def check_public_key():
self.description = "Test SSH public key parsing (%s)" % repr(pk)
def __call__(self, pk, out):
try: try:
parsed = ssh.SSHPublicKey(pk) parsed = ssh.SSHPublicKey(pk)
assert parsed.openssh() == out assert parsed.openssh() == out
except Exception, e: except Exception, e:
assert type(e) is out assert type(e) is out
check_public_key.description = "Test SSH public key parsing (%s)" % repr(pk)
return check_public_key
def test_public_key_parsing(): def test_public_key_parsing():
b64 = 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDGAX3xAeLeaJggwTqMjxNwa6XHBUAikXPGMzEpVrlLDCZtv00djsFTBi38PkgxBJVkgRWMrcBsr/35lq7P6w8KGIwA8GI48Z0qBS2NBMJ2u9WQ2hjLN6GdMlo77O0uJY3251p12pCVIS/bHRSq8kHO2No8g7KA9fGGcagPfQH+ee3t7HUkpbQkFTmbPPN++r3V8oVUk5LxbryB3UIIVzNmcSIn3JrXynlvui4MixvrtX6zx+O/bBo68o8/eZD26QrahVbA09fivrn/4h3TM019Eu/c2jOdckfU3cHUV/3Tno5d6JicibyaoDDK7S/yjdn5jhaz8MSEayQvFkZkiF0L' b64 = 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDGAX3xAeLeaJggwTqMjxNwa6XHBUAikXPGMzEpVrlLDCZtv00djsFTBi38PkgxBJVkgRWMrcBsr/35lq7P6w8KGIwA8GI48Z0qBS2NBMJ2u9WQ2hjLN6GdMlo77O0uJY3251p12pCVIS/bHRSq8kHO2No8g7KA9fGGcagPfQH+ee3t7HUkpbQkFTmbPPN++r3V8oVUk5LxbryB3UIIVzNmcSIn3JrXynlvui4MixvrtX6zx+O/bBo68o8/eZD26QrahVbA09fivrn/4h3TM019Eu/c2jOdckfU3cHUV/3Tno5d6JicibyaoDDK7S/yjdn5jhaz8MSEayQvFkZkiF0L'
@ -73,4 +72,4 @@ def test_public_key_parsing():
] ]
for pk in pks: for pk in pks:
yield (CheckPublicKey(pk[0]),) + pk yield make_public_key_checker(*pk)