Fix zmq._QueueLock test in Python2.6 - TestCase.assertRaises is not context manager yet
This commit is contained in:
@@ -13,6 +13,11 @@ slurp_properties(__zmq__, globals(), ignore=__patched__)
|
||||
|
||||
from collections import deque
|
||||
|
||||
|
||||
class LockReleaseError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class _QueueLock(object):
|
||||
"""A Lock that can be acquired by at most one thread. Any other
|
||||
thread calling acquire will be blocked in a queue. When release
|
||||
@@ -50,7 +55,7 @@ class _QueueLock(object):
|
||||
|
||||
def release(self):
|
||||
if self._count <= 0:
|
||||
raise Exception("Cannot release unacquired lock")
|
||||
raise LockReleaseError("Cannot release unacquired lock")
|
||||
|
||||
self._count -= 1
|
||||
if self._count == 0:
|
||||
@@ -59,6 +64,7 @@ class _QueueLock(object):
|
||||
# wake next
|
||||
self._hub.schedule_call_global(0, self._waiters[0].switch)
|
||||
|
||||
|
||||
class _BlockedThread(object):
|
||||
"""Is either empty, or represents a single blocked thread that
|
||||
blocked itself by calling the block() method. The thread can be
|
||||
|
@@ -12,6 +12,7 @@ try:
|
||||
except ImportError:
|
||||
zmq = {} # for systems lacking zmq, skips tests instead of barfing
|
||||
|
||||
|
||||
def zmq_supported(_):
|
||||
try:
|
||||
import zmq
|
||||
@@ -19,22 +20,24 @@ def zmq_supported(_):
|
||||
return False
|
||||
return not using_pyevent(_)
|
||||
|
||||
class TestUpstreamDownStream(LimitedTestCase):
|
||||
|
||||
class TestUpstreamDownStream(LimitedTestCase):
|
||||
@skip_unless(zmq_supported)
|
||||
def setUp(self):
|
||||
super(TestUpstreamDownStream, self).setUp()
|
||||
self.context = zmq.Context()
|
||||
self.sockets = []
|
||||
|
||||
@skip_unless(zmq_supported)
|
||||
def tearDown(self):
|
||||
self.clear_up_sockets()
|
||||
super(TestUpstreamDownStream, self).tearDown()
|
||||
|
||||
def create_bound_pair(self, type1, type2, interface='tcp://127.0.0.1'):
|
||||
"""Create a bound socket pair using a random port."""
|
||||
self.context = context = zmq.Context()
|
||||
s1 = context.socket(type1)
|
||||
s1 = self.context.socket(type1)
|
||||
port = s1.bind_to_random_port(interface)
|
||||
s2 = context.socket(type2)
|
||||
s2 = self.context.socket(type2)
|
||||
s2.connect('%s:%s' % (interface, port))
|
||||
self.sockets.append(s1)
|
||||
self.sockets.append(s2)
|
||||
@@ -436,14 +439,12 @@ class TestQueueLock(LimitedTestCase):
|
||||
def test_errors(self):
|
||||
q = zmq._QueueLock()
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
q.release()
|
||||
self.assertRaises(zmq.LockReleaseError, q.release)
|
||||
|
||||
q.acquire()
|
||||
q.release()
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
q.release()
|
||||
self.assertRaises(zmq.LockReleaseError, q.release)
|
||||
|
||||
@skip_unless(zmq_supported)
|
||||
def test_nested_acquire(self):
|
||||
@@ -471,6 +472,7 @@ class TestQueueLock(LimitedTestCase):
|
||||
s.acquire()
|
||||
self.assertEquals(results, [1])
|
||||
|
||||
|
||||
class TestBlockedThread(LimitedTestCase):
|
||||
@skip_unless(zmq_supported)
|
||||
def test_block(self):
|
||||
|
Reference in New Issue
Block a user