diff options
| author | Jakub Stasiak <jakub@stasiak.at> | 2015-02-12 00:30:28 +0100 |
|---|---|---|
| committer | Jakub Stasiak <jakub@stasiak.at> | 2015-02-13 02:26:45 +0100 |
| commit | ea14cd5ee84a2d0c5ba205c9dcc34198a80e9af1 (patch) | |
| tree | f2de48622506d3a14e06ca1c9d80e1be039158d3 /tests | |
| parent | 4e1804af31c2ceeed5ff4aa29eab9f1597e7092e (diff) | |
| download | eventlet-test2.tar.gz | |
Python 3 compat: Fix all Travis test failurestest2
This patch consists of the following changes:
* Splitting eventlet.greenio into base, py2 and py3 parts
(eventlet.greenio should be exporing the same public objects). This
change is motivated by the size and the number of conditions present
in the current greenio code
* Connected to the first point: implementing almost completely new
GreenPipe callable utilizing parts of old GreenPipe code but dropping
_fileobject/SocketIO inheritance in favour of io.FileIO and making use
of patched _pyio.open function which wraps raw file-like object in
various readers and writers (they take care of the buffering,
encoding/decoding etc.)
* Implementing (from scratch or updating existing versions)
green versions of the following modules:
* http.* (needed by Python 3's urllib)
* selectors (Python >= 3.4, used in subprocess module)
* urllib.* (needed by various tests and we were already exposing green
urllib)
* Modifying some tests to make tests pass, which includes:
* unicode/bytestring issues
* modifying wsgi_test_conntimeout.py to not pass bufsize and close
arguments to ExplodingSocketFile - on Python 3 it inherits from
SocketIO, which doesn't deal with buffering at all as far as I can
see
* Random cleaning up and reorganizing
* Requiring Python 3.x tests to pass for the whole build to pass
Known issues:
* code repetition
* naming inconsistencies
* possibly breaking some external code using private eventlet.greenio attributes
Closes https://github.com/eventlet/eventlet/issues/108
Affects https://github.com/eventlet/eventlet/issues/6 (I'd call it an
experimental support)
Should help for https://github.com/eventlet/eventlet/issues/145
Should help for https://github.com/eventlet/eventlet/issues/157
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 | 32 | ||||
| -rw-r--r-- | tests/wsgi_test_conntimeout.py | 4 |
5 files changed, 52 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..8587803 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,9 @@ class TestChunkedInput(_TestBase): fd = self.connect() fd.sendall(req.encode()) fd.close() - eventlet.sleep(0.0) + + # TODO changed from 0 to make Python 3 tests pass, not sure if ok + eventlet.sleep(0.01) 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): |
