Commit 21f96760 authored by Denis Bilenko's avatar Denis Bilenko

use greentest instead of unittest

in 5 more tests; this ensures more checks, esp. in debug mode
parent e23fb41a
import unittest import greentest
from gevent import core from gevent import core
class Test(unittest.TestCase): class Test(greentest.TestCase):
def test_types(self): def test_types(self):
loop = core.loop() loop = core.loop()
...@@ -43,8 +43,11 @@ class Test(unittest.TestCase): ...@@ -43,8 +43,11 @@ class Test(unittest.TestCase):
self.assertEqual(io.args, (1, 2, 3)) self.assertEqual(io.args, (1, 2, 3))
# None also works, means empty tuple # None also works, means empty tuple
io.args = None io.args = None
start = core.time()
loop.run() loop.run()
took = core.time() - start
self.assertEqual(lst, [()]) self.assertEqual(lst, [()])
assert took < 1, took
io.start(reset, io, lst) io.start(reset, io, lst)
del io del io
...@@ -59,4 +62,4 @@ def reset(watcher, lst): ...@@ -59,4 +62,4 @@ def reset(watcher, lst):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() greentest.main()
import unittest import greentest
from copy import copy from copy import copy
# Comment the line below to see that the standard thread.local is working correct # Comment the line below to see that the standard thread.local is working correct
from gevent import monkey; monkey.patch_all() from gevent import monkey; monkey.patch_all()
...@@ -22,7 +22,7 @@ class Obj(object): ...@@ -22,7 +22,7 @@ class Obj(object):
pass pass
class GeventLocalTestCase(unittest.TestCase): class GeventLocalTestCase(greentest.TestCase):
def test_copy(self): def test_copy(self):
a = A(Obj()) a = A(Obj())
...@@ -59,4 +59,4 @@ class GeventLocalTestCase(unittest.TestCase): ...@@ -59,4 +59,4 @@ class GeventLocalTestCase(unittest.TestCase):
self.assertNotEqual(a.path, b.path, 'The values in the two objects must be different') self.assertNotEqual(a.path, b.path, 'The values in the two objects must be different')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() greentest.main()
import unittest import greentest
import gevent import gevent
from gevent import pywsgi from gevent import pywsgi
import test__server import test__server
...@@ -81,4 +81,4 @@ test__server.Settings = Settings ...@@ -81,4 +81,4 @@ test__server.Settings = Settings
del TestNoneSpawn del TestNoneSpawn
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() greentest.main()
#!/usr/bin/python #!/usr/bin/python
from gevent import monkey; monkey.patch_all() from gevent import monkey; monkey.patch_all()
import sys import sys
import unittest import greentest
try: try:
import httplib import httplib
except ImportError: except ImportError:
...@@ -12,7 +12,7 @@ if not hasattr(socket, 'ssl'): ...@@ -12,7 +12,7 @@ if not hasattr(socket, 'ssl'):
sys.exit(0) sys.exit(0)
class AmazonHTTPSTests(unittest.TestCase): class AmazonHTTPSTests(greentest.TestCase):
def test_amazon_response(self): def test_amazon_response(self):
conn = httplib.HTTPSConnection('sdb.amazonaws.com') conn = httplib.HTTPSConnection('sdb.amazonaws.com')
...@@ -29,4 +29,4 @@ class AmazonHTTPSTests(unittest.TestCase): ...@@ -29,4 +29,4 @@ class AmazonHTTPSTests(unittest.TestCase):
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() greentest.main()
import sys import sys
import gevent import gevent
from gevent import socket from gevent import socket
import unittest import greentest
class Test(unittest.TestCase): class Test(greentest.TestCase):
def setUp(self): def start(self):
self.server = socket.socket() self.server = socket.socket()
self.server.bind(('127.0.0.1', 0)) self.server.bind(('127.0.0.1', 0))
self.server.listen(1) self.server.listen(1)
self.server_port = self.server.getsockname()[1] self.server_port = self.server.getsockname()[1]
self.acceptor = gevent.spawn(self.server.accept) self.acceptor = gevent.spawn(self.server.accept)
def tearDown(self): def stop(self):
self.server.close() self.server.close()
self.acceptor.kill() self.acceptor.kill()
del self.acceptor del self.acceptor
del self.server del self.server
def test(self): def test(self):
sock = socket.socket() self.start()
sock.connect(('127.0.0.1', self.server_port))
try: try:
sock.settimeout(0.1) sock = socket.socket()
sock.connect(('127.0.0.1', self.server_port))
try: try:
result = sock.recv(1024) sock.settimeout(0.1)
raise AssertionError('Expected timeout to be raised, instead recv() returned %r' % (result, )) try:
except socket.error: result = sock.recv(1024)
ex = sys.exc_info()[1] raise AssertionError('Expected timeout to be raised, instead recv() returned %r' % (result, ))
self.assertEqual(ex.args, ('timed out',)) except socket.error:
self.assertEqual(str(ex), 'timed out') ex = sys.exc_info()[1]
self.assertEqual(ex[0], 'timed out') self.assertEqual(ex.args, ('timed out',))
self.assertEqual(str(ex), 'timed out')
self.assertEqual(ex[0], 'timed out')
finally:
sock.close()
finally: finally:
sock.close() self.stop()
if __name__ == '__main__': if __name__ == '__main__':
unittest.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