diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/greenio_test.py | 12 | ||||
| -rw-r--r-- | tests/patcher_test.py | 14 | ||||
| -rw-r--r-- | tests/test__greenness.py | 15 | ||||
| -rw-r--r-- | tests/wsgi_test.py | 39 | ||||
| -rw-r--r-- | tests/wsgi_test_conntimeout.py | 4 |
5 files changed, 59 insertions, 25 deletions
diff --git a/tests/greenio_test.py b/tests/greenio_test.py index ffdc534..fa7c160 100644 --- a/tests/greenio_test.py +++ b/tests/greenio_test.py @@ -667,8 +667,8 @@ class TestGreenPipe(LimitedTestCase): def test_pipe(self): r, w = os.pipe() - rf = greenio.GreenPipe(r, 'r') - wf = greenio.GreenPipe(w, 'w', 0) + rf = greenio.GreenPipe(r, 'rb') + wf = greenio.GreenPipe(w, 'wb', 0) def sender(f, content): for ch in map(six.int2byte, six.iterbytes(content)): @@ -690,8 +690,8 @@ class TestGreenPipe(LimitedTestCase): # also ensures that readline() terminates on '\n' and '\r\n' r, w = os.pipe() - r = greenio.GreenPipe(r) - w = greenio.GreenPipe(w, 'w') + r = greenio.GreenPipe(r, 'rb') + w = greenio.GreenPipe(w, 'wb') def writer(): eventlet.sleep(.1) @@ -717,8 +717,8 @@ class TestGreenPipe(LimitedTestCase): def test_pipe_writes_large_messages(self): r, w = os.pipe() - r = greenio.GreenPipe(r) - w = greenio.GreenPipe(w, 'w') + r = greenio.GreenPipe(r, 'rb') + w = greenio.GreenPipe(w, 'wb') large_message = b"".join([1024 * six.int2byte(i) for i in range(65)]) diff --git a/tests/patcher_test.py b/tests/patcher_test.py index 5c9076f..3ace281 100644 --- a/tests/patcher_test.py +++ b/tests/patcher_test.py @@ -9,10 +9,7 @@ from tests import LimitedTestCase, main, run_python, skip_with_pyevent base_module_contents = """ import socket -try: - import urllib.request as urllib -except ImportError: - import urllib +import urllib print("base {0} {1}".format(socket, urllib)) """ @@ -86,7 +83,14 @@ class ImportPatched(ProcessBase): assert 'eventlet.green.httplib' not in lines[2], repr(output) def test_import_patched_defaults(self): - self.write_to_tempfile("base", base_module_contents) + self.write_to_tempfile("base", """ +import socket +try: + import urllib.request as urllib +except ImportError: + import urllib +print("base {0} {1}".format(socket, urllib))""") + new_mod = """ from eventlet import patcher base = patcher.import_patched('base') diff --git a/tests/test__greenness.py b/tests/test__greenness.py index 7d90890..a594b4d 100644 --- a/tests/test__greenness.py +++ b/tests/test__greenness.py @@ -4,8 +4,15 @@ If either operation blocked the whole script would block and timeout. """ import unittest -from eventlet.green import urllib2, BaseHTTPServer +from eventlet.green import BaseHTTPServer from eventlet import spawn, kill +from eventlet.support import six + +if six.PY2: + from eventlet.green.urllib2 import HTTPError, urlopen +else: + from eventlet.green.urllib.request import urlopen + from eventlet.green.urllib.error import HTTPError class QuietHandler(BaseHTTPServer.BaseHTTPRequestHandler): @@ -40,12 +47,12 @@ class TestGreenness(unittest.TestCase): self.server.server_close() kill(self.gthread) - def test_urllib2(self): + def test_urllib(self): self.assertEqual(self.server.request_count, 0) try: - urllib2.urlopen('http://127.0.0.1:%s' % self.port) + urlopen('http://127.0.0.1:%s' % self.port) assert False, 'should not get there' - except urllib2.HTTPError as ex: + except HTTPError as ex: assert ex.code == 501, repr(ex) self.assertEqual(self.server.request_count, 1) diff --git a/tests/wsgi_test.py b/tests/wsgi_test.py index 179881d..053122e 100644 --- a/tests/wsgi_test.py +++ b/tests/wsgi_test.py @@ -1330,11 +1330,24 @@ class TestHttpd(_TestBase): self.assertEqual(result.headers_lower['connection'], 'close') assert 'transfer-encoding' not in result.headers_lower - def test_unicode_raises_error(self): + def test_unicode_with_only_ascii_characters_works(self): def wsgi_app(environ, start_response): start_response("200 OK", []) - yield u"oh hai" - yield u"non-encodable unicode: \u0230" + yield b"oh hai, " + yield u"xxx" + self.site.application = wsgi_app + sock = eventlet.connect(('localhost', self.port)) + fd = sock.makefile('rwb') + fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n') + fd.flush() + result = read_http(sock) + assert b'xxx' in result.body + + def test_unicode_with_nonascii_characters_raises_error(self): + def wsgi_app(environ, start_response): + start_response("200 OK", []) + yield b"oh hai, " + yield u"xxx \u0230" self.site.application = wsgi_app sock = eventlet.connect(('localhost', self.port)) fd = sock.makefile('rwb') @@ -1343,7 +1356,6 @@ class TestHttpd(_TestBase): result = read_http(sock) self.assertEqual(result.status, 'HTTP/1.1 500 Internal Server Error') self.assertEqual(result.headers_lower['connection'], 'close') - assert b'unicode' in result.body def test_path_info_decoding(self): def wsgi_app(environ, start_response): @@ -1454,11 +1466,11 @@ class TestHttpd(_TestBase): # (if eventlet stops using file.readline() to read HTTP headers, # for instance) for runlog in sections[1:]: - debug = False if "debug set to: False" in runlog else True + debug = False if b"debug set to: False" in runlog else True if debug: - self.assertTrue("timed out" in runlog) - self.assertTrue("BOOM" in runlog) - self.assertFalse("Traceback" in runlog) + self.assertTrue(b"timed out" in runlog) + self.assertTrue(b"BOOM" in runlog) + self.assertFalse(b"Traceback" in runlog) def test_server_socket_timeout(self): self.spawn_server(socket_timeout=0.1) @@ -1743,7 +1755,16 @@ class TestChunkedInput(_TestBase): fd = self.connect() fd.sendall(req.encode()) fd.close() - eventlet.sleep(0.0) + + eventlet.sleep(0) + + # This is needed because on Python 3 GreenSocket.recv_into is called + # rather than recv; recv_into right now (git 5ec3a3c) trampolines to + # the hub *before* attempting to read anything from a file descriptor + # therefore we need one extra context switch to let it notice closed + # socket, die and leave the hub empty + if six.PY3: + eventlet.sleep(0) finally: signal.alarm(0) signal.signal(signal.SIGALRM, signal.SIG_DFL) diff --git a/tests/wsgi_test_conntimeout.py b/tests/wsgi_test_conntimeout.py index d925a04..01ecc0e 100644 --- a/tests/wsgi_test_conntimeout.py +++ b/tests/wsgi_test_conntimeout.py @@ -25,6 +25,7 @@ connection makefile() file objects - ExplodingSocketFile <-- these raise from __future__ import print_function import eventlet +from eventlet.support import six import socket import sys @@ -96,7 +97,8 @@ class ExplodingConnectionWrap(object): class ExplodingSocketFile(eventlet.greenio._fileobject): def __init__(self, sock, mode='rb', bufsize=-1, close=False): - super(self.__class__, self).__init__(sock, mode, bufsize, close) + args = [bufsize, close] if six.PY2 else [] + super(self.__class__, self).__init__(sock, mode, *args) self.armed = False def arm(self): |
