mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-02 00:05:27 +00:00
Merge pull request #2026 from Kriechi/filename-matching
add filename-matching linter
This commit is contained in:
commit
bb2fa6dc7d
57
test/filename_matching.py
Normal file
57
test/filename_matching.py
Normal file
@ -0,0 +1,57 @@
|
||||
import os
|
||||
import re
|
||||
import glob
|
||||
import sys
|
||||
|
||||
|
||||
def check_src_files_have_test():
|
||||
missing_test_files = []
|
||||
|
||||
excluded = ['mitmproxy/contrib/', 'mitmproxy/test/', 'mitmproxy/tools/', 'mitmproxy/platform/']
|
||||
src_files = glob.glob('mitmproxy/**/*.py', recursive=True) + glob.glob('pathod/**/*.py', recursive=True)
|
||||
src_files = [f for f in src_files if os.path.basename(f) != '__init__.py']
|
||||
src_files = [f for f in src_files if not any(os.path.normpath(p) in f for p in excluded)]
|
||||
for f in src_files:
|
||||
p = os.path.join("test", os.path.dirname(f), "test_" + os.path.basename(f))
|
||||
if not os.path.isfile(p):
|
||||
missing_test_files.append((f, p))
|
||||
|
||||
return missing_test_files
|
||||
|
||||
|
||||
def check_test_files_have_src():
|
||||
unknown_test_files = []
|
||||
|
||||
excluded = ['test/mitmproxy/data/', 'test/mitmproxy/net/data/', '/tservers.py']
|
||||
test_files = glob.glob('test/mitmproxy/**/*.py', recursive=True) + glob.glob('test/pathod/**/*.py', recursive=True)
|
||||
test_files = [f for f in test_files if os.path.basename(f) != '__init__.py']
|
||||
test_files = [f for f in test_files if not any(os.path.normpath(p) in f for p in excluded)]
|
||||
for f in test_files:
|
||||
p = os.path.join(re.sub('^test/', '', os.path.dirname(f)), re.sub('^test_', '', os.path.basename(f)))
|
||||
if not os.path.isfile(p):
|
||||
unknown_test_files.append((f, p))
|
||||
|
||||
return unknown_test_files
|
||||
|
||||
|
||||
def main():
|
||||
exitcode = 0
|
||||
|
||||
missing_test_files = check_src_files_have_test()
|
||||
if missing_test_files:
|
||||
exitcode += 1
|
||||
for f, p in sorted(missing_test_files):
|
||||
print("{} MUST have a matching test file: {}".format(f, p))
|
||||
|
||||
unknown_test_files = check_test_files_have_src()
|
||||
if unknown_test_files:
|
||||
# TODO: enable this in the future
|
||||
# exitcode += 1
|
||||
for f, p in sorted(unknown_test_files):
|
||||
print("{} DOES NOT MATCH a source file! Expected to find: {}".format(f, p))
|
||||
|
||||
sys.exit(exitcode)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
1
test/mitmproxy/addons/onboardingapp/test_app.py
Normal file
1
test/mitmproxy/addons/onboardingapp/test_app.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/addons/test_eventstore.py
Normal file
1
test/mitmproxy/addons/test_eventstore.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
@ -1,6 +1,6 @@
|
||||
from mitmproxy.contentviews import image
|
||||
from mitmproxy.test import tutils
|
||||
from . import full_eval
|
||||
from .. import full_eval
|
||||
|
||||
|
||||
def test_view_image():
|
1
test/mitmproxy/contentviews/test_base.py
Normal file
1
test/mitmproxy/contentviews/test_base.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/contentviews/test_wbxml.py
Normal file
1
test/mitmproxy/contentviews/test_wbxml.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
@ -1,11 +0,0 @@
|
||||
import os
|
||||
import sys
|
||||
from unittest import mock
|
||||
|
||||
if os.name == "nt":
|
||||
m = mock.Mock()
|
||||
m.__version__ = "1.1.1"
|
||||
m.Widget = mock.Mock
|
||||
m.WidgetWrap = mock.Mock
|
||||
sys.modules['urwid'] = m
|
||||
sys.modules['urwid.util'] = mock.Mock()
|
0
test/mitmproxy/proxy/__init__.py
Normal file
0
test/mitmproxy/proxy/__init__.py
Normal file
1
test/mitmproxy/proxy/modes/test_http_proxy.py
Normal file
1
test/mitmproxy/proxy/modes/test_http_proxy.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/proxy/modes/test_reverse_proxy.py
Normal file
1
test/mitmproxy/proxy/modes/test_reverse_proxy.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/proxy/modes/test_socks_proxy.py
Normal file
1
test/mitmproxy/proxy/modes/test_socks_proxy.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/proxy/modes/test_transparent_proxy.py
Normal file
1
test/mitmproxy/proxy/modes/test_transparent_proxy.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
0
test/mitmproxy/proxy/protocol/__init__.py
Normal file
0
test/mitmproxy/proxy/protocol/__init__.py
Normal file
1
test/mitmproxy/proxy/protocol/test_base.py
Normal file
1
test/mitmproxy/proxy/protocol/test_base.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/proxy/protocol/test_http.py
Normal file
1
test/mitmproxy/proxy/protocol/test_http.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
@ -2,7 +2,7 @@ from mitmproxy.test import tflow
|
||||
from mitmproxy.net.http import http1
|
||||
from mitmproxy.net.tcp import TCPClient
|
||||
from mitmproxy.test.tutils import treq
|
||||
from .. import tservers
|
||||
from ... import tservers
|
||||
|
||||
|
||||
class TestHTTPFlow:
|
@ -11,12 +11,12 @@ from mitmproxy import options
|
||||
from mitmproxy.proxy.config import ProxyConfig
|
||||
|
||||
import mitmproxy.net
|
||||
from ...mitmproxy.net import tservers as net_tservers
|
||||
from ....mitmproxy.net import tservers as net_tservers
|
||||
from mitmproxy import exceptions
|
||||
from mitmproxy.net.http import http1, http2
|
||||
|
||||
from .. import tservers
|
||||
from ...conftest import requires_alpn
|
||||
from ... import tservers
|
||||
from ....conftest import requires_alpn
|
||||
|
||||
import logging
|
||||
logging.getLogger("hyper.packages.hpack.hpack").setLevel(logging.WARNING)
|
1
test/mitmproxy/proxy/protocol/test_http_replay.py
Normal file
1
test/mitmproxy/proxy/protocol/test_http_replay.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/proxy/protocol/test_rawtcp.py
Normal file
1
test/mitmproxy/proxy/protocol/test_rawtcp.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
@ -9,17 +9,17 @@ from mitmproxy.http import HTTPFlow
|
||||
from mitmproxy.websocket import WebSocketFlow
|
||||
from mitmproxy.proxy.config import ProxyConfig
|
||||
|
||||
import mitmproxy.net
|
||||
from mitmproxy.net import tcp
|
||||
from mitmproxy.net import http
|
||||
from ...mitmproxy.net import tservers as net_tservers
|
||||
from .. import tservers
|
||||
from ....mitmproxy.net import tservers as net_tservers
|
||||
from ... import tservers
|
||||
|
||||
from mitmproxy.net import websockets
|
||||
|
||||
|
||||
class _WebSocketServerBase(net_tservers.ServerTestBase):
|
||||
|
||||
class handler(mitmproxy.net.tcp.BaseHandler):
|
||||
class handler(tcp.BaseHandler):
|
||||
|
||||
def handle(self):
|
||||
try:
|
||||
@ -80,7 +80,7 @@ class _WebSocketTestBase:
|
||||
self.server.server.handle_websockets = self.handle_websockets
|
||||
|
||||
def _setup_connection(self):
|
||||
client = mitmproxy.net.tcp.TCPClient(("127.0.0.1", self.proxy.port))
|
||||
client = tcp.TCPClient(("127.0.0.1", self.proxy.port))
|
||||
client.connect()
|
||||
|
||||
request = http.Request(
|
1
test/mitmproxy/proxy/test_root_context.py
Normal file
1
test/mitmproxy/proxy/test_root_context.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
@ -21,8 +21,8 @@ from mitmproxy.net.tcp import Address
|
||||
from pathod import pathoc
|
||||
from pathod import pathod
|
||||
|
||||
from . import tservers
|
||||
from ..conftest import skip_appveyor
|
||||
from .. import tservers
|
||||
from ...conftest import skip_appveyor
|
||||
|
||||
|
||||
"""
|
1
test/mitmproxy/test_connections.py
Normal file
1
test/mitmproxy/test_connections.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/test_ctx.py
Normal file
1
test/mitmproxy/test_ctx.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/test_exceptions.py
Normal file
1
test/mitmproxy/test_exceptions.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/test_http.py
Normal file
1
test/mitmproxy/test_http.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/test_io.py
Normal file
1
test/mitmproxy/test_io.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/test_log.py
Normal file
1
test/mitmproxy/test_log.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/test_master.py
Normal file
1
test/mitmproxy/test_master.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/test_options.py
Normal file
1
test/mitmproxy/test_options.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/test_tcp.py
Normal file
1
test/mitmproxy/test_tcp.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
1
test/mitmproxy/test_websocket.py
Normal file
1
test/mitmproxy/test_websocket.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
0
test/mitmproxy/tools/__init__.py
Normal file
0
test/mitmproxy/tools/__init__.py
Normal file
0
test/mitmproxy/tools/console/__init__.py
Normal file
0
test/mitmproxy/tools/console/__init__.py
Normal file
@ -1,7 +1,7 @@
|
||||
from mitmproxy.test import tflow
|
||||
from mitmproxy.tools.console import common
|
||||
|
||||
from ...conftest import skip_appveyor
|
||||
from ....conftest import skip_appveyor
|
||||
|
||||
|
||||
@skip_appveyor
|
@ -1,6 +1,6 @@
|
||||
import mitmproxy.tools.console.help as help
|
||||
|
||||
from ...conftest import skip_appveyor
|
||||
from ....conftest import skip_appveyor
|
||||
|
||||
|
||||
@skip_appveyor
|
@ -1,10 +1,10 @@
|
||||
from mitmproxy.test import tflow
|
||||
import mitmproxy.test.tutils
|
||||
from mitmproxy.test import tutils
|
||||
from mitmproxy.tools import console
|
||||
from mitmproxy import proxy
|
||||
from mitmproxy import options
|
||||
from mitmproxy.tools.console import common
|
||||
from .. import tservers
|
||||
from ... import tservers
|
||||
|
||||
|
||||
def test_format_keyvals():
|
||||
@ -45,12 +45,12 @@ class TestMaster(tservers.MasterTest):
|
||||
def test_intercept(self):
|
||||
"""regression test for https://github.com/mitmproxy/mitmproxy/issues/1605"""
|
||||
m = self.mkmaster(intercept="~b bar")
|
||||
f = tflow.tflow(req=mitmproxy.test.tutils.treq(content=b"foo"))
|
||||
f = tflow.tflow(req=tutils.treq(content=b"foo"))
|
||||
m.request(f)
|
||||
assert not m.view[0].intercepted
|
||||
f = tflow.tflow(req=mitmproxy.test.tutils.treq(content=b"bar"))
|
||||
f = tflow.tflow(req=tutils.treq(content=b"bar"))
|
||||
m.request(f)
|
||||
assert m.view[1].intercepted
|
||||
f = tflow.tflow(resp=mitmproxy.test.tutils.tresp(content=b"bar"))
|
||||
f = tflow.tflow(resp=tutils.tresp(content=b"bar"))
|
||||
m.request(f)
|
||||
assert m.view[2].intercepted
|
@ -1,6 +1,6 @@
|
||||
import mitmproxy.tools.console.palettes as palettes
|
||||
|
||||
from ...conftest import skip_appveyor
|
||||
from ....conftest import skip_appveyor
|
||||
|
||||
|
||||
@skip_appveyor
|
@ -8,7 +8,7 @@ from mitmproxy import controller
|
||||
from mitmproxy.tools import dump
|
||||
|
||||
from mitmproxy.test import tutils
|
||||
from . import tservers
|
||||
from .. import tservers
|
||||
|
||||
|
||||
class TestDumpMaster(tservers.MasterTest):
|
0
test/mitmproxy/tools/web/__init__.py
Normal file
0
test/mitmproxy/tools/web/__init__.py
Normal file
@ -3,7 +3,7 @@ from mitmproxy import proxy
|
||||
from mitmproxy import options
|
||||
from mitmproxy.proxy.config import ProxyConfig
|
||||
|
||||
from . import tservers
|
||||
from ... import tservers
|
||||
|
||||
|
||||
class TestWebMaster(tservers.MasterTest):
|
1
test/mitmproxy/utils/test_bits.py
Normal file
1
test/mitmproxy/utils/test_bits.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
0
test/pathod/language/__init__.py
Normal file
0
test/pathod/language/__init__.py
Normal file
1
test/pathod/language/test_exceptions.py
Normal file
1
test/pathod/language/test_exceptions.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
@ -4,7 +4,7 @@ import pytest
|
||||
from pathod import language
|
||||
from pathod.language import http, base
|
||||
|
||||
from . import tservers
|
||||
from .. import tservers
|
||||
|
||||
|
||||
def parse_request(s):
|
1
test/pathod/language/test_message.py
Normal file
1
test/pathod/language/test_message.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
@ -4,7 +4,7 @@ from pathod import language
|
||||
from pathod.language import websockets
|
||||
import mitmproxy.net.websockets
|
||||
|
||||
from . import tservers
|
||||
from .. import tservers
|
||||
|
||||
|
||||
def parse_request(s):
|
0
test/pathod/protocols/__init__.py
Normal file
0
test/pathod/protocols/__init__.py
Normal file
1
test/pathod/protocols/test_http.py
Normal file
1
test/pathod/protocols/test_http.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
@ -7,11 +7,11 @@ from mitmproxy.net import tcp, http
|
||||
from mitmproxy.net.http import http2
|
||||
from mitmproxy import exceptions
|
||||
|
||||
from ..mitmproxy.net import tservers as net_tservers
|
||||
from ...mitmproxy.net import tservers as net_tservers
|
||||
|
||||
from pathod.protocols.http2 import HTTP2StateProtocol, TCPHandler
|
||||
|
||||
from ..conftest import requires_alpn
|
||||
from ...conftest import requires_alpn
|
||||
|
||||
|
||||
class TestTCPHandlerWrapper:
|
1
test/pathod/protocols/test_websockets.py
Normal file
1
test/pathod/protocols/test_websockets.py
Normal file
@ -0,0 +1 @@
|
||||
# TODO: write tests
|
5
tox.ini
5
tox.ini
@ -29,9 +29,10 @@ commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html
|
||||
[testenv:lint]
|
||||
commands =
|
||||
mitmdump --version
|
||||
flake8 --jobs 8 --count mitmproxy pathod examples test release
|
||||
flake8 --jobs 8 mitmproxy pathod examples test release
|
||||
python3 test/filename_matching.py
|
||||
rstcheck README.rst
|
||||
mypy --silent-imports \
|
||||
mypy --ignore-missing-imports --follow-imports=skip \
|
||||
mitmproxy/addons/ \
|
||||
mitmproxy/addonmanager.py \
|
||||
mitmproxy/proxy/protocol/ \
|
||||
|
Loading…
Reference in New Issue
Block a user