From eacbd5bfddae5dc79bc1ce8faf40c00c987743ca Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Thu, 14 May 2015 23:31:21 +0200 Subject: [PATCH] tests/common: refactor Python 2.6 compatibility functions. --- tests/common.py | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/common.py b/tests/common.py index 873ef84..3d0d534 100644 --- a/tests/common.py +++ b/tests/common.py @@ -25,31 +25,31 @@ assert_true, ) -try: - from nose.tools import assert_is -except ImportError: +if sys.version_info >= (2, 7): + from nose.tools import ( + assert_greater, + assert_is, + assert_is_instance, + assert_is_none, + assert_is_not_none, + ) +else: # Python 2.6: + def assert_greater(x, y): + assert_true( + x > y, + msg='{0!r} not greater than {1!r}'.format(x, y) + ) def assert_is(obj, cls): assert_true( obj is cls, msg='{0!r} is not {1!r}'.format(obj, cls) ) - -try: - from nose.tools import assert_is_instance -except ImportError: - # Python 2.6: def assert_is_instance(obj, cls): assert_true( isinstance(obj, cls), msg='{0!r} is not an instance of {1!r}'.format(obj, cls) ) - -try: - from nose.tools import assert_is_none - from nose.tools import assert_is_not_none -except ImportError: - # Python 2.6: def assert_is_none(obj): assert_true( obj is None, @@ -61,16 +61,6 @@ def assert_is_not_none(obj): msg='{0!r} is not None'.format(obj) ) -try: - from nose.tools import assert_greater -except ImportError: - # Python 2.6: - def assert_greater(x, y): - assert_true( - x > y, - msg='{0!r} not greater than {1!r}'.format(x, y) - ) - def assert_regexp_matches(regexp, text): if isinstance(regexp, basestring): regexp = re.compile(regexp)