Skip to content

Commit bcb64c4

Browse files
committed
Apply linters on tests/simple_server.py
Apply all 4 linters on tests/simple_server.py, so we can lint it in the future and not rename and exclude it. As we are going to use part or most of tests/utils.py after we remove the test files testing the old code, then we would need to keep the simple_server.py file. It's currently used in tests/updater_ng.py testing the new updater implementation. Black and isort changes where automatically made. The only manual changes are: - pylint disable once in can_connect - add type annotations - simplifications around setting up the handler variable - function docstrings Signed-off-by: Martin Vrachev <[email protected]>
1 parent 580fd4d commit bcb64c4

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

tests/simple_server.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,42 @@
2525
http://docs.python.org/library/simplehttpserver.html#module-SimpleHTTPServer
2626
"""
2727

28-
import sys
29-
import random
3028
import socketserver
29+
import sys
3130
from http.server import SimpleHTTPRequestHandler
31+
from typing import Type, Union
3232

3333

3434
class QuietHTTPRequestHandler(SimpleHTTPRequestHandler):
35-
"""A SimpleHTTPRequestHandler that does not write incoming requests to
36-
stderr. """
37-
def log_request(self, code='-', size='-'):
38-
pass
35+
"""A SimpleHTTPRequestHandler that does not write incoming requests to
36+
stderr."""
37+
38+
def log_request(
39+
self, code: Union[int, str] = "-", size: Union[int, str] = "-"
40+
) -> None:
41+
pass
42+
3943

4044
# NOTE: On Windows/Python2 tests that use this simple_server.py in a
4145
# subprocesses hang after a certain amount of requests (~68), if a PIPE is
4246
# passed as Popen's stderr argument. This problem doesn't emerge if
4347
# we silence the HTTP messages.
4448
# If you decide to receive the HTTP messages, then this bug
4549
# could reappear.
46-
use_quiet_http_request_handler = True
4750

48-
if len(sys.argv) > 2:
49-
use_quiet_http_request_handler = sys.argv[2]
51+
# pylint: disable=invalid-name
52+
handler: Type[
53+
Union[SimpleHTTPRequestHandler, QuietHTTPRequestHandler]
54+
] = QuietHTTPRequestHandler
5055

51-
if use_quiet_http_request_handler:
52-
handler = QuietHTTPRequestHandler
53-
else:
54-
handler = SimpleHTTPRequestHandler
56+
if len(sys.argv) > 2:
57+
handler = SimpleHTTPRequestHandler
5558

5659
# Allow re-use so you can re-run tests as often as you want even if the
5760
# tests re-use ports. Otherwise TCP TIME-WAIT prevents reuse for ~1 minute
5861
socketserver.TCPServer.allow_reuse_address = True
5962

60-
httpd = socketserver.TCPServer(('localhost', 0), handler)
61-
port_message = 'bind succeeded, server port is: ' \
62-
+ str(httpd.server_address[1])
63+
httpd = socketserver.TCPServer(("localhost", 0), handler)
64+
port_message = "bind succeeded, server port is: " + str(httpd.server_address[1])
6365
print(port_message)
6466
httpd.serve_forever()

0 commit comments

Comments
 (0)