Merge pull request #2026 from Kriechi/filename-matching

add filename-matching linter
This commit is contained in:
Thomas Kriechbaumer 2017-02-15 00:24:05 +01:00 committed by GitHub
commit bb2fa6dc7d
78 changed files with 114 additions and 39 deletions

57
test/filename_matching.py Normal file
View 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()

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -1,6 +1,6 @@
from mitmproxy.contentviews import image from mitmproxy.contentviews import image
from mitmproxy.test import tutils from mitmproxy.test import tutils
from . import full_eval from .. import full_eval
def test_view_image(): def test_view_image():

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -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()

View File

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -2,7 +2,7 @@ from mitmproxy.test import tflow
from mitmproxy.net.http import http1 from mitmproxy.net.http import http1
from mitmproxy.net.tcp import TCPClient from mitmproxy.net.tcp import TCPClient
from mitmproxy.test.tutils import treq from mitmproxy.test.tutils import treq
from .. import tservers from ... import tservers
class TestHTTPFlow: class TestHTTPFlow:

View File

@ -11,12 +11,12 @@ from mitmproxy import options
from mitmproxy.proxy.config import ProxyConfig from mitmproxy.proxy.config import ProxyConfig
import mitmproxy.net 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 import exceptions
from mitmproxy.net.http import http1, http2 from mitmproxy.net.http import http1, http2
from .. import tservers from ... import tservers
from ...conftest import requires_alpn from ....conftest import requires_alpn
import logging import logging
logging.getLogger("hyper.packages.hpack.hpack").setLevel(logging.WARNING) logging.getLogger("hyper.packages.hpack.hpack").setLevel(logging.WARNING)

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -9,17 +9,17 @@ from mitmproxy.http import HTTPFlow
from mitmproxy.websocket import WebSocketFlow from mitmproxy.websocket import WebSocketFlow
from mitmproxy.proxy.config import ProxyConfig from mitmproxy.proxy.config import ProxyConfig
import mitmproxy.net from mitmproxy.net import tcp
from mitmproxy.net import http from mitmproxy.net import http
from ...mitmproxy.net import tservers as net_tservers from ....mitmproxy.net import tservers as net_tservers
from .. import tservers from ... import tservers
from mitmproxy.net import websockets from mitmproxy.net import websockets
class _WebSocketServerBase(net_tservers.ServerTestBase): class _WebSocketServerBase(net_tservers.ServerTestBase):
class handler(mitmproxy.net.tcp.BaseHandler): class handler(tcp.BaseHandler):
def handle(self): def handle(self):
try: try:
@ -80,7 +80,7 @@ class _WebSocketTestBase:
self.server.server.handle_websockets = self.handle_websockets self.server.server.handle_websockets = self.handle_websockets
def _setup_connection(self): 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() client.connect()
request = http.Request( request = http.Request(

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -21,8 +21,8 @@ from mitmproxy.net.tcp import Address
from pathod import pathoc from pathod import pathoc
from pathod import pathod from pathod import pathod
from . import tservers from .. import tservers
from ..conftest import skip_appveyor from ...conftest import skip_appveyor
""" """

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -0,0 +1 @@
# TODO: write tests

View File

View File

View File

@ -1,7 +1,7 @@
from mitmproxy.test import tflow from mitmproxy.test import tflow
from mitmproxy.tools.console import common from mitmproxy.tools.console import common
from ...conftest import skip_appveyor from ....conftest import skip_appveyor
@skip_appveyor @skip_appveyor

View File

@ -1,6 +1,6 @@
import mitmproxy.tools.console.help as help import mitmproxy.tools.console.help as help
from ...conftest import skip_appveyor from ....conftest import skip_appveyor
@skip_appveyor @skip_appveyor

View File

@ -1,10 +1,10 @@
from mitmproxy.test import tflow from mitmproxy.test import tflow
import mitmproxy.test.tutils from mitmproxy.test import tutils
from mitmproxy.tools import console from mitmproxy.tools import console
from mitmproxy import proxy from mitmproxy import proxy
from mitmproxy import options from mitmproxy import options
from mitmproxy.tools.console import common from mitmproxy.tools.console import common
from .. import tservers from ... import tservers
def test_format_keyvals(): def test_format_keyvals():
@ -45,12 +45,12 @@ class TestMaster(tservers.MasterTest):
def test_intercept(self): def test_intercept(self):
"""regression test for https://github.com/mitmproxy/mitmproxy/issues/1605""" """regression test for https://github.com/mitmproxy/mitmproxy/issues/1605"""
m = self.mkmaster(intercept="~b bar") 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) m.request(f)
assert not m.view[0].intercepted 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) m.request(f)
assert m.view[1].intercepted 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) m.request(f)
assert m.view[2].intercepted assert m.view[2].intercepted

View File

@ -1,6 +1,6 @@
import mitmproxy.tools.console.palettes as palettes import mitmproxy.tools.console.palettes as palettes
from ...conftest import skip_appveyor from ....conftest import skip_appveyor
@skip_appveyor @skip_appveyor

View File

@ -8,7 +8,7 @@ from mitmproxy import controller
from mitmproxy.tools import dump from mitmproxy.tools import dump
from mitmproxy.test import tutils from mitmproxy.test import tutils
from . import tservers from .. import tservers
class TestDumpMaster(tservers.MasterTest): class TestDumpMaster(tservers.MasterTest):

View File

View File

@ -3,7 +3,7 @@ from mitmproxy import proxy
from mitmproxy import options from mitmproxy import options
from mitmproxy.proxy.config import ProxyConfig from mitmproxy.proxy.config import ProxyConfig
from . import tservers from ... import tservers
class TestWebMaster(tservers.MasterTest): class TestWebMaster(tservers.MasterTest):

View File

@ -0,0 +1 @@
# TODO: write tests

View File

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -4,7 +4,7 @@ import pytest
from pathod import language from pathod import language
from pathod.language import http, base from pathod.language import http, base
from . import tservers from .. import tservers
def parse_request(s): def parse_request(s):

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -4,7 +4,7 @@ from pathod import language
from pathod.language import websockets from pathod.language import websockets
import mitmproxy.net.websockets import mitmproxy.net.websockets
from . import tservers from .. import tservers
def parse_request(s): def parse_request(s):

View File

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -7,11 +7,11 @@ from mitmproxy.net import tcp, http
from mitmproxy.net.http import http2 from mitmproxy.net.http import http2
from mitmproxy import exceptions 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 pathod.protocols.http2 import HTTP2StateProtocol, TCPHandler
from ..conftest import requires_alpn from ...conftest import requires_alpn
class TestTCPHandlerWrapper: class TestTCPHandlerWrapper:

View File

@ -0,0 +1 @@
# TODO: write tests

View File

@ -29,9 +29,10 @@ commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html
[testenv:lint] [testenv:lint]
commands = commands =
mitmdump --version 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 rstcheck README.rst
mypy --silent-imports \ mypy --ignore-missing-imports --follow-imports=skip \
mitmproxy/addons/ \ mitmproxy/addons/ \
mitmproxy/addonmanager.py \ mitmproxy/addonmanager.py \
mitmproxy/proxy/protocol/ \ mitmproxy/proxy/protocol/ \