From 35e9c57af7c6e312ec6f22fad2137f5500b0ff15 Mon Sep 17 00:00:00 2001 From: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com> Date: Mon, 10 Jan 2022 13:28:22 +0530 Subject: [PATCH] `isort` everything except lib (for now) (#952) * isort the tests folder * Carry over changes from #672 * Disable pre-commit * Revert flake8 config change * isort examples too --- .isort.cfg | 24 +++++++++++++++ .pre-commit-config.yaml | 2 +- check.py | 3 +- examples/https_connect_tunnel.py | 8 ++--- examples/pubsub_eventing.py | 10 ++++--- examples/ssl_echo_client.py | 1 + examples/ssl_echo_server.py | 3 +- examples/tcp_echo_client.py | 1 + examples/web_scraper.py | 2 +- examples/websocket_client.py | 5 +++- tests/__init__.py | 1 + tests/common/test_flags.py | 9 +++--- tests/common/test_pki.py | 5 ++-- tests/common/test_utils.py | 9 ++++-- tests/core/test_acceptor.py | 5 ++-- tests/core/test_acceptor_pool.py | 1 - tests/core/test_conn_pool.py | 5 ++-- tests/core/test_connection.py | 17 +++++++---- tests/core/test_event_dispatcher.py | 7 ++--- tests/core/test_event_manager.py | 1 - tests/core/test_event_queue.py | 4 +-- tests/core/test_event_subscriber.py | 9 ++++-- tests/core/test_listener.py | 7 ++--- .../exceptions/test_http_proxy_auth_failed.py | 8 ++--- .../exceptions/test_http_request_rejected.py | 2 +- tests/http/test_chunk_parser.py | 2 +- tests/http/test_http2.py | 5 ++-- tests/http/test_http_parser.py | 10 +++---- tests/http/test_http_proxy.py | 13 ++++---- .../http/test_http_proxy_tls_interception.py | 14 ++++----- tests/http/test_protocol_handler.py | 26 ++++++++-------- tests/http/test_proxy_protocol.py | 2 +- tests/http/test_tls_parser.py | 4 +-- tests/http/test_web_server.py | 21 ++++++------- tests/http/test_websocket_client.py | 6 ++-- tests/integration/test_integration.py | 8 ++--- tests/plugin/test_http_proxy_plugins.py | 24 +++++++-------- ...ttp_proxy_plugins_with_tls_interception.py | 18 +++++------ tests/plugin/utils.py | 9 ++++-- tests/test_circular_imports.py | 12 ++++---- tests/test_main.py | 30 +++++++++++-------- tests/test_set_open_file_limit.py | 6 ++-- tests/testing/test_embed.py | 8 +++-- tests/testing/test_test_case.py | 2 +- 44 files changed, 209 insertions(+), 160 deletions(-) create mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000000..88a87bdf69 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,24 @@ +# https://github.com/timothycrosley/isort/wiki/isort-Settings +[settings] +default_section = THIRDPARTY +# force_to_top=file1.py,file2.py +# forced_separate = django.contrib,django.utils +include_trailing_comma = true +indent = 4 +known_first_party = proxy +# known_future_library = future,pies +# known_standard_library = std,std2 +known_testing = pytest,unittest +length_sort = 1 +# Should be: 80 - 1 +line_length = 79 +lines_after_imports = 2 +# https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html +# NOTE: Another mode could be "5" for grouping multiple "import from" under +# NOTE: a single instruction. +multi_line_output = 5 +no_lines_before = LOCALFOLDER +sections=FUTURE,STDLIB,TESTING,THIRDPARTY,FIRSTPARTY,LOCALFOLDER +# skip=file3.py,file4.py +use_parentheses = true +verbose = true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 516e19abc3..f6243648ef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: - --py36-plus # - repo: https://github.com/timothycrosley/isort.git -# rev: 5.4.2 +# rev: 5.10.0 # hooks: # - id: isort # args: diff --git a/check.py b/check.py index 59147caf53..37320f79dc 100644 --- a/check.py +++ b/check.py @@ -10,10 +10,11 @@ """ import sys import subprocess - from pathlib import Path + from proxy.common.version import __version__ as lib_version + # This script ensures our versions never run out of sync. # # 1. TODO: Version is hardcoded in homebrew stable package diff --git a/examples/https_connect_tunnel.py b/examples/https_connect_tunnel.py index 21ef67e3e3..16626c81d7 100644 --- a/examples/https_connect_tunnel.py +++ b/examples/https_connect_tunnel.py @@ -9,18 +9,14 @@ :license: BSD, see LICENSE for more details. """ import time - from typing import Any, Optional from proxy import Proxy - +from proxy.core.base import BaseTcpTunnelHandler from proxy.http.responses import ( - PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT, - PROXY_TUNNEL_UNSUPPORTED_SCHEME, + PROXY_TUNNEL_UNSUPPORTED_SCHEME, PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT, ) -from proxy.core.base import BaseTcpTunnelHandler - class HttpsConnectTunnelHandler(BaseTcpTunnelHandler): """A https CONNECT tunnel.""" diff --git a/examples/pubsub_eventing.py b/examples/pubsub_eventing.py index 607cf4536e..101a8d540c 100644 --- a/examples/pubsub_eventing.py +++ b/examples/pubsub_eventing.py @@ -9,13 +9,15 @@ :license: BSD, see LICENSE for more details. """ import time -import multiprocessing import logging +import multiprocessing +from typing import Any, Dict, Optional -from typing import Dict, Any, Optional - +from proxy.core.event import ( + EventQueue, EventManager, EventSubscriber, eventNames, +) from proxy.common.constants import DEFAULT_LOG_FORMAT -from proxy.core.event import EventManager, EventQueue, EventSubscriber, eventNames + logging.basicConfig(level=logging.DEBUG, format=DEFAULT_LOG_FORMAT) diff --git a/examples/ssl_echo_client.py b/examples/ssl_echo_client.py index 3c8f2d8cc5..37b2f19890 100644 --- a/examples/ssl_echo_client.py +++ b/examples/ssl_echo_client.py @@ -13,6 +13,7 @@ from proxy.core.connection import TcpServerConnection from proxy.common.constants import DEFAULT_BUFFER_SIZE + logger = logging.getLogger(__name__) if __name__ == '__main__': diff --git a/examples/ssl_echo_server.py b/examples/ssl_echo_server.py index 65432f3719..433af3878d 100644 --- a/examples/ssl_echo_server.py +++ b/examples/ssl_echo_server.py @@ -12,11 +12,10 @@ from typing import Optional from proxy import Proxy +from proxy.core.base import BaseTcpServerHandler from proxy.common.utils import wrap_socket from proxy.core.connection import TcpClientConnection -from proxy.core.base import BaseTcpServerHandler - class EchoSSLServerHandler(BaseTcpServerHandler): """Wraps client socket during initialization.""" diff --git a/examples/tcp_echo_client.py b/examples/tcp_echo_client.py index e62230f13e..9ddecbd614 100644 --- a/examples/tcp_echo_client.py +++ b/examples/tcp_echo_client.py @@ -13,6 +13,7 @@ from proxy.common.utils import socket_connection from proxy.common.constants import DEFAULT_BUFFER_SIZE + logger = logging.getLogger(__name__) if __name__ == '__main__': diff --git a/examples/web_scraper.py b/examples/web_scraper.py index c08e58a938..8168dca09d 100644 --- a/examples/web_scraper.py +++ b/examples/web_scraper.py @@ -11,9 +11,9 @@ import time from proxy import Proxy +from proxy.common.types import Readables, Writables, SelectableEvents from proxy.core.acceptor import Work from proxy.core.connection import TcpClientConnection -from proxy.common.types import Readables, SelectableEvents, Writables class WebScraper(Work[TcpClientConnection]): diff --git a/examples/websocket_client.py b/examples/websocket_client.py index 48a217b4d3..8c18a6e55d 100644 --- a/examples/websocket_client.py +++ b/examples/websocket_client.py @@ -11,7 +11,10 @@ import time import logging -from proxy.http.websocket import WebsocketClient, WebsocketFrame, websocketOpcodes +from proxy.http.websocket import ( + WebsocketFrame, WebsocketClient, websocketOpcodes, +) + # globals client: WebsocketClient diff --git a/tests/__init__.py b/tests/__init__.py index 891fe5fddd..5831815f1f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -12,4 +12,5 @@ from proxy.common.constants import DEFAULT_LOG_FORMAT + logging.basicConfig(level=logging.DEBUG, format=DEFAULT_LOG_FORMAT) diff --git a/tests/common/test_flags.py b/tests/common/test_flags.py index a8791d5ce4..1fc92119c5 100644 --- a/tests/common/test_flags.py +++ b/tests/common/test_flags.py @@ -8,16 +8,15 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import unittest +from typing import Dict, List +import unittest from unittest import mock -from typing import List, Dict +from proxy.plugin import CacheResponsesPlugin, FilterByUpstreamHostPlugin from proxy.http.proxy import HttpProxyPlugin -from proxy.plugin import CacheResponsesPlugin -from proxy.plugin import FilterByUpstreamHostPlugin -from proxy.common.utils import bytes_ from proxy.common.flag import FlagParser +from proxy.common.utils import bytes_ from proxy.common.version import __version__ from proxy.common.constants import PLUGIN_HTTP_PROXY, PY2_DEPRECATION_MESSAGE diff --git a/tests/common/test_pki.py b/tests/common/test_pki.py index 1abcb1c625..2bbebe06bb 100644 --- a/tests/common/test_pki.py +++ b/tests/common/test_pki.py @@ -10,11 +10,12 @@ """ import os import tempfile -import unittest import subprocess -from unittest import mock from typing import Tuple +import unittest +from unittest import mock + from proxy.common import pki diff --git a/tests/common/test_utils.py b/tests/common/test_utils.py index 6d6217a641..4123aa9eaa 100644 --- a/tests/common/test_utils.py +++ b/tests/common/test_utils.py @@ -9,12 +9,15 @@ :license: BSD, see LICENSE for more details. """ import socket + import unittest from unittest import mock -from proxy.common.constants import DEFAULT_IPV6_HOSTNAME, DEFAULT_IPV4_HOSTNAME, DEFAULT_PORT, DEFAULT_TIMEOUT -from proxy.common.constants import DEFAULT_HTTP_PORT -from proxy.common.utils import new_socket_connection, socket_connection +from proxy.common.utils import socket_connection, new_socket_connection +from proxy.common.constants import ( + DEFAULT_PORT, DEFAULT_TIMEOUT, DEFAULT_HTTP_PORT, DEFAULT_IPV4_HOSTNAME, + DEFAULT_IPV6_HOSTNAME, +) class TestSocketConnectionUtils(unittest.TestCase): diff --git a/tests/core/test_acceptor.py b/tests/core/test_acceptor.py index 89bbce46aa..8f7a529b6a 100644 --- a/tests/core/test_acceptor.py +++ b/tests/core/test_acceptor.py @@ -8,14 +8,15 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import unittest import socket import selectors import multiprocessing + +import unittest from unittest import mock -from proxy.core.acceptor import Acceptor from proxy.common.flag import FlagParser +from proxy.core.acceptor import Acceptor class TestAcceptor(unittest.TestCase): diff --git a/tests/core/test_acceptor_pool.py b/tests/core/test_acceptor_pool.py index 5241bd4341..d35b80e10d 100644 --- a/tests/core/test_acceptor_pool.py +++ b/tests/core/test_acceptor_pool.py @@ -9,7 +9,6 @@ :license: BSD, see LICENSE for more details. """ import unittest - from unittest import mock from proxy.common.flag import FlagParser diff --git a/tests/core/test_conn_pool.py b/tests/core/test_conn_pool.py index 7f38d993cf..6547a0de81 100644 --- a/tests/core/test_conn_pool.py +++ b/tests/core/test_conn_pool.py @@ -8,11 +8,12 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import pytest -import unittest import selectors +import pytest +import unittest from unittest import mock + from pytest_mock import MockerFixture from proxy.core.connection import UpstreamConnectionPool diff --git a/tests/core/test_connection.py b/tests/core/test_connection.py index 95bc000626..b3c00ad708 100644 --- a/tests/core/test_connection.py +++ b/tests/core/test_connection.py @@ -8,15 +8,20 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import unittest -import socket import ssl +import socket +from typing import Union, Optional + +import unittest from unittest import mock -from typing import Optional, Union -from proxy.core.connection import tcpConnectionTypes, TcpConnectionUninitializedException -from proxy.core.connection import TcpServerConnection, TcpConnection, TcpClientConnection -from proxy.common.constants import DEFAULT_IPV6_HOSTNAME, DEFAULT_PORT, DEFAULT_IPV4_HOSTNAME +from proxy.core.connection import ( + TcpConnection, TcpClientConnection, TcpServerConnection, + TcpConnectionUninitializedException, tcpConnectionTypes, +) +from proxy.common.constants import ( + DEFAULT_PORT, DEFAULT_IPV4_HOSTNAME, DEFAULT_IPV6_HOSTNAME, +) class TestTcpConnection(unittest.TestCase): diff --git a/tests/core/test_event_dispatcher.py b/tests/core/test_event_dispatcher.py index 74e7b7187e..63999187b6 100644 --- a/tests/core/test_event_dispatcher.py +++ b/tests/core/test_event_dispatcher.py @@ -9,16 +9,15 @@ :license: BSD, see LICENSE for more details. """ import os -import threading -import unittest import queue +import threading import multiprocessing - from multiprocessing import connection +import unittest from unittest import mock -from proxy.core.event import EventDispatcher, EventQueue, eventNames +from proxy.core.event import EventQueue, EventDispatcher, eventNames class TestEventDispatcher(unittest.TestCase): diff --git a/tests/core/test_event_manager.py b/tests/core/test_event_manager.py index 5f532a95fe..0685f997a8 100644 --- a/tests/core/test_event_manager.py +++ b/tests/core/test_event_manager.py @@ -9,7 +9,6 @@ :license: BSD, see LICENSE for more details. """ import unittest - from unittest import mock from proxy.core.event import EventManager diff --git a/tests/core/test_event_queue.py b/tests/core/test_event_queue.py index 174d573244..29c4299805 100644 --- a/tests/core/test_event_queue.py +++ b/tests/core/test_event_queue.py @@ -8,11 +8,11 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import multiprocessing import os import threading -import unittest +import multiprocessing +import unittest from unittest import mock from proxy.core.event import EventQueue, eventNames diff --git a/tests/core/test_event_subscriber.py b/tests/core/test_event_subscriber.py index 3ce8dcb844..59be997d41 100644 --- a/tests/core/test_event_subscriber.py +++ b/tests/core/test_event_subscriber.py @@ -11,13 +11,16 @@ import os import queue import threading -import unittest import multiprocessing -from typing import Dict, Any +from typing import Any, Dict +import unittest from unittest import mock -from proxy.core.event import EventQueue, EventDispatcher, EventSubscriber, eventNames +from proxy.core.event import ( + EventQueue, EventDispatcher, EventSubscriber, eventNames, +) + PUBLISHER_ID = threading.get_ident() diff --git a/tests/core/test_listener.py b/tests/core/test_listener.py index 8d5706953b..79ab28a78d 100644 --- a/tests/core/test_listener.py +++ b/tests/core/test_listener.py @@ -11,15 +11,14 @@ import os import socket import tempfile -import unittest - -from unittest import mock import pytest +import unittest +from unittest import mock +from proxy.common.flag import FlagParser from proxy.core.acceptor import Listener from proxy.common.constants import IS_WINDOWS -from proxy.common.flag import FlagParser class TestListener(unittest.TestCase): diff --git a/tests/http/exceptions/test_http_proxy_auth_failed.py b/tests/http/exceptions/test_http_proxy_auth_failed.py index 23a3b4dcd5..e0695bcdb0 100644 --- a/tests/http/exceptions/test_http_proxy_auth_failed.py +++ b/tests/http/exceptions/test_http_proxy_auth_failed.py @@ -8,17 +8,17 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import pytest import selectors +import pytest + from pytest_mock import MockerFixture -from proxy.common.flag import FlagParser from proxy.http import HttpProtocolHandler, httpHeaders +from proxy.common.flag import FlagParser +from proxy.common.utils import build_http_request from proxy.http.responses import PROXY_AUTH_FAILED_RESPONSE_PKT from proxy.core.connection import TcpClientConnection -from proxy.common.utils import build_http_request - from ...test_assertions import Assertions diff --git a/tests/http/exceptions/test_http_request_rejected.py b/tests/http/exceptions/test_http_request_rejected.py index 69a9611339..9a6652d6b8 100644 --- a/tests/http/exceptions/test_http_request_rejected.py +++ b/tests/http/exceptions/test_http_request_rejected.py @@ -12,9 +12,9 @@ from proxy.http import httpStatusCodes from proxy.http.parser import HttpParser, httpParserTypes +from proxy.common.utils import build_http_response from proxy.http.exception import HttpRequestRejected from proxy.common.constants import CRLF -from proxy.common.utils import build_http_response class TestHttpRequestRejected(unittest.TestCase): diff --git a/tests/http/test_chunk_parser.py b/tests/http/test_chunk_parser.py index 68d10781b8..1fde17256a 100644 --- a/tests/http/test_chunk_parser.py +++ b/tests/http/test_chunk_parser.py @@ -10,7 +10,7 @@ """ import unittest -from proxy.http.parser import chunkParserStates, ChunkParser +from proxy.http.parser import ChunkParser, chunkParserStates class TestChunkParser(unittest.TestCase): diff --git a/tests/http/test_http2.py b/tests/http/test_http2.py index 942e5edf8b..e8462aab3d 100644 --- a/tests/http/test_http2.py +++ b/tests/http/test_http2.py @@ -8,11 +8,12 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import httpx import pytest -from proxy.common.constants import IS_WINDOWS +import httpx + from proxy import TestCase +from proxy.common.constants import IS_WINDOWS class TestHttp2WithProxy(TestCase): diff --git a/tests/http/test_http_parser.py b/tests/http/test_http_parser.py index 0489b85741..b817847775 100644 --- a/tests/http/test_http_parser.py +++ b/tests/http/test_http_parser.py @@ -10,14 +10,14 @@ """ import unittest -from proxy.common.constants import CRLF, HTTP_1_0 -from proxy.common.utils import build_http_request, build_http_header -from proxy.common.utils import find_http_line, bytes_ - from proxy.http import httpMethods -from proxy.http.exception import HttpProtocolException from proxy.http.parser import HttpParser, httpParserTypes, httpParserStates +from proxy.common.utils import ( + bytes_, find_http_line, build_http_header, build_http_request, +) +from proxy.http.exception import HttpProtocolException from proxy.http.responses import okResponse +from proxy.common.constants import CRLF, HTTP_1_0 class TestHttpParser(unittest.TestCase): diff --git a/tests/http/test_http_proxy.py b/tests/http/test_http_proxy.py index 6c09776d2c..54789ff8a9 100644 --- a/tests/http/test_http_proxy.py +++ b/tests/http/test_http_proxy.py @@ -8,18 +8,19 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import pytest import selectors +import pytest + from pytest_mock import MockerFixture -from proxy.common.constants import DEFAULT_HTTP_PORT -from proxy.common.flag import FlagParser -from proxy.core.connection import TcpClientConnection -from proxy.http.proxy import HttpProxyPlugin from proxy.http import HttpProtocolHandler -from proxy.http.exception import HttpProtocolException +from proxy.http.proxy import HttpProxyPlugin +from proxy.common.flag import FlagParser from proxy.common.utils import build_http_request +from proxy.http.exception import HttpProtocolException +from proxy.core.connection import TcpClientConnection +from proxy.common.constants import DEFAULT_HTTP_PORT class TestHttpProxyPlugin: diff --git a/tests/http/test_http_proxy_tls_interception.py b/tests/http/test_http_proxy_tls_interception.py index af8de9ce0a..dcc81a6e6c 100644 --- a/tests/http/test_http_proxy_tls_interception.py +++ b/tests/http/test_http_proxy_tls_interception.py @@ -11,21 +11,21 @@ import ssl import uuid import socket -import pytest import selectors - from typing import Any -from pytest_mock import MockerFixture + +import pytest from unittest import mock -from proxy.common.constants import DEFAULT_CA_FILE -from proxy.common.utils import build_http_request, bytes_ -from proxy.common.flag import FlagParser +from pytest_mock import MockerFixture + from proxy.http import HttpProtocolHandler, httpMethods from proxy.http.proxy import HttpProxyPlugin +from proxy.common.flag import FlagParser +from proxy.common.utils import bytes_, build_http_request from proxy.http.responses import PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT from proxy.core.connection import TcpClientConnection, TcpServerConnection - +from proxy.common.constants import DEFAULT_CA_FILE from ..test_assertions import Assertions diff --git a/tests/http/test_protocol_handler.py b/tests/http/test_protocol_handler.py index 9adb0bb683..6faf99f34b 100644 --- a/tests/http/test_protocol_handler.py +++ b/tests/http/test_protocol_handler.py @@ -9,29 +9,29 @@ :license: BSD, see LICENSE for more details. """ import base64 -import pytest import selectors +from typing import Any, cast +import pytest from unittest import mock + from pytest_mock import MockerFixture -from typing import cast, Any -from proxy.common.plugins import Plugins +from proxy.http import HttpProtocolHandler, httpHeaders +from proxy.http.proxy import HttpProxyPlugin from proxy.common.flag import FlagParser -from proxy.common.version import __version__ +from proxy.http.parser import HttpParser, httpParserTypes, httpParserStates from proxy.common.utils import bytes_ -from proxy.common.constants import CRLF, PLUGIN_HTTP_PROXY, PLUGIN_PROXY_AUTH, PLUGIN_WEB_SERVER -from proxy.core.connection import TcpClientConnection -from proxy.http.parser import HttpParser -from proxy.http.proxy import HttpProxyPlugin +from proxy.common.plugins import Plugins +from proxy.common.version import __version__ from proxy.http.responses import ( - BAD_GATEWAY_RESPONSE_PKT, - PROXY_AUTH_FAILED_RESPONSE_PKT, + BAD_GATEWAY_RESPONSE_PKT, PROXY_AUTH_FAILED_RESPONSE_PKT, PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT, ) -from proxy.http.parser import httpParserStates, httpParserTypes -from proxy.http import HttpProtocolHandler, httpHeaders - +from proxy.core.connection import TcpClientConnection +from proxy.common.constants import ( + CRLF, PLUGIN_HTTP_PROXY, PLUGIN_PROXY_AUTH, PLUGIN_WEB_SERVER, +) from ..test_assertions import Assertions diff --git a/tests/http/test_proxy_protocol.py b/tests/http/test_proxy_protocol.py index f8b609b1b9..1ac340baaa 100644 --- a/tests/http/test_proxy_protocol.py +++ b/tests/http/test_proxy_protocol.py @@ -10,7 +10,7 @@ """ import unittest -from proxy.http.parser import ProxyProtocol, PROXY_PROTOCOL_V2_SIGNATURE +from proxy.http.parser import PROXY_PROTOCOL_V2_SIGNATURE, ProxyProtocol from proxy.http.exception import HttpProtocolException diff --git a/tests/http/test_tls_parser.py b/tests/http/test_tls_parser.py index 1a5a0c93d3..2b6646ed69 100644 --- a/tests/http/test_tls_parser.py +++ b/tests/http/test_tls_parser.py @@ -9,11 +9,11 @@ :license: BSD, see LICENSE for more details. """ import re -import unittest import binascii - from pathlib import Path +import unittest + from proxy.http.parser.tls import TlsParser, tlsContentType, tlsHandshakeType diff --git a/tests/http/test_web_server.py b/tests/http/test_web_server.py index f383b30a6a..58fa47b5b5 100644 --- a/tests/http/test_web_server.py +++ b/tests/http/test_web_server.py @@ -10,23 +10,24 @@ """ import os import gzip -import pytest import tempfile import selectors - from typing import Any + +import pytest + from pytest_mock import MockerFixture -# from unittest import mock -from proxy.common.plugins import Plugins -from proxy.common.flag import FlagParser -from proxy.core.connection import TcpClientConnection from proxy.http import HttpProtocolHandler -from proxy.http.parser import HttpParser, httpParserStates, httpParserTypes -from proxy.common.utils import build_http_response, build_http_request, bytes_ -from proxy.common.constants import CRLF, PLUGIN_HTTP_PROXY, PLUGIN_PAC_FILE, PLUGIN_WEB_SERVER, PROXY_PY_DIR +from proxy.common.flag import FlagParser +from proxy.http.parser import HttpParser, httpParserTypes, httpParserStates +from proxy.common.utils import bytes_, build_http_request, build_http_response +from proxy.common.plugins import Plugins from proxy.http.responses import NOT_FOUND_RESPONSE_PKT - +from proxy.core.connection import TcpClientConnection +from proxy.common.constants import ( + CRLF, PROXY_PY_DIR, PLUGIN_PAC_FILE, PLUGIN_HTTP_PROXY, PLUGIN_WEB_SERVER, +) from ..test_assertions import Assertions diff --git a/tests/http/test_websocket_client.py b/tests/http/test_websocket_client.py index ef500c5b97..4e31e48e30 100644 --- a/tests/http/test_websocket_client.py +++ b/tests/http/test_websocket_client.py @@ -11,8 +11,10 @@ import unittest from unittest import mock -from proxy.common.utils import build_websocket_handshake_response, build_websocket_handshake_request -from proxy.http.websocket import WebsocketClient, WebsocketFrame +from proxy.common.utils import ( + build_websocket_handshake_request, build_websocket_handshake_response, +) +from proxy.http.websocket import WebsocketFrame, WebsocketClient from proxy.common.constants import DEFAULT_PORT diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 66307d9ccc..ef98d52616 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -11,12 +11,12 @@ Test the simplest proxy use scenario for smoke. """ import time -import pytest import tempfile - +from typing import Any, Generator from pathlib import Path -from subprocess import check_output, Popen -from typing import Generator, Any +from subprocess import Popen, check_output + +import pytest from proxy.common.constants import IS_WINDOWS diff --git a/tests/plugin/test_http_proxy_plugins.py b/tests/plugin/test_http_proxy_plugins.py index 50d2055888..3550c3295e 100644 --- a/tests/plugin/test_http_proxy_plugins.py +++ b/tests/plugin/test_http_proxy_plugins.py @@ -10,27 +10,25 @@ """ import gzip import json -import pytest import selectors - +from typing import Any, cast +from urllib import parse as urlparse from pathlib import Path + +import pytest from unittest import mock -from typing import cast, Any -from urllib import parse as urlparse + from pytest_mock import MockerFixture -from proxy.common.flag import FlagParser -from proxy.core.connection import TcpClientConnection -from proxy.http import HttpProtocolHandler -from proxy.http import httpStatusCodes +from proxy.http import HttpProtocolHandler, httpStatusCodes +from proxy.plugin import ProposedRestApiPlugin, RedirectToCustomServerPlugin from proxy.http.proxy import HttpProxyPlugin +from proxy.common.flag import FlagParser from proxy.http.parser import HttpParser, httpParserTypes -from proxy.common.utils import build_http_request, bytes_, build_http_response -from proxy.common.constants import PROXY_AGENT_HEADER_VALUE, DEFAULT_HTTP_PORT -from proxy.plugin import ProposedRestApiPlugin, RedirectToCustomServerPlugin - +from proxy.common.utils import bytes_, build_http_request, build_http_response +from proxy.core.connection import TcpClientConnection +from proxy.common.constants import DEFAULT_HTTP_PORT, PROXY_AGENT_HEADER_VALUE from .utils import get_plugin_by_test_name - from ..test_assertions import Assertions diff --git a/tests/plugin/test_http_proxy_plugins_with_tls_interception.py b/tests/plugin/test_http_proxy_plugins_with_tls_interception.py index 9845980201..55d09b62a6 100644 --- a/tests/plugin/test_http_proxy_plugins_with_tls_interception.py +++ b/tests/plugin/test_http_proxy_plugins_with_tls_interception.py @@ -11,23 +11,23 @@ import ssl import gzip import socket -import pytest import selectors +from typing import Any, cast + +import pytest from pytest_mock import MockerFixture -from typing import Any, cast +from proxy.http import HttpProtocolHandler, httpMethods +from proxy.http.proxy import HttpProxyPlugin from proxy.common.flag import FlagParser +from proxy.http.parser import HttpParser, httpParserTypes from proxy.common.utils import bytes_, build_http_request +from proxy.http.responses import ( + PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT, okResponse, +) from proxy.core.connection import TcpClientConnection, TcpServerConnection - -from proxy.http import httpMethods, HttpProtocolHandler -from proxy.http.proxy import HttpProxyPlugin -from proxy.http.parser import HttpParser, httpParserTypes -from proxy.http.responses import PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT, okResponse - from .utils import get_plugin_by_test_name - from ..test_assertions import Assertions diff --git a/tests/plugin/utils.py b/tests/plugin/utils.py index 3e58ff12f9..7e6335057d 100644 --- a/tests/plugin/utils.py +++ b/tests/plugin/utils.py @@ -9,10 +9,13 @@ :license: BSD, see LICENSE for more details. """ from typing import Type -from proxy.http.proxy import HttpProxyBasePlugin -from proxy.plugin import ModifyPostDataPlugin, ProposedRestApiPlugin, RedirectToCustomServerPlugin, \ - FilterByUpstreamHostPlugin, CacheResponsesPlugin, ManInTheMiddlePlugin, FilterByURLRegexPlugin +from proxy.plugin import ( + CacheResponsesPlugin, ManInTheMiddlePlugin, ModifyPostDataPlugin, + ProposedRestApiPlugin, FilterByURLRegexPlugin, FilterByUpstreamHostPlugin, + RedirectToCustomServerPlugin, +) +from proxy.http.proxy import HttpProxyBasePlugin def get_plugin_by_test_name(test_name: str) -> Type[HttpProxyBasePlugin]: diff --git a/tests/test_circular_imports.py b/tests/test_circular_imports.py index 4e6f8d6f77..32763491f0 100644 --- a/tests/test_circular_imports.py +++ b/tests/test_circular_imports.py @@ -18,15 +18,15 @@ * https://github.com/pytest-dev/pytest/blob/d18c75b/testing/test_meta.py * https://twitter.com/codewithanthony/status/1229445110510735361 """ -from itertools import chain -from pathlib import Path -from types import ModuleType -from typing import Generator, List - import os +import sys import pkgutil import subprocess -import sys +from types import ModuleType +from typing import List, Generator +from pathlib import Path +from itertools import chain + import pytest import proxy diff --git a/tests/test_main.py b/tests/test_main.py index 3f8816edda..c2fb4ea872 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -10,24 +10,28 @@ """ import os import tempfile -import unittest +import unittest from unittest import mock from proxy.proxy import main, entry_point -from proxy.common.constants import DEFAULT_PORT_FILE, _env_threadless_compliant # noqa: WPS450 from proxy.common.utils import bytes_ - -from proxy.common.constants import DEFAULT_ENABLE_DASHBOARD, DEFAULT_LOCAL_EXECUTOR, DEFAULT_LOG_LEVEL, DEFAULT_LOG_FILE -from proxy.common.constants import DEFAULT_TIMEOUT, DEFAULT_DEVTOOLS_WS_PATH, DEFAULT_DISABLE_HTTP_PROXY -from proxy.common.constants import DEFAULT_ENABLE_STATIC_SERVER, DEFAULT_ENABLE_EVENTS, DEFAULT_ENABLE_DEVTOOLS -from proxy.common.constants import DEFAULT_ENABLE_WEB_SERVER, DEFAULT_THREADLESS, DEFAULT_CERT_FILE, DEFAULT_KEY_FILE -from proxy.common.constants import DEFAULT_CA_CERT_FILE, DEFAULT_CA_KEY_FILE, DEFAULT_CA_SIGNING_KEY_FILE -from proxy.common.constants import DEFAULT_PAC_FILE, DEFAULT_PLUGINS, DEFAULT_PID_FILE, DEFAULT_PORT, DEFAULT_BASIC_AUTH -from proxy.common.constants import DEFAULT_NUM_WORKERS, DEFAULT_OPEN_FILE_LIMIT, DEFAULT_IPV6_HOSTNAME -from proxy.common.constants import DEFAULT_SERVER_RECVBUF_SIZE, DEFAULT_CLIENT_RECVBUF_SIZE, DEFAULT_WORK_KLASS -from proxy.common.constants import PLUGIN_INSPECT_TRAFFIC, PLUGIN_DASHBOARD, PLUGIN_DEVTOOLS_PROTOCOL, PLUGIN_WEB_SERVER -from proxy.common.constants import PLUGIN_HTTP_PROXY, DEFAULT_NUM_ACCEPTORS, PLUGIN_PROXY_AUTH, DEFAULT_LOG_FORMAT +from proxy.common.constants import ( # noqa: WPS450 + DEFAULT_PORT, DEFAULT_PLUGINS, DEFAULT_TIMEOUT, DEFAULT_KEY_FILE, + DEFAULT_LOG_FILE, DEFAULT_PAC_FILE, DEFAULT_PID_FILE, PLUGIN_DASHBOARD, + DEFAULT_CERT_FILE, DEFAULT_LOG_LEVEL, DEFAULT_PORT_FILE, PLUGIN_HTTP_PROXY, + PLUGIN_PROXY_AUTH, PLUGIN_WEB_SERVER, DEFAULT_BASIC_AUTH, + DEFAULT_LOG_FORMAT, DEFAULT_THREADLESS, DEFAULT_WORK_KLASS, + DEFAULT_CA_KEY_FILE, DEFAULT_NUM_WORKERS, DEFAULT_CA_CERT_FILE, + DEFAULT_ENABLE_EVENTS, DEFAULT_IPV6_HOSTNAME, DEFAULT_NUM_ACCEPTORS, + DEFAULT_LOCAL_EXECUTOR, PLUGIN_INSPECT_TRAFFIC, DEFAULT_ENABLE_DEVTOOLS, + DEFAULT_OPEN_FILE_LIMIT, DEFAULT_DEVTOOLS_WS_PATH, + DEFAULT_ENABLE_DASHBOARD, PLUGIN_DEVTOOLS_PROTOCOL, + DEFAULT_ENABLE_WEB_SERVER, DEFAULT_DISABLE_HTTP_PROXY, + DEFAULT_CA_SIGNING_KEY_FILE, DEFAULT_CLIENT_RECVBUF_SIZE, + DEFAULT_SERVER_RECVBUF_SIZE, DEFAULT_ENABLE_STATIC_SERVER, + _env_threadless_compliant, +) class TestMain(unittest.TestCase): diff --git a/tests/test_set_open_file_limit.py b/tests/test_set_open_file_limit.py index f02e3c2215..d0638a4172 100644 --- a/tests/test_set_open_file_limit.py +++ b/tests/test_set_open_file_limit.py @@ -8,13 +8,13 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ +import pytest import unittest from unittest import mock -import pytest - -from proxy.common.constants import IS_WINDOWS from proxy.common.utils import set_open_file_limit +from proxy.common.constants import IS_WINDOWS + if not IS_WINDOWS: import resource diff --git a/tests/testing/test_embed.py b/tests/testing/test_embed.py index a1f485bf3e..fb594173c1 100644 --- a/tests/testing/test_embed.py +++ b/tests/testing/test_embed.py @@ -9,16 +9,18 @@ :license: BSD, see LICENSE for more details. """ import http.client -import urllib.request import urllib.error +import urllib.request import pytest from proxy import TestCase -from proxy.common.constants import DEFAULT_CLIENT_RECVBUF_SIZE, PROXY_AGENT_HEADER_VALUE, IS_WINDOWS -from proxy.common.utils import socket_connection, build_http_request from proxy.http import httpMethods +from proxy.common.utils import socket_connection, build_http_request from proxy.http.responses import NOT_FOUND_RESPONSE_PKT +from proxy.common.constants import ( + IS_WINDOWS, PROXY_AGENT_HEADER_VALUE, DEFAULT_CLIENT_RECVBUF_SIZE, +) @pytest.mark.skipif( diff --git a/tests/testing/test_test_case.py b/tests/testing/test_test_case.py index daa28d0d63..ae984acce1 100644 --- a/tests/testing/test_test_case.py +++ b/tests/testing/test_test_case.py @@ -9,8 +9,8 @@ :license: BSD, see LICENSE for more details. """ import unittest -import proxy +import proxy from proxy.common.utils import get_available_port