diff options
author | Viktors <viktor.sergeyev@gmail.com> | 2014-04-17 21:07:09 +0300 |
---|---|---|
committer | Sergey Shepelev <temotor@gmail.com> | 2014-04-23 12:20:10 +0400 |
commit | 92d12567b20dbe159a1a8a8db4d2cd05d15e6588 (patch) | |
tree | 43ab27f7bea269bff081ec0fbfdeb8e229b46d97 /tests | |
parent | e4dedf73364a8b9e032722e6cf4ee04ad9bdab23 (diff) | |
download | eventlet-92d12567b20dbe159a1a8a8db4d2cd05d15e6588.tar.gz |
python3 compatibility: range, zip, StringIO
Diffstat (limited to 'tests')
-rw-r--r-- | tests/debug_test.py | 25 | ||||
-rw-r--r-- | tests/greenpool_test.py | 2 | ||||
-rw-r--r-- | tests/websocket_new_test.py | 2 | ||||
-rw-r--r-- | tests/wsgi_test.py | 15 |
4 files changed, 18 insertions, 26 deletions
diff --git a/tests/debug_test.py b/tests/debug_test.py index 4edcb0f..c7e6a91 100644 --- a/tests/debug_test.py +++ b/tests/debug_test.py @@ -2,13 +2,10 @@ import sys import eventlet from eventlet import debug +from eventlet.support import six from tests import LimitedTestCase, main, s2b from unittest import TestCase -try: - from cStringIO import StringIO -except ImportError: - from StringIO import StringIO class TestSpew(TestCase): def setUp(self): @@ -33,7 +30,7 @@ class TestSpew(TestCase): self.failUnlessEqual(self.tracer, None) def test_line(self): - sys.stdout = StringIO() + sys.stdout = six.StringIO() s = debug.Spew() f = sys._getframe() s(f, "line", None) @@ -43,7 +40,7 @@ class TestSpew(TestCase): self.failUnless("f=<frame object at" in output) def test_line_nofile(self): - sys.stdout = StringIO() + sys.stdout = six.StringIO() s = debug.Spew() g = globals().copy() del g['__file__'] @@ -56,7 +53,7 @@ class TestSpew(TestCase): def test_line_global(self): global GLOBAL_VAR - sys.stdout = StringIO() + sys.stdout = six.StringIO() GLOBAL_VAR = debug.Spew() f = sys._getframe() GLOBAL_VAR(f, "line", None) @@ -69,7 +66,7 @@ class TestSpew(TestCase): del GLOBAL_VAR def test_line_novalue(self): - sys.stdout = StringIO() + sys.stdout = six.StringIO() s = debug.Spew(show_values=False) f = sys._getframe() s(f, "line", None) @@ -79,7 +76,7 @@ class TestSpew(TestCase): self.failIf("f=<frame object at" in output) def test_line_nooutput(self): - sys.stdout = StringIO() + sys.stdout = six.StringIO() s = debug.Spew(trace_names=['foo']) f = sys._getframe() s(f, "line", None) @@ -106,16 +103,16 @@ class TestDebug(LimitedTestCase): server = eventlet.listen(('0.0.0.0', 0)) client = eventlet.connect(('127.0.0.1', server.getsockname()[1])) client_2, addr = server.accept() - + def hurl(s): s.recv(1) {}[1] # keyerror - fake = StringIO() + fake = six.StringIO() orig = sys.stderr sys.stderr = fake try: - gt = eventlet.spawn(hurl, client_2) + gt = eventlet.spawn(hurl, client_2) eventlet.sleep(0) client.send(s2b(' ')) eventlet.sleep(0) @@ -127,8 +124,8 @@ class TestDebug(LimitedTestCase): self.assertRaises(KeyError, gt.wait) debug.hub_exceptions(False) # look for the KeyError exception in the traceback - self.assert_('KeyError: 1' in fake.getvalue(), + self.assert_('KeyError: 1' in fake.getvalue(), "Traceback not in:\n" + fake.getvalue()) - + if __name__ == "__main__": main() diff --git a/tests/greenpool_test.py b/tests/greenpool_test.py index 4c7cdb8..efdc5ed 100644 --- a/tests/greenpool_test.py +++ b/tests/greenpool_test.py @@ -274,7 +274,7 @@ class GreenPool(tests.LimitedTestCase): def test_imap_multi_args(self): p = greenpool.GreenPool(4) result_list = list(p.imap(passthru2, range(10), range(10, 20))) - self.assertEquals(result_list, list(itertools.izip(range(10), range(10,20)))) + self.assertEquals(result_list, list(zip(range(10), range(10,20)))) def test_imap_raises(self): # testing the case where the function raises an exception; diff --git a/tests/websocket_new_test.py b/tests/websocket_new_test.py index 629b28c..55569a4 100644 --- a/tests/websocket_new_test.py +++ b/tests/websocket_new_test.py @@ -19,7 +19,7 @@ def handle(ws): break ws.send(m) elif ws.path == '/range': - for i in xrange(10): + for i in range(10): ws.send("msg %d" % i) eventlet.sleep(0.01) elif ws.path == '/error': diff --git a/tests/wsgi_test.py b/tests/wsgi_test.py index 9171acd..b4401f3 100644 --- a/tests/wsgi_test.py +++ b/tests/wsgi_test.py @@ -14,7 +14,7 @@ from eventlet import event from eventlet import hubs from eventlet.green import socket as greensocket from eventlet import wsgi -from eventlet.support import get_errno +from eventlet.support import get_errno, six from tests import find_command, run_python @@ -23,11 +23,6 @@ httplib = eventlet.import_patched('httplib') certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt') private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key') -try: - from cStringIO import StringIO -except ImportError: - from StringIO import StringIO - HttpReadResult = collections.namedtuple( 'HttpReadResult', @@ -205,7 +200,7 @@ def read_http(sock): class _TestBase(LimitedTestCase): def setUp(self): super(_TestBase, self).setUp() - self.logfile = StringIO() + self.logfile = six.StringIO() self.site = Site() self.killer = None self.set_site() @@ -635,7 +630,7 @@ class TestHttpd(_TestBase): self.assert_('1.2.3.4,5.6.7.8,127.0.0.1' in self.logfile.getvalue()) # turning off the option should work too - self.logfile = StringIO() + self.logfile = six.StringIO() self.spawn_server(log_x_forwarded_for=False) sock = eventlet.connect(('localhost', self.port)) @@ -777,7 +772,7 @@ class TestHttpd(_TestBase): listener = greensocket.socket() listener.bind(('localhost', 0)) # NOT calling listen, to trigger the error - self.logfile = StringIO() + self.logfile = six.StringIO() self.spawn_server(sock=listener) old_stderr = sys.stderr try: @@ -1133,7 +1128,7 @@ class TestHttpd(_TestBase): sock = eventlet.listen(('::1', 0), family=socket.AF_INET6) except (socket.gaierror, socket.error): # probably no ipv6 return - log = StringIO() + log = six.StringIO() # first thing the server does is try to log the IP it's bound to def run_server(): |