diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-04-22 00:48:57 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-04-22 00:48:57 +0200 |
commit | c9a2100668259057956caeddda1bcda79f5b52bc (patch) | |
tree | 9bbd47bf93780e1d988de24a145c5f49d7d1f4cc /tests | |
parent | 57493dfab04600a22b6ba9ae37b39b974241f724 (diff) | |
download | paste-git-c9a2100668259057956caeddda1bcda79f5b52bc.tar.gz |
Fix test_exceptions on Python 3
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_exceptions/test_error_middleware.py | 8 | ||||
-rw-r--r-- | tests/test_exceptions/test_formatter.py | 1 | ||||
-rw-r--r-- | tests/test_exceptions/test_httpexceptions.py | 20 |
3 files changed, 15 insertions, 14 deletions
diff --git a/tests/test_exceptions/test_error_middleware.py b/tests/test_exceptions/test_error_middleware.py index d8fd802..95ab177 100644 --- a/tests/test_exceptions/test_error_middleware.py +++ b/tests/test_exceptions/test_error_middleware.py @@ -57,7 +57,7 @@ def after_start_response_app(environ, start_response): def iter_app(environ, start_response): start_response("200 OK", [('Content-type', 'text/plain')]) - return yielder(['this', ' is ', ' a', None]) + return yielder([b'this', b' is ', b' a', None]) def yielder(args): for arg in args: @@ -73,8 +73,10 @@ def test_makes_exception(): res = do_request(bad_app) assert '<html' in res res = strip_html(str(res)) - #print res - assert 'bad_app() takes no arguments (2 given' in res + if six.PY3: + assert 'bad_app() takes 0 positional arguments but 2 were given' in res + else: + assert 'bad_app() takes no arguments (2 given' in res, repr(res) assert 'iterator = application(environ, start_response_wrapper)' in res assert 'paste.lint' in res assert 'paste.exceptions.errormiddleware' in res diff --git a/tests/test_exceptions/test_formatter.py b/tests/test_exceptions/test_formatter.py index 3d5bdad..15656d8 100644 --- a/tests/test_exceptions/test_formatter.py +++ b/tests/test_exceptions/test_formatter.py @@ -153,7 +153,6 @@ def test_hide_after(): raise_error) except: result = format(f) - print(strip_html(result).encode('ascii', 'replace')) assert 'AABB' in result assert 'CCDD' not in result assert 'raise_error' in result diff --git a/tests/test_exceptions/test_httpexceptions.py b/tests/test_exceptions/test_httpexceptions.py index 08e23d4..f740d22 100644 --- a/tests/test_exceptions/test_httpexceptions.py +++ b/tests/test_exceptions/test_httpexceptions.py @@ -10,6 +10,7 @@ from nose.tools import assert_raises from paste.httpexceptions import * from paste.wsgilib import raw_interactive from paste.response import header_value +import six def test_HTTPMove(): @@ -30,8 +31,8 @@ def test_badapp(): start_response("200 OK",[]) raise HTTPBadRequest("Do not do this at home.") newapp = HTTPExceptionHandler(badapp) - assert 'Bad Request' in ''.join(newapp({'HTTP_ACCEPT': 'text/html'}, - (lambda a, b, c=None: None))) + assert b'Bad Request' in b''.join(newapp({'HTTP_ACCEPT': 'text/html'}, + (lambda a, b, c=None: None))) def test_unicode(): """ verify unicode output """ @@ -40,10 +41,10 @@ def test_unicode(): start_response("200 OK",[]) raise HTTPBadRequest(tstr) newapp = HTTPExceptionHandler(badapp) - assert tstr.encode("utf-8") in ''.join(newapp({'HTTP_ACCEPT': + assert tstr.encode("utf-8") in b''.join(newapp({'HTTP_ACCEPT': 'text/html'}, (lambda a, b, c=None: None))) - assert tstr.encode("utf-8") in ''.join(newapp({'HTTP_ACCEPT': + assert tstr.encode("utf-8") in b''.join(newapp({'HTTP_ACCEPT': 'text/plain'}, (lambda a, b, c=None: None))) @@ -67,15 +68,14 @@ def test_redapp(): raise HTTPFound("/bing/foo") app = HTTPExceptionHandler(redapp) result = list(app({'HTTP_ACCEPT': 'text/html'},saveit)) - assert '<a href="/bing/foo">' in result[0] + assert b'<a href="/bing/foo">' in result[0] assert "302 Found" == saved[0][0] - assert "text/html" == header_value(saved[0][1], 'content-type') + if six.PY3: + assert "text/html; charset=utf8" == header_value(saved[0][1], 'content-type') + else: + assert "text/html" == header_value(saved[0][1], 'content-type') assert "/bing/foo" == header_value(saved[0][1],'location') result = list(app({'HTTP_ACCEPT': 'text/plain'},saveit)) - print(result[0] == ( - '302 Found\n' - 'This resource was found at /bing/foo;\n' - 'you should be redirected automatically.\n')) assert "text/plain; charset=utf8" == header_value(saved[1][1],'content-type') assert "/bing/foo" == header_value(saved[1][1],'location') |