diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-04-21 16:32:40 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-04-21 16:32:40 +0200 |
commit | 0c5b1445cb75e87e74ecc2eb513f1dad03a32cbf (patch) | |
tree | 1bc9a2088b991f5a07d35065bbdb6b278f5cda77 /tests | |
parent | 978eddf9923b2aa18898efe273c7fc80347e758c (diff) | |
download | paste-git-0c5b1445cb75e87e74ecc2eb513f1dad03a32cbf.tar.gz |
Fix test_registry on Python 3
HTTP body must be bytes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_registry.py | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/tests/test_registry.py b/tests/test_registry.py index af3a389..23cd9b6 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -15,19 +15,25 @@ def simpleapp(environ, start_response): status = '200 OK' response_headers = [('Content-type','text/plain')] start_response(status, response_headers) - return ['Hello world!\n'] + return [b'Hello world!\n'] def simpleapp_withregistry(environ, start_response): status = '200 OK' response_headers = [('Content-type','text/plain')] start_response(status, response_headers) - return ['Hello world!Value is %s\n' % regobj.keys()] + body = 'Hello world!Value is %s\n' % regobj.keys() + if six.PY3: + body = body.encode('utf8') + return [body] def simpleapp_withregistry_default(environ, start_response): status = '200 OK' response_headers = [('Content-type','text/plain')] start_response(status, response_headers) - return ['Hello world!Value is %s\n' % secondobj] + body = 'Hello world!Value is %s\n' % secondobj + if six.PY3: + body = body.encode('utf8') + return [body] class RegistryUsingApp(object): @@ -44,7 +50,10 @@ class RegistryUsingApp(object): status = '200 OK' response_headers = [('Content-type','text/plain')] start_response(status, response_headers) - return ['Hello world!\nThe variable is %s' % str(regobj)] + body = 'Hello world!\nThe variable is %s' % str(regobj) + if six.PY3: + body = body.encode('utf8') + return [body] class RegistryUsingIteratorApp(object): def __init__(self, var, value): @@ -57,7 +66,10 @@ class RegistryUsingIteratorApp(object): status = '200 OK' response_headers = [('Content-type','text/plain')] start_response(status, response_headers) - return iter(['Hello world!\nThe variable is %s' % str(regobj)]) + body = 'Hello world!\nThe variable is %s' % str(regobj) + if six.PY3: + body = body.encode('utf8') + return iter([body]) class RegistryMiddleMan(object): def __init__(self, app, var, value, depth): @@ -69,8 +81,11 @@ class RegistryMiddleMan(object): def __call__(self, environ, start_response): if 'paste.registry' in environ: environ['paste.registry'].register(self.var, self.value) - app_response = ['\nInserted by middleware!\nInsertValue at depth \ - %s is %s' % (self.depth, str(regobj))] + line = ('\nInserted by middleware!\nInsertValue at depth %s is %s' + % (self.depth, str(regobj))) + if six.PY3: + line = line.encode('utf8') + app_response = [line] app_iter = None app_iter = self.app(environ, start_response) if type(app_iter) in (list, tuple): @@ -82,8 +97,11 @@ class RegistryMiddleMan(object): if hasattr(app_iter, 'close'): app_iter.close() app_response.extend(response) - app_response.extend(['\nAppended by middleware!\nAppendValue at \ - depth %s is %s' % (self.depth, str(regobj))]) + line = ('\nAppended by middleware!\nAppendValue at \ + depth %s is %s' % (self.depth, str(regobj))) + if six.PY3: + line = line.encode('utf8') + app_response.append(line) return app_response |