diff options
| author | Jakub Stasiak <jakub@stasiak.at> | 2015-02-12 00:30:28 +0100 |
|---|---|---|
| committer | Jakub Stasiak <jakub@stasiak.at> | 2015-02-13 08:52:54 +0100 |
| commit | 449c90a50965af369c91c0175b19de83f0d3a030 (patch) | |
| tree | dc40851b7a10fbb57cbb361b741a18399d0c3c2c /tests/wsgi_test.py | |
| parent | 4e1804af31c2ceeed5ff4aa29eab9f1597e7092e (diff) | |
| download | eventlet-449c90a50965af369c91c0175b19de83f0d3a030.tar.gz | |
Python 3 compat: Fix all Travis test failuresdev
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/wsgi_test.py')
| -rw-r--r-- | tests/wsgi_test.py | 39 |
1 files changed, 30 insertions, 9 deletions
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) |
