Commit f28cb38c authored by Denis Bilenko's avatar Denis Bilenko

add GenericGetTestCase

parent b47db2d4
...@@ -95,12 +95,8 @@ class CountingHub(_original_Hub): ...@@ -95,12 +95,8 @@ class CountingHub(_original_Hub):
gevent.hub.Hub = CountingHub gevent.hub.Hub = CountingHub
class GenericWaitTestCase(TestCase):
def wait(self, timeout):
raise NotImplementedError('override me in subclass')
def test_outer_timeout_is_not_lost(self): def test_outer_timeout_is_not_lost(self):
t = gevent.Timeout.start_new(0.01) t = gevent.Timeout.start_new(0.01)
try: try:
self.wait(timeout=0.02) self.wait(timeout=0.02)
...@@ -110,10 +106,54 @@ class GenericWaitTestCase(TestCase): ...@@ -110,10 +106,54 @@ class GenericWaitTestCase(TestCase):
raise AssertionError('must raise Timeout') raise AssertionError('must raise Timeout')
gevent.sleep(0.02) gevent.sleep(0.02)
def test_returns_after_timeout(self):
class GenericWaitTestCase(TestCase):
def wait(self, timeout):
raise NotImplementedError('override me in subclass')
test_outer_timeout_is_not_lost = test_outer_timeout_is_not_lost
def test_returns_none_after_timeout(self):
start = time.time()
result = self.wait(timeout=0.01)
# join and wait simply returns after timeout expires
delay = time.time() - start
assert 0.01 <= delay < 0.01 + 0.01, delay
assert result is None, repr(result)
class GenericGetTestCase(TestCase):
def wait(self, timeout):
raise NotImplementedError('override me in subclass')
test_outer_timeout_is_not_lost = test_outer_timeout_is_not_lost
def test_raises_timeout_number(self):
start = time.time()
self.assertRaises(gevent.Timeout, self.wait, timeout=0.01)
# get raises Timeout after timeout expired
delay = time.time() - start
assert 0.01 <= delay < 0.01 + 0.01, delay
def test_raises_timeout_Timeout(self):
start = time.time() start = time.time()
self.wait(timeout=0.01) t = gevent.Timeout(0.01)
# join simply returns after timeout expires try:
self.wait(timeout=t)
except gevent.Timeout, ex:
assert ex is t, (ex, t)
delay = time.time() - start
assert 0.01 <= delay < 0.01 + 0.01, delay
def test_raises_timeout_Timeout_exc_customized(self):
start = time.time()
error = RuntimeError('expected error')
t = gevent.Timeout(0.01, exception=error)
try:
self.wait(timeout=t)
except RuntimeError, ex:
assert ex is error, (ex, error)
delay = time.time() - start delay = time.time() - start
assert 0.01 <= delay < 0.01 + 0.01, delay assert 0.01 <= delay < 0.01 + 0.01, delay
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment