Refactoring zmq support tests in light of lack of zeromq hub.
This commit is contained in:
@@ -89,23 +89,6 @@ def using_pyevent(_f):
|
|||||||
return 'pyevent' in type(get_hub()).__module__
|
return 'pyevent' in type(get_hub()).__module__
|
||||||
|
|
||||||
|
|
||||||
def using_zmq(_f):
|
|
||||||
try:
|
|
||||||
import zmq
|
|
||||||
except ImportError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def skip_unless_zmq(func):
|
|
||||||
""" Decorator that skips a test if we're not using the zeromq hub."""
|
|
||||||
return skip_unless(using_zmq)(func)
|
|
||||||
|
|
||||||
def skip_with_zmq(func):
|
|
||||||
""" Decorator that skips a test if we're using the zeromq hub."""
|
|
||||||
return skip_if(using_zmq)(func)
|
|
||||||
|
|
||||||
|
|
||||||
def skip_with_pyevent(func):
|
def skip_with_pyevent(func):
|
||||||
""" Decorator that skips a test if we're using the pyevent hub."""
|
""" Decorator that skips a test if we're using the pyevent hub."""
|
||||||
return skip_if(using_pyevent)(func)
|
return skip_if(using_pyevent)(func)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
from tests import LimitedTestCase, main, skip_with_pyevent, skip_if_no_itimer, skip_with_zmq
|
from tests import LimitedTestCase, main, skip_with_pyevent, skip_if_no_itimer
|
||||||
import time
|
import time
|
||||||
import eventlet
|
import eventlet
|
||||||
from eventlet import hubs
|
from eventlet import hubs
|
||||||
@@ -208,7 +208,6 @@ except eventlet.Timeout:
|
|||||||
|
|
||||||
class TestBadFilenos(LimitedTestCase):
|
class TestBadFilenos(LimitedTestCase):
|
||||||
@skip_with_pyevent
|
@skip_with_pyevent
|
||||||
@skip_with_zmq
|
|
||||||
def test_repeated_selects(self):
|
def test_repeated_selects(self):
|
||||||
from eventlet.green import select
|
from eventlet.green import select
|
||||||
self.assertRaises(ValueError, select.select, [-1], [], [])
|
self.assertRaises(ValueError, select.select, [-1], [], [])
|
||||||
@@ -218,7 +217,6 @@ class TestBadFilenos(LimitedTestCase):
|
|||||||
from tests.patcher_test import ProcessBase
|
from tests.patcher_test import ProcessBase
|
||||||
class TestFork(ProcessBase):
|
class TestFork(ProcessBase):
|
||||||
@skip_with_pyevent
|
@skip_with_pyevent
|
||||||
@skip_with_zmq
|
|
||||||
def test_fork(self):
|
def test_fork(self):
|
||||||
new_mod = """
|
new_mod = """
|
||||||
import os
|
import os
|
||||||
|
@@ -1,12 +1,21 @@
|
|||||||
from eventlet import event, spawn, sleep, patcher
|
from eventlet import event, spawn, sleep, patcher
|
||||||
from eventlet.hubs import get_hub, _threadlocal, use_hub
|
from eventlet.hubs import get_hub, _threadlocal, use_hub
|
||||||
from nose.tools import *
|
from nose.tools import *
|
||||||
from tests import mock, LimitedTestCase, skip_unless_zmq
|
from tests import mock, LimitedTestCase, using_pyevent, skip_unless
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
try:
|
||||||
from eventlet.green import zmq
|
from eventlet.green import zmq
|
||||||
|
except ImportError:
|
||||||
|
zmq = {} # for systems lacking zmq, skips tests instead of barfing
|
||||||
|
|
||||||
|
def zmq_supported(_):
|
||||||
|
try:
|
||||||
|
import zmq
|
||||||
|
except ImportError:
|
||||||
|
return False
|
||||||
|
return not using_pyevent(_)
|
||||||
|
|
||||||
class TestUpstreamDownStream(LimitedTestCase):
|
class TestUpstreamDownStream(LimitedTestCase):
|
||||||
|
|
||||||
@@ -39,7 +48,7 @@ got '%s'" % (zmq.ZMQError(errno), zmq.ZMQError(e.errno)))
|
|||||||
else:
|
else:
|
||||||
self.fail("Function did not raise any error")
|
self.fail("Function did not raise any error")
|
||||||
|
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_recv_spawned_before_send_is_non_blocking(self):
|
def test_recv_spawned_before_send_is_non_blocking(self):
|
||||||
req, rep, port = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
|
req, rep, port = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
|
||||||
# req.connect(ipc)
|
# req.connect(ipc)
|
||||||
@@ -57,7 +66,7 @@ got '%s'" % (zmq.ZMQError(errno), zmq.ZMQError(e.errno)))
|
|||||||
done.wait()
|
done.wait()
|
||||||
self.assertEqual(msg['res'], 'test')
|
self.assertEqual(msg['res'], 'test')
|
||||||
|
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_close_socket_raises_enotsup(self):
|
def test_close_socket_raises_enotsup(self):
|
||||||
req, rep, port = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
|
req, rep, port = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
|
||||||
|
|
||||||
@@ -66,7 +75,7 @@ got '%s'" % (zmq.ZMQError(errno), zmq.ZMQError(e.errno)))
|
|||||||
self.assertRaisesErrno(zmq.ENOTSUP, rep.recv)
|
self.assertRaisesErrno(zmq.ENOTSUP, rep.recv)
|
||||||
self.assertRaisesErrno(zmq.ENOTSUP, req.send, 'test')
|
self.assertRaisesErrno(zmq.ENOTSUP, req.send, 'test')
|
||||||
|
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_send_1k_req_rep(self):
|
def test_send_1k_req_rep(self):
|
||||||
req, rep, port = self.create_bound_pair(zmq.REQ, zmq.REP)
|
req, rep, port = self.create_bound_pair(zmq.REQ, zmq.REP)
|
||||||
sleep()
|
sleep()
|
||||||
@@ -93,7 +102,7 @@ got '%s'" % (zmq.ZMQError(errno), zmq.ZMQError(e.errno)))
|
|||||||
final_i = done.wait()
|
final_i = done.wait()
|
||||||
self.assertEqual(final_i, 0)
|
self.assertEqual(final_i, 0)
|
||||||
|
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_send_1k_push_pull(self):
|
def test_send_1k_push_pull(self):
|
||||||
down, up, port = self.create_bound_pair(zmq.PUSH, zmq.PULL)
|
down, up, port = self.create_bound_pair(zmq.PUSH, zmq.PULL)
|
||||||
sleep()
|
sleep()
|
||||||
@@ -117,7 +126,7 @@ got '%s'" % (zmq.ZMQError(errno), zmq.ZMQError(e.errno)))
|
|||||||
final_i = done.wait()
|
final_i = done.wait()
|
||||||
self.assertEqual(final_i, 0)
|
self.assertEqual(final_i, 0)
|
||||||
|
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_send_1k_pub_sub(self):
|
def test_send_1k_pub_sub(self):
|
||||||
pub, sub_all, port = self.create_bound_pair(zmq.PUB, zmq.SUB)
|
pub, sub_all, port = self.create_bound_pair(zmq.PUB, zmq.SUB)
|
||||||
sub1 = self.context.socket(zmq.SUB)
|
sub1 = self.context.socket(zmq.SUB)
|
||||||
@@ -166,7 +175,7 @@ got '%s'" % (zmq.ZMQError(errno), zmq.ZMQError(e.errno)))
|
|||||||
self.assertEqual(sub2_count, 500)
|
self.assertEqual(sub2_count, 500)
|
||||||
self.assertEqual(sub_all_count, 1000)
|
self.assertEqual(sub_all_count, 1000)
|
||||||
|
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_change_subscription(self):
|
def test_change_subscription(self):
|
||||||
pub, sub, port = self.create_bound_pair(zmq.PUB, zmq.SUB)
|
pub, sub, port = self.create_bound_pair(zmq.PUB, zmq.SUB)
|
||||||
sub.setsockopt(zmq.SUBSCRIBE, 'test')
|
sub.setsockopt(zmq.SUBSCRIBE, 'test')
|
||||||
@@ -205,7 +214,7 @@ got '%s'" % (zmq.ZMQError(errno), zmq.ZMQError(e.errno)))
|
|||||||
rx_count = sub_done.wait()
|
rx_count = sub_done.wait()
|
||||||
self.assertEqual(rx_count, 50)
|
self.assertEqual(rx_count, 50)
|
||||||
|
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_recv_multipart_bug68(self):
|
def test_recv_multipart_bug68(self):
|
||||||
req, rep, port = self.create_bound_pair(zmq.REQ, zmq.REP)
|
req, rep, port = self.create_bound_pair(zmq.REQ, zmq.REP)
|
||||||
msg = ['']
|
msg = ['']
|
||||||
@@ -223,7 +232,7 @@ got '%s'" % (zmq.ZMQError(errno), zmq.ZMQError(e.errno)))
|
|||||||
# but it's private __str__ appears to be the way to go
|
# but it's private __str__ appears to be the way to go
|
||||||
self.assertEqual([str(m) for m in recieved_msg], msg2)
|
self.assertEqual([str(m) for m in recieved_msg], msg2)
|
||||||
|
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_recv_noblock_bug76(self):
|
def test_recv_noblock_bug76(self):
|
||||||
req, rep, port = self.create_bound_pair(zmq.REQ, zmq.REP)
|
req, rep, port = self.create_bound_pair(zmq.REQ, zmq.REP)
|
||||||
self.assertRaisesErrno(zmq.EAGAIN, rep.recv, zmq.NOBLOCK)
|
self.assertRaisesErrno(zmq.EAGAIN, rep.recv, zmq.NOBLOCK)
|
||||||
@@ -243,19 +252,19 @@ class TestThreadedContextAccess(TestCase):
|
|||||||
in the same context
|
in the same context
|
||||||
"""
|
"""
|
||||||
if zmq: # don't call decorators if zmq module unavailable
|
if zmq: # don't call decorators if zmq module unavailable
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_context_factory_function(self):
|
def test_context_factory_function(self):
|
||||||
ctx = zmq.Context()
|
ctx = zmq.Context()
|
||||||
self.assertTrue(ctx is not None)
|
self.assertTrue(ctx is not None)
|
||||||
|
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_threadlocal_context(self):
|
def test_threadlocal_context(self):
|
||||||
context = zmq.Context()
|
context = zmq.Context()
|
||||||
self.assertEqual(context, _threadlocal.context)
|
self.assertEqual(context, _threadlocal.context)
|
||||||
next_context = zmq.Context()
|
next_context = zmq.Context()
|
||||||
self.assertTrue(context is next_context)
|
self.assertTrue(context is next_context)
|
||||||
|
|
||||||
@skip_unless_zmq
|
@skip_unless(zmq_supported)
|
||||||
def test_different_context_in_different_thread(self):
|
def test_different_context_in_different_thread(self):
|
||||||
context = zmq.Context()
|
context = zmq.Context()
|
||||||
test_result = []
|
test_result = []
|
||||||
|
Reference in New Issue
Block a user