From b5bfb4231a3fba918fa23be25c6a60c993c2e517 Mon Sep 17 00:00:00 2001 From: Christopher Grebs Date: Sun, 28 Aug 2011 17:30:10 +0200 Subject: [PATCH 1/2] Fixed test_transport_pyamqplib, localhost != 127.0.0.1 --- kombu/tests/test_transport_pyamqplib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kombu/tests/test_transport_pyamqplib.py b/kombu/tests/test_transport_pyamqplib.py index 3e2f3423..5cb17c5f 100644 --- a/kombu/tests/test_transport_pyamqplib.py +++ b/kombu/tests/test_transport_pyamqplib.py @@ -19,7 +19,7 @@ class test_amqplib(unittest.TestCase): c = BrokerConnection(port=None, transport=Transport).connect() self.assertEqual(c["host"], - "localhost:%s" % (Transport.default_port, )) + "127.0.0.1:%s" % (Transport.default_port, )) def test_custom_port(self): @@ -27,4 +27,4 @@ class test_amqplib(unittest.TestCase): Connection = MockConnection c = BrokerConnection(port=1337, transport=Transport).connect() - self.assertEqual(c["host"], "localhost:1337") + self.assertEqual(c["host"], "127.0.0.1:1337") From 9f78ae0fed389f5d3e009aa3e11ef45f2697408d Mon Sep 17 00:00:00 2001 From: Christopher Grebs Date: Sun, 28 Aug 2011 17:30:44 +0200 Subject: [PATCH 2/2] Fixed unittests to run with PyPy, moved some module logic to test utilities --- kombu/tests/test_serialization.py | 28 +++++----------------------- kombu/tests/test_utils.py | 3 ++- kombu/tests/utils.py | 29 +++++++++++++++++++++++++++++ requirements/test-pypy.txt | 6 ++++++ tox.ini | 10 +++++++++- 5 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 requirements/test-pypy.txt diff --git a/kombu/tests/test_serialization.py b/kombu/tests/test_serialization.py index 6ed0d5c0..3ac4e08a 100644 --- a/kombu/tests/test_serialization.py +++ b/kombu/tests/test_serialization.py @@ -11,7 +11,7 @@ from kombu.serialization import registry, register, SerializerNotInstalled, \ unregister, register_pickle from kombu.tests.utils import unittest -from kombu.tests.utils import mask_modules +from kombu.tests.utils import mask_modules, skip_if_not_module # For content_encoding tests unicode_string = u'abcdé\u8463' @@ -120,28 +120,18 @@ class test_Serialization(unittest.TestCase): content_type='application/json', content_encoding='utf-8')) + @skip_if_not_module('msgpack') def test_msgpack_decode(self): register_msgpack() - try: - __import__("msgpack") - except ImportError: - say("* msgpack-python not installed, will not execute " - "related tests.") - raise SkipTest("msgpack-python not installed") self.assertEquals(msgpack_py_data, registry.decode( msgpack_data, content_type='application/x-msgpack', content_encoding='binary')) + @skip_if_not_module('msgpack') def test_msgpack_encode(self): register_msgpack() - try: - __import__("msgpack") - except ImportError: - say("* msgpack-python not installed, will not execute " - "related tests.") - raise SkipTest("msgpack-python not installed") self.assertEquals(registry.decode( registry.encode(msgpack_py_data, serializer="msgpack")[-1], content_type='application/x-msgpack', @@ -151,26 +141,18 @@ class test_Serialization(unittest.TestCase): content_type='application/x-msgpack', content_encoding='binary')) + @skip_if_not_module('yaml') def test_yaml_decode(self): register_yaml() - try: - __import__("yaml") - except ImportError: - say("* PyYAML not installed, will not execute related tests.") - raise SkipTest("PyYAML not installed") self.assertEquals(py_data, registry.decode( yaml_data, content_type='application/x-yaml', content_encoding='utf-8')) + @skip_if_not_module('yaml') def test_yaml_encode(self): register_yaml() - try: - __import__("yaml") - except ImportError: - say("* PyYAML not installed, will not execute related tests.") - raise SkipTest("PyYAML not installed") self.assertEquals(registry.decode( registry.encode(py_data, serializer="yaml")[-1], content_type='application/x-yaml', diff --git a/kombu/tests/test_utils.py b/kombu/tests/test_utils.py index 058e6d9a..8af9f993 100644 --- a/kombu/tests/test_utils.py +++ b/kombu/tests/test_utils.py @@ -10,7 +10,7 @@ else: from kombu import utils from kombu.utils.functional import wraps -from kombu.tests.utils import redirect_stdouts, mask_modules +from kombu.tests.utils import redirect_stdouts, mask_modules, skip_if_module partition = utils._compat_partition rpartition = utils._compat_rpartition @@ -93,6 +93,7 @@ class test_UUID(unittest.TestCase): self.assertIsInstance(i1, str) self.assertNotEqual(i1, i2) + @skip_if_module('__pypy__') def test_gen_unique_id_without_ctypes(self): old_utils = sys.modules.pop("kombu.utils") diff --git a/kombu/tests/utils.py b/kombu/tests/utils.py index 545f51b2..8ef4cbd4 100644 --- a/kombu/tests/utils.py +++ b/kombu/tests/utils.py @@ -110,5 +110,34 @@ def skip_if_environ(env_var_name): return _wrap_test +def skip_if_module(module): + def _wrap_test(fun): + @wraps(fun) + def _skip_if_module(*args, **kwargs): + try: + __import__(module) + raise SkipTest("SKIP %s: %s available\n" % ( + fun.__name__, module)) + except ImportError: + pass + return fun(*args, **kwargs) + return _skip_if_module + return _wrap_test + + +def skip_if_not_module(module): + def _wrap_test(fun): + @wraps(fun) + def _skip_if_not_module(*args, **kwargs): + try: + __import__(module) + except ImportError: + raise SkipTest("SKIP %s: %s available\n" % ( + fun.__name__, module)) + return fun(*args, **kwargs) + return _skip_if_not_module + return _wrap_test + + def skip_if_quick(fun): return skip_if_environ("QUICKTEST")(fun) diff --git a/requirements/test-pypy.txt b/requirements/test-pypy.txt new file mode 100644 index 00000000..a06af83e --- /dev/null +++ b/requirements/test-pypy.txt @@ -0,0 +1,6 @@ +nose +nose-cover3 +unittest2>=0.5.0 +coverage>=3.0 +simplejson +PyYAML==3.09 # 3.10 dropped 2.4 support diff --git a/tox.ini b/tox.ini index c7e0678b..6f3211ef 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py24,py25,py26,py27 +envlist = py24,py25,py26,py27,pypy [testenv] distribute = True @@ -39,3 +39,11 @@ commands = pip -E {envdir} install -r contrib/requirements/default.txt nosetests --with-xunit --xunit-file=nosetests.xml \ --with-coverage3 --cover3-xml \ --cover3-xml-file=coverage.xml + +[testenv:pypy] +basepython = pypy +commands = pip -E {envdir} install -r contrib/requirements/default.txt + pip -E {envdir} install -r contrib/requirements/test-pypy.txt + nosetests --with-xunit --xunit-file=nosetests.xml \ + --with-coverage3 --cover3-xml \ + --cover3-xml-file=coverage.xml