diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2021-04-05 14:03:05 +0100 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2021-04-05 14:03:05 +0100 |
commit | 6c97a1a069f0ae8cf683c8364fb7f9dabc5e89cb (patch) | |
tree | a7eab02b6fc63ff8d1a1329a090162715371aa62 /test/python | |
parent | 46d8567dd7c2a9af025f1de13084a9efd7118e20 (diff) | |
download | unit-6c97a1a069f0ae8cf683c8364fb7f9dabc5e89cb.tar.gz unit-6c97a1a069f0ae8cf683c8364fb7f9dabc5e89cb.tar.bz2 |
Tests: style.
Diffstat (limited to 'test/python')
29 files changed, 218 insertions, 181 deletions
diff --git a/test/python/atexit/wsgi.py b/test/python/atexit/wsgi.py index a5a9918d..b64b8477 100644 --- a/test/python/atexit/wsgi.py +++ b/test/python/atexit/wsgi.py @@ -1,5 +1,6 @@ import atexit + def application(environ, start_response): def at_exit(): environ['wsgi.errors'].write('At exit called.\n') diff --git a/test/python/body_io/wsgi.py b/test/python/body_io/wsgi.py index 14303b5f..58ce76a4 100644 --- a/test/python/body_io/wsgi.py +++ b/test/python/body_io/wsgi.py @@ -1,5 +1,6 @@ import io + def application(env, start_response): start_response('200', [('Content-Length', '10')]) f = io.BytesIO(b'0123456789') diff --git a/test/python/callable/wsgi.py b/test/python/callable/wsgi.py index 365f82fa..374ecb28 100644 --- a/test/python/callable/wsgi.py +++ b/test/python/callable/wsgi.py @@ -2,6 +2,7 @@ def application(env, start_response): start_response('204', [('Content-Length', '0')]) return [] + def app(env, start_response): start_response('200', [('Content-Length', '0')]) return [] diff --git a/test/python/ctx_iter_atexit/wsgi.py b/test/python/ctx_iter_atexit/wsgi.py index d0b33daa..b2f12c35 100644 --- a/test/python/ctx_iter_atexit/wsgi.py +++ b/test/python/ctx_iter_atexit/wsgi.py @@ -1,5 +1,6 @@ import atexit + class application: def __init__(self, environ, start_response): self.environ = environ @@ -11,13 +12,14 @@ class application: content_length = int(self.environ.get('CONTENT_LENGTH', 0)) body = bytes(self.environ['wsgi.input'].read(content_length)) - self.start('200', [ - ('Content-Type', self.environ.get('CONTENT_TYPE')), - ('Content-Length', str(len(body))) - ]) + self.start( + '200', + [ + ('Content-Type', self.environ.get('CONTENT_TYPE')), + ('Content-Length', str(len(body))), + ], + ) yield body def _atexit(self): - self.start('200', [ - ('Content-Length', '0') - ]) + self.start('200', [('Content-Length', '0')]) diff --git a/test/python/custom_header/wsgi.py b/test/python/custom_header/wsgi.py index 44f145d1..44fc2af5 100644 --- a/test/python/custom_header/wsgi.py +++ b/test/python/custom_header/wsgi.py @@ -1,7 +1,10 @@ def application(environ, start_response): - start_response('200', [ - ('Content-Length', '0'), - ('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')) - ]) + start_response( + '200', + [ + ('Content-Length', '0'), + ('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')), + ], + ) return [] diff --git a/test/python/delayed/asgi.py b/test/python/delayed/asgi.py index d5cad929..1cb15a92 100644 --- a/test/python/delayed/asgi.py +++ b/test/python/delayed/asgi.py @@ -1,5 +1,6 @@ import asyncio + async def application(scope, receive, send): assert scope['type'] == 'http' @@ -28,13 +29,13 @@ async def application(scope, receive, send): loop.call_later(n, future.set_result, None) await future - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - (b'content-length', str(len(body)).encode()), - ] - }) + await send( + { + 'type': 'http.response.start', + 'status': 200, + 'headers': [(b'content-length', str(len(body)).encode()),], + } + ) if not body: await sleep(delay) @@ -42,10 +43,12 @@ async def application(scope, receive, send): step = int(len(body) / parts) for i in range(0, len(body), step): - await send({ - 'type': 'http.response.body', - 'body': body[i : i + step], - 'more_body': True, - }) + await send( + { + 'type': 'http.response.body', + 'body': body[i : i + step], + 'more_body': True, + } + ) await sleep(delay) diff --git a/test/python/empty/asgi.py b/test/python/empty/asgi.py index 58b7c1f2..14a40629 100644 --- a/test/python/empty/asgi.py +++ b/test/python/empty/asgi.py @@ -1,10 +1,10 @@ async def application(scope, receive, send): assert scope['type'] == 'http' - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - (b'content-length', b'0'), - ] - }) + await send( + { + 'type': 'http.response.start', + 'status': 200, + 'headers': [(b'content-length', b'0')], + } + ) diff --git a/test/python/environment/wsgi.py b/test/python/environment/wsgi.py index fa3a1d2b..d1564f29 100644 --- a/test/python/environment/wsgi.py +++ b/test/python/environment/wsgi.py @@ -1,5 +1,6 @@ import os + def application(env, start_response): body = '' vars = env.get('HTTP_X_VARIABLES').split(',') diff --git a/test/python/header_fields/wsgi.py b/test/python/header_fields/wsgi.py index bd1ba0e2..41144528 100644 --- a/test/python/header_fields/wsgi.py +++ b/test/python/header_fields/wsgi.py @@ -2,8 +2,7 @@ def application(environ, start_response): h = (k for k, v in environ.items() if k.startswith('HTTP_')) - start_response('200', [ - ('Content-Length', '0'), - ('All-Headers', ','.join(h)) - ]) + start_response( + '200', [('Content-Length', '0'), ('All-Headers', ','.join(h))] + ) return [] diff --git a/test/python/host/wsgi.py b/test/python/host/wsgi.py index db7de306..0a08bc36 100644 --- a/test/python/host/wsgi.py +++ b/test/python/host/wsgi.py @@ -1,7 +1,10 @@ def application(env, start_response): - start_response('200', [ - ('Content-Length', '0'), - ('X-Server-Name', env.get('SERVER_NAME')), - ('X-Http-Host', str(env.get('HTTP_HOST'))) - ]) + start_response( + '200', + [ + ('Content-Length', '0'), + ('X-Server-Name', env.get('SERVER_NAME')), + ('X-Http-Host', str(env.get('HTTP_HOST'))), + ], + ) return [] diff --git a/test/python/iter_exception/wsgi.py b/test/python/iter_exception/wsgi.py index 66a09af7..2779a845 100644 --- a/test/python/iter_exception/wsgi.py +++ b/test/python/iter_exception/wsgi.py @@ -8,7 +8,9 @@ class application: def __iter__(self): self.__i = 0 self._skip_level = int(self.environ.get('HTTP_X_SKIP', 0)) - self._not_skip_close = int(self.environ.get('HTTP_X_NOT_SKIP_CLOSE', 0)) + self._not_skip_close = int( + self.environ.get('HTTP_X_NOT_SKIP_CLOSE', 0) + ) self._is_chunked = self.environ.get('HTTP_X_CHUNKED') headers = [(('Content-Length', '10'))] diff --git a/test/python/legacy/asgi.py b/test/python/legacy/asgi.py index f065d026..1d45cc4f 100644 --- a/test/python/legacy/asgi.py +++ b/test/python/legacy/asgi.py @@ -3,11 +3,12 @@ def application(scope): return app_http + async def app_http(receive, send): - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - (b'content-length', b'0'), - ] - }) + await send( + { + 'type': 'http.response.start', + 'status': 200, + 'headers': [(b'content-length', b'0'),], + } + ) diff --git a/test/python/legacy_force/asgi.py b/test/python/legacy_force/asgi.py index 2e5859f2..ad2785f2 100644 --- a/test/python/legacy_force/asgi.py +++ b/test/python/legacy_force/asgi.py @@ -7,11 +7,12 @@ def application(scope, receive=None, send=None): else: return app_http(receive, send) + async def app_http(receive, send): - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - (b'content-length', b'0'), - ] - }) + await send( + { + 'type': 'http.response.start', + 'status': 200, + 'headers': [(b'content-length', b'0'),], + } + ) diff --git a/test/python/mirror/asgi.py b/test/python/mirror/asgi.py index 7088e893..18a66a4c 100644 --- a/test/python/mirror/asgi.py +++ b/test/python/mirror/asgi.py @@ -8,15 +8,12 @@ async def application(scope, receive, send): if not m.get('more_body', False): break - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - (b'content-length', str(len(body)).encode()), - ] - }) + await send( + { + 'type': 'http.response.start', + 'status': 200, + 'headers': [(b'content-length', str(len(body)).encode())], + } + ) - await send({ - 'type': 'http.response.body', - 'body': body, - }) + await send({'type': 'http.response.body', 'body': body}) diff --git a/test/python/mirror/wsgi.py b/test/python/mirror/wsgi.py index eb1fb922..3cd95437 100644 --- a/test/python/mirror/wsgi.py +++ b/test/python/mirror/wsgi.py @@ -3,7 +3,5 @@ def application(environ, start_response): content_length = int(environ.get('CONTENT_LENGTH', 0)) body = bytes(environ['wsgi.input'].read(content_length)) - start_response('200', [ - ('Content-Length', str(len(body))) - ]) + start_response('200', [('Content-Length', str(len(body)))]) return [body] diff --git a/test/python/path/wsgi.py b/test/python/path/wsgi.py index 2807f6ef..da7e1ff1 100644 --- a/test/python/path/wsgi.py +++ b/test/python/path/wsgi.py @@ -1,6 +1,7 @@ import os import sys + def application(environ, start_response): body = os.pathsep.join(sys.path).encode() diff --git a/test/python/query_string/asgi.py b/test/python/query_string/asgi.py index 28f4d107..5b659f9c 100644 --- a/test/python/query_string/asgi.py +++ b/test/python/query_string/asgi.py @@ -1,11 +1,13 @@ async def application(scope, receive, send): assert scope['type'] == 'http' - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - (b'content-length', b'0'), - (b'query-string', scope['query_string']), - ] - }) + await send( + { + 'type': 'http.response.start', + 'status': 200, + 'headers': [ + (b'content-length', b'0'), + (b'query-string', scope['query_string']), + ], + } + ) diff --git a/test/python/query_string/wsgi.py b/test/python/query_string/wsgi.py index 90f1c7ec..54a67b03 100644 --- a/test/python/query_string/wsgi.py +++ b/test/python/query_string/wsgi.py @@ -1,7 +1,10 @@ def application(environ, start_response): - start_response('200', [ - ('Content-Length', '0'), - ('Query-String', environ.get('QUERY_STRING')) - ]) + start_response( + '200', + [ + ('Content-Length', '0'), + ('Query-String', environ.get('QUERY_STRING')), + ], + ) return [] diff --git a/test/python/server_port/asgi.py b/test/python/server_port/asgi.py index e79ced00..810a182c 100644 --- a/test/python/server_port/asgi.py +++ b/test/python/server_port/asgi.py @@ -1,11 +1,13 @@ async def application(scope, receive, send): assert scope['type'] == 'http' - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - (b'content-length', b'0'), - (b'server-port', str(scope['server'][1]).encode()), - ] - }) + await send( + { + 'type': 'http.response.start', + 'status': 200, + 'headers': [ + (b'content-length', b'0'), + (b'server-port', str(scope['server'][1]).encode()), + ], + } + ) diff --git a/test/python/server_port/wsgi.py b/test/python/server_port/wsgi.py index 89cd82b3..c796da95 100644 --- a/test/python/server_port/wsgi.py +++ b/test/python/server_port/wsgi.py @@ -1,7 +1,7 @@ def application(environ, start_response): - start_response('200', [ - ('Content-Length', '0'), - ('Server-Port', environ.get('SERVER_PORT')) - ]) + start_response( + '200', + [('Content-Length', '0'), ('Server-Port', environ.get('SERVER_PORT'))], + ) return [] diff --git a/test/python/threading/asgi.py b/test/python/threading/asgi.py index 3c978e50..c4169a24 100644 --- a/test/python/threading/asgi.py +++ b/test/python/threading/asgi.py @@ -33,10 +33,10 @@ async def application(scope, receive, send): Foo(Foo.num).start() Foo.num += 10 - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - (b'content-length', b'0'), - ] - }) + await send( + { + 'type': 'http.response.start', + 'status': 200, + 'headers': [(b'content-length', b'0')], + } + ) diff --git a/test/python/threads/asgi.py b/test/python/threads/asgi.py index d51ae431..ff4e52ad 100644 --- a/test/python/threads/asgi.py +++ b/test/python/threads/asgi.py @@ -2,6 +2,7 @@ import asyncio import time import threading + async def application(scope, receive, send): assert scope['type'] == 'http' @@ -17,11 +18,13 @@ async def application(scope, receive, send): time.sleep(delay) - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - (b'content-length', b'0'), - (b'x-thread', str(threading.currentThread().ident).encode()), - ] - }) + await send( + { + 'type': 'http.response.start', + 'status': 200, + 'headers': [ + (b'content-length', b'0'), + (b'x-thread', str(threading.currentThread().ident).encode()), + ], + } + ) diff --git a/test/python/threads/wsgi.py b/test/python/threads/wsgi.py index 1cc8ffe2..cc283cfe 100644 --- a/test/python/threads/wsgi.py +++ b/test/python/threads/wsgi.py @@ -1,15 +1,19 @@ import time import threading + def application(environ, start_response): delay = float(environ.get('HTTP_X_DELAY', 0)) time.sleep(delay) - start_response('200', [ - ('Content-Length', '0'), - ('Wsgi-Multithread', str(environ['wsgi.multithread'])), - ('X-Thread', str(threading.currentThread().ident)) - ]) + start_response( + '200', + [ + ('Content-Length', '0'), + ('Wsgi-Multithread', str(environ['wsgi.multithread'])), + ('X-Thread', str(threading.currentThread().ident)), + ], + ) return [] diff --git a/test/python/upload/wsgi.py b/test/python/upload/wsgi.py index 37ee89eb..953c5ecc 100644 --- a/test/python/upload/wsgi.py +++ b/test/python/upload/wsgi.py @@ -1,6 +1,7 @@ from tempfile import TemporaryFile import os, cgi + def read(environ): length = int(environ.get('CONTENT_LENGTH', 0)) @@ -11,6 +12,7 @@ def read(environ): environ['wsgi.input'] = body return body + def application(environ, start_response): file = read(environ) @@ -19,9 +21,9 @@ def application(environ, start_response): filename = form['file'].filename data = filename.encode() + form['file'].file.read() - start_response('200 OK', [ - ('Content-Type', 'text/plain'), - ('Content-Length', str(len(data))), - ]) + start_response( + '200 OK', + [('Content-Type', 'text/plain'), ('Content-Length', str(len(data)))], + ) return data diff --git a/test/python/user_group/wsgi.py b/test/python/user_group/wsgi.py index f5deb87d..4003c064 100644 --- a/test/python/user_group/wsgi.py +++ b/test/python/user_group/wsgi.py @@ -1,18 +1,19 @@ import json import os + def application(environ, start_response): uid = os.geteuid() gid = os.getegid() - out = json.dumps({ - 'UID': uid, - 'GID': gid, - }).encode('utf-8') + out = json.dumps({'UID': uid, 'GID': gid,}).encode('utf-8') - start_response('200 OK', [ - ('Content-Length', str(len(out))), - ('Content-Type', 'application/json') - ]) + start_response( + '200 OK', + [ + ('Content-Length', str(len(out))), + ('Content-Type', 'application/json'), + ], + ) return [out] diff --git a/test/python/variables/asgi.py b/test/python/variables/asgi.py index dd1cca72..5a4f55e8 100644 --- a/test/python/variables/asgi.py +++ b/test/python/variables/asgi.py @@ -17,24 +17,23 @@ async def application(scope, receive, send): res.append(h[1]) return b', '.join(res) - await send({ - 'type': 'http.response.start', - 'status': 200, - 'headers': [ - (b'content-type', get_header(b'content-type')), - (b'content-length', str(len(body)).encode()), - (b'request-method', scope['method'].encode()), - (b'request-uri', scope['path'].encode()), - (b'http-host', get_header(b'host')), - (b'http-version', scope['http_version'].encode()), - (b'asgi-version', scope['asgi']['version'].encode()), - (b'asgi-spec-version', scope['asgi']['spec_version'].encode()), - (b'scheme', scope['scheme'].encode()), - (b'custom-header', get_header(b'custom-header')), - ] - }) + await send( + { + 'type': 'http.response.start', + 'status': 200, + 'headers': [ + (b'content-type', get_header(b'content-type')), + (b'content-length', str(len(body)).encode()), + (b'request-method', scope['method'].encode()), + (b'request-uri', scope['path'].encode()), + (b'http-host', get_header(b'host')), + (b'http-version', scope['http_version'].encode()), + (b'asgi-version', scope['asgi']['version'].encode()), + (b'asgi-spec-version', scope['asgi']['spec_version'].encode()), + (b'scheme', scope['scheme'].encode()), + (b'custom-header', get_header(b'custom-header')), + ], + } + ) - await send({ - 'type': 'http.response.body', - 'body': body, - }) + await send({'type': 'http.response.body', 'body': body}) diff --git a/test/python/variables/wsgi.py b/test/python/variables/wsgi.py index 53991e5e..5d77902d 100644 --- a/test/python/variables/wsgi.py +++ b/test/python/variables/wsgi.py @@ -3,19 +3,22 @@ def application(environ, start_response): content_length = int(environ.get('CONTENT_LENGTH', 0)) body = bytes(environ['wsgi.input'].read(content_length)) - start_response('200', [ - ('Content-Type', environ.get('CONTENT_TYPE')), - ('Content-Length', str(len(body))), - ('Request-Method', environ.get('REQUEST_METHOD')), - ('Request-Uri', environ.get('REQUEST_URI')), - ('Http-Host', environ.get('HTTP_HOST')), - ('Server-Protocol', environ.get('SERVER_PROTOCOL')), - ('Server-Software', environ.get('SERVER_SOFTWARE')), - ('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')), - ('Wsgi-Version', str(environ['wsgi.version'])), - ('Wsgi-Url-Scheme', environ['wsgi.url_scheme']), - ('Wsgi-Multithread', str(environ['wsgi.multithread'])), - ('Wsgi-Multiprocess', str(environ['wsgi.multiprocess'])), - ('Wsgi-Run-Once', str(environ['wsgi.run_once'])) - ]) + start_response( + '200', + [ + ('Content-Type', environ.get('CONTENT_TYPE')), + ('Content-Length', str(len(body))), + ('Request-Method', environ.get('REQUEST_METHOD')), + ('Request-Uri', environ.get('REQUEST_URI')), + ('Http-Host', environ.get('HTTP_HOST')), + ('Server-Protocol', environ.get('SERVER_PROTOCOL')), + ('Server-Software', environ.get('SERVER_SOFTWARE')), + ('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')), + ('Wsgi-Version', str(environ['wsgi.version'])), + ('Wsgi-Url-Scheme', environ['wsgi.url_scheme']), + ('Wsgi-Multithread', str(environ['wsgi.multithread'])), + ('Wsgi-Multiprocess', str(environ['wsgi.multiprocess'])), + ('Wsgi-Run-Once', str(environ['wsgi.run_once'])), + ], + ) return [body] diff --git a/test/python/websockets/mirror/asgi.py b/test/python/websockets/mirror/asgi.py index 0f1d9953..72a32d67 100644 --- a/test/python/websockets/mirror/asgi.py +++ b/test/python/websockets/mirror/asgi.py @@ -3,16 +3,16 @@ async def application(scope, receive, send): while True: m = await receive() if m['type'] == 'websocket.connect': - await send({ - 'type': 'websocket.accept', - }) + await send({'type': 'websocket.accept'}) if m['type'] == 'websocket.receive': - await send({ - 'type': 'websocket.send', - 'bytes': m.get('bytes', None), - 'text': m.get('text', None), - }) + await send( + { + 'type': 'websocket.send', + 'bytes': m.get('bytes', None), + 'text': m.get('text', None), + } + ) if m['type'] == 'websocket.disconnect': - break; + break diff --git a/test/python/websockets/subprotocol/asgi.py b/test/python/websockets/subprotocol/asgi.py index 92263dd7..0385bb9d 100644 --- a/test/python/websockets/subprotocol/asgi.py +++ b/test/python/websockets/subprotocol/asgi.py @@ -6,20 +6,24 @@ async def application(scope, receive, send): if m['type'] == 'websocket.connect': subprotocols = scope['subprotocols'] - await send({ - 'type': 'websocket.accept', - 'headers': [ - (b'x-subprotocols', str(subprotocols).encode()), - ], - 'subprotocol': subprotocols[0], - }) + await send( + { + 'type': 'websocket.accept', + 'headers': [ + (b'x-subprotocols', str(subprotocols).encode()), + ], + 'subprotocol': subprotocols[0], + } + ) if m['type'] == 'websocket.receive': - await send({ - 'type': 'websocket.send', - 'bytes': m.get('bytes', None), - 'text': m.get('text', None), - }) + await send( + { + 'type': 'websocket.send', + 'bytes': m.get('bytes', None), + 'text': m.get('text', None), + } + ) if m['type'] == 'websocket.disconnect': - break; + break |