Commit e27075d0 authored by Denis Bilenko's avatar Denis Bilenko

Add a bunch of tests for Waiter

parent feed3312
......@@ -25,6 +25,7 @@ import time
import gevent
from gevent import core
from gevent import socket
from gevent.hub import Waiter
import signal
DELAY = 0.1
......@@ -142,6 +143,37 @@ class TestSignal(greentest.TestCase):
assert str(ex) == 'TestSignal', ex
class TestWaiter(greentest.GenericWaitTestCase):
def setUp(self):
super(TestWaiter, self).setUp()
self.waiter = Waiter()
def wait(self, timeout):
evt = core.timer(timeout, self.waiter.switch, None)
try:
return self.waiter.get()
finally:
evt.cancel()
def test(self):
waiter = self.waiter
self.assertEqual(str(waiter), '<Waiter greenlet=None>')
waiter.switch(25)
self.assertEqual(str(waiter), '<Waiter greenlet=None value=25>')
self.assertEqual(waiter.get(), 25)
waiter = Waiter()
waiter.throw(ZeroDivisionError)
self.assertEqual(str(waiter), "<Waiter greenlet=None exc_info=(<type 'exceptions.ZeroDivisionError'>,)>")
self.assertRaises(ZeroDivisionError, waiter.get)
waiter = Waiter()
gevent.spawn(waiter.get)
gevent.sleep(0)
assert str(waiter).startswith('<Waiter greenlet=<Greenlet at 0x'), str(waiter)
if __name__=='__main__':
greentest.main()
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