diff --git a/tests/__init__.py b/tests/__init__.py index 80fec0cc..feba16fb 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -59,8 +59,8 @@ def is_monkey_patched(): return is_gevent_monkey_patched() or is_eventlet_monkey_patched() -MONKEY_PATCH_LOOP = bool(os.getenv('MONKEY_PATCH_LOOP', False)) +MONKEY_PATCH_LOOP = bool(os.getenv('MONKEY_PATCH_LOOP', False) == "1") notwindows = unittest.skipUnless(not "Windows" in platform.system(), "This test is not adequate for windows") -notpypy = unittest.skipUnless(not '__pypy__' in sys.builtin_module_names, "This tests is not suitable for pypy") +notpypy = unittest.skipUnless(not platform.python_implementation() == 'PyPy', "This tests is not suitable for pypy") notmonkeypatch = unittest.skipUnless(MONKEY_PATCH_LOOP, "Skpping this test because monkey patching is required") \ No newline at end of file diff --git a/tests/unit/io/eventlet_utils.py b/tests/unit/io/eventlet_utils.py index 05ef6bc9..2ed929c8 100644 --- a/tests/unit/io/eventlet_utils.py +++ b/tests/unit/io/eventlet_utils.py @@ -20,10 +20,11 @@ try: import thread import Queue import __builtin__ -except: + #For python3 compatibility +except ImportError: import _thread as thread import queue as Queue - import builtins + import builtins as __builtin__ import threading import ssl diff --git a/tests/unit/io/test_eventletreactor.py b/tests/unit/io/test_eventletreactor.py index 01445735..69ee23e4 100644 --- a/tests/unit/io/test_eventletreactor.py +++ b/tests/unit/io/test_eventletreactor.py @@ -19,34 +19,31 @@ except ImportError: import unittest # noqa from tests.unit.io.utils import TimerConnectionTests -from tests.unit.io.eventlet_utils import restore_saved_module, eventlet_un_patch_all -from tests import notpypy, MONKEY_PATCH_LOOP +from tests.unit.io.eventlet_utils import restore_saved_module +from tests import notpypy +from tests import notmonkeypatch + import time from eventlet import monkey_patch, kill -import threading try: from cassandra.io.eventletreactor import EventletConnection except ImportError: EventletConnection = None # noqa +@unittest.skipUnless(EventletConnection is not None, "Skpping the eventlet tests because it's not installed") +@notmonkeypatch +# There are some issues with some versions of pypy and eventlet +@notpypy class EventletTimerTest(unittest.TestCase, TimerConnectionTests): - # There are some issues with some versions of pypy and eventlet - @notpypy + def setUp(self): - if not MONKEY_PATCH_LOOP: - raise unittest.SkipTest("Skpping because monkey patching may affect the rest of the tests") - - if not EventletConnection: - raise unittest.SkipTest("Can't test eventlet without monkey patching") - - monkey_patch(thread=False, time=True) + self.connection_class = EventletConnection + # We only to patch the time module + monkey_patch(time=True) EventletConnection.initialize_reactor() def tearDown(self): kill(EventletConnection._timeout_watcher) EventletConnection._timers = None restore_saved_module(time) - - def getClass(self): - return EventletConnection diff --git a/tests/unit/io/test_geventreactor.py b/tests/unit/io/test_geventreactor.py index 4bcfa315..ad7f9de7 100644 --- a/tests/unit/io/test_geventreactor.py +++ b/tests/unit/io/test_geventreactor.py @@ -19,8 +19,7 @@ except ImportError: from tests.unit.io.utils import TimerConnectionTests -from tests import MONKEY_PATCH_LOOP - +from tests import notmonkeypatch try: from cassandra.io.geventreactor import GeventConnection import gevent.monkey @@ -28,20 +27,16 @@ try: except ImportError: GeventConnection = None # noqa - +@unittest.skipUnless(GeventConnection is not None, "Skpping the gevent tests because it's not installed") +@notmonkeypatch class GeventTimerTest(unittest.TestCase, TimerConnectionTests): - def setUp(self): - if not MONKEY_PATCH_LOOP: - raise unittest.SkipTest("Skpping because monkey patching may affect the rest of the tests") - if not GeventConnection: - raise unittest.SkipTest("Can't test gevent without monkey patching") + def setUp(self): + self.connection_class = GeventConnection + #We only to patch the time module gevent.monkey.patch_time() GeventConnection.initialize_reactor() def tearDown(self): restore_saved_module("time") - GeventConnection._timers = None - - def getClass(self): - return GeventConnection + GeventConnection._timers = None \ No newline at end of file diff --git a/tests/unit/io/utils.py b/tests/unit/io/utils.py index 3a3179dc..4533f771 100644 --- a/tests/unit/io/utils.py +++ b/tests/unit/io/utils.py @@ -116,11 +116,11 @@ class TimerConnectionTests(object): Verify that timer timeouts are honored appropriately """ # Tests timers submitted in order at various timeouts - submit_and_wait_for_completion(self, self.getClass(), 0, 100, 1, 100) + submit_and_wait_for_completion(self, self.connection_class, 0, 100, 1, 100) # Tests timers submitted in reverse order at various timeouts - submit_and_wait_for_completion(self, self.getClass(), 100, 0, -1, 100) + submit_and_wait_for_completion(self, self.connection_class, 100, 0, -1, 100) # Tests timers submitted in varying order at various timeouts - submit_and_wait_for_completion(self, self.getClass(), 0, 100, 1, 100, True), + submit_and_wait_for_completion(self, self.connection_class, 0, 100, 1, 100, True), def test_timer_cancellation(self): """ @@ -130,11 +130,11 @@ class TimerConnectionTests(object): # Various lists for tracking callback stage timeout = .1 callback = TimerCallback(timeout) - timer = self.getClass().create_timer(timeout, callback.invoke) + timer = self.connection_class.create_timer(timeout, callback.invoke) timer.cancel() # Release context allow for timer thread to run. time.sleep(.2) - timer_manager = self.getClass()._timers + timer_manager = self.connection_class._timers # Assert that the cancellation was honored self.assertFalse(timer_manager._queue) self.assertFalse(timer_manager._new_timers) diff --git a/tox.ini b/tox.ini index 06bb8274..9b221315 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,6 @@ deps = nose six packaging cython - gevent eventlet twisted <15.5.0 @@ -17,12 +16,14 @@ deps = {[base]deps} setenv = LIBEV_EMBED=0 CARES_EMBED=0 + MONKEY_PATCH_LOOP=0 changedir = {envtmpdir} commands = nosetests --verbosity=2 --no-path-adjustment {toxinidir}/tests/unit/ [testenv:py27] deps = {[base]deps} + gevent setenv = LIBEV_EMBED=0 CARES_EMBED=0 @@ -35,6 +36,7 @@ commands = [testenv:py34] deps = {[base]deps} + gevent setenv = LIBEV_EMBED=0 CARES_EMBED=0