aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2016-05-29 13:33:20 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2016-05-29 13:43:20 +0200
commite2447406cc89c5a9c3e20f1faf4f5bb9fd2f55b7 (patch)
treeb37af6f7e7658aa8d4851fde80928475840921f3
parent5c45ca7f9aba05849bd8db24bb58c1951f79e630 (diff)
downloadmitmproxy-e2447406cc89c5a9c3e20f1faf4f5bb9fd2f55b7.tar.gz
mitmproxy-e2447406cc89c5a9c3e20f1faf4f5bb9fd2f55b7.tar.bz2
mitmproxy-e2447406cc89c5a9c3e20f1faf4f5bb9fd2f55b7.zip
more style cleanup
-rw-r--r--.travis.yml2
-rw-r--r--mitmproxy/controller.py2
-rw-r--r--mitmproxy/version.py7
-rw-r--r--mitmproxy/web/app.py3
-rw-r--r--netlib/http/headers.py2
-rw-r--r--netlib/http/request.py4
-rw-r--r--netlib/websockets/__init__.py13
-rw-r--r--pathod/language/__init__.py8
-rw-r--r--pathod/language/exceptions.py1
-rw-r--r--pathod/protocols/__init__.py6
-rw-r--r--pathod/version.py7
-rw-r--r--setup.cfg4
-rw-r--r--test/mitmproxy/console/__init__.py0
-rw-r--r--test/mitmproxy/console/test_common.py (renamed from test/mitmproxy/test_console_common.py)9
-rw-r--r--test/mitmproxy/console/test_console.py (renamed from test/mitmproxy/test_console.py)2
-rw-r--r--test/mitmproxy/console/test_help.py (renamed from test/mitmproxy/test_console_help.py)7
-rw-r--r--test/mitmproxy/console/test_palettes.py (renamed from test/mitmproxy/test_console_palettes.py)6
-rw-r--r--test/mitmproxy/console/test_pathedit.py (renamed from test/mitmproxy/test_console_pathedit.py)2
-rw-r--r--test/mitmproxy/data/scripts/a.py (renamed from test/mitmproxy/scripts/a.py)0
-rw-r--r--test/mitmproxy/data/scripts/a_helper.py (renamed from test/mitmproxy/scripts/a_helper.py)0
-rw-r--r--test/mitmproxy/data/scripts/all.py (renamed from test/mitmproxy/scripts/all.py)0
-rw-r--r--test/mitmproxy/data/scripts/concurrent_decorator.py (renamed from test/mitmproxy/scripts/concurrent_decorator.py)1
-rw-r--r--test/mitmproxy/data/scripts/concurrent_decorator_err.py (renamed from test/mitmproxy/scripts/concurrent_decorator_err.py)0
-rw-r--r--test/mitmproxy/data/scripts/duplicate_flow.py (renamed from test/mitmproxy/scripts/duplicate_flow.py)0
-rw-r--r--test/mitmproxy/data/scripts/loaderr.py (renamed from test/mitmproxy/scripts/loaderr.py)0
-rw-r--r--test/mitmproxy/data/scripts/reqerr.py (renamed from test/mitmproxy/scripts/reqerr.py)0
-rw-r--r--test/mitmproxy/data/scripts/starterr.py (renamed from test/mitmproxy/scripts/starterr.py)0
-rw-r--r--test/mitmproxy/data/scripts/stream_modify.py (renamed from test/mitmproxy/scripts/stream_modify.py)0
-rw-r--r--test/mitmproxy/data/scripts/syntaxerr.py (renamed from test/mitmproxy/scripts/syntaxerr.py)0
-rw-r--r--test/mitmproxy/data/scripts/tcp_stream_modify.py (renamed from test/mitmproxy/scripts/tcp_stream_modify.py)0
-rw-r--r--test/mitmproxy/data/scripts/unloaderr.py (renamed from test/mitmproxy/scripts/unloaderr.py)0
-rw-r--r--test/mitmproxy/data/test_flow_export/locust_get.py (renamed from test/mitmproxy/test_flow_export/locust_get.py)0
-rw-r--r--test/mitmproxy/data/test_flow_export/locust_patch.py (renamed from test/mitmproxy/test_flow_export/locust_patch.py)0
-rw-r--r--test/mitmproxy/data/test_flow_export/locust_post.py (renamed from test/mitmproxy/test_flow_export/locust_post.py)0
-rw-r--r--test/mitmproxy/data/test_flow_export/locust_task_get.py (renamed from test/mitmproxy/test_flow_export/locust_task_get.py)0
-rw-r--r--test/mitmproxy/data/test_flow_export/locust_task_patch.py (renamed from test/mitmproxy/test_flow_export/locust_task_patch.py)0
-rw-r--r--test/mitmproxy/data/test_flow_export/locust_task_post.py (renamed from test/mitmproxy/test_flow_export/locust_task_post.py)0
-rw-r--r--test/mitmproxy/data/test_flow_export/python_get.py (renamed from test/mitmproxy/test_flow_export/python_get.py)0
-rw-r--r--test/mitmproxy/data/test_flow_export/python_patch.py (renamed from test/mitmproxy/test_flow_export/python_patch.py)0
-rw-r--r--test/mitmproxy/data/test_flow_export/python_post.py (renamed from test/mitmproxy/test_flow_export/python_post.py)0
-rw-r--r--test/mitmproxy/data/test_flow_export/python_post_json.py (renamed from test/mitmproxy/test_flow_export/python_post_json.py)0
-rw-r--r--test/mitmproxy/script/test_concurrent.py4
-rw-r--r--test/mitmproxy/script/test_script.py10
-rw-r--r--test/mitmproxy/test_app.py11
-rw-r--r--test/mitmproxy/test_dump.py2
-rw-r--r--test/mitmproxy/test_flow.py16
-rw-r--r--test/mitmproxy/test_flow_export.py33
-rw-r--r--test/mitmproxy/test_protocol_http2.py22
-rw-r--r--test/mitmproxy/test_proxy.py9
-rw-r--r--test/mitmproxy/test_script.py2
-rw-r--r--test/mitmproxy/test_server.py4
-rw-r--r--test/mitmproxy/tutils.py1
-rw-r--r--test/netlib/data/verificationcerts/generate.py2
-rw-r--r--test/netlib/http/test_authentication.py2
-rw-r--r--test/netlib/http/test_cookies.py2
-rw-r--r--test/netlib/http/test_response.py3
-rw-r--r--test/netlib/test_multidict.py2
-rw-r--r--test/netlib/test_tcp.py1
-rw-r--r--test/netlib/test_utils.py4
-rw-r--r--test/netlib/test_wsgi.py2
-rw-r--r--test/netlib/websockets/test_websockets.py4
-rw-r--r--test/pathod/test_language_actions.py4
-rw-r--r--test/pathod/test_language_base.py2
-rw-r--r--test/pathod/test_pathod.py10
64 files changed, 139 insertions, 99 deletions
diff --git a/.travis.yml b/.travis.yml
index a4af2152..fb579ac1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -46,7 +46,7 @@ install:
before_script:
- "openssl version -a"
- "python -c \"from OpenSSL import SSL; print(SSL.SSLeay_version(SSL.SSLEAY_VERSION))\""
- - "[[ $(flake8 -qq --count --exit-zero mitmproxy netlib pathod examples test) -le 71 ]]"
+ - "[[ $(flake8 -qq --count --exit-zero mitmproxy netlib pathod examples test) -le 12 ]]"
script:
- "py.test --timeout 60 --cov netlib --cov mitmproxy --cov pathod ./test/$SCOPE"
diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py
index 3afc70a8..e48f90e9 100644
--- a/mitmproxy/controller.py
+++ b/mitmproxy/controller.py
@@ -174,7 +174,7 @@ def handler(f):
raise exceptions.ControlException("Handler takes one argument: a message")
if not hasattr(message, "reply"):
- raise exceptions.ControlException("Message %s has no reply attribute"%message)
+ raise exceptions.ControlException("Message %s has no reply attribute" % message)
# The following ensures that inheritance with wrapped handlers in the
# base class works. If we're the first handler, then responsibility for
diff --git a/mitmproxy/version.py b/mitmproxy/version.py
index da1e7229..02b0d900 100644
--- a/mitmproxy/version.py
+++ b/mitmproxy/version.py
@@ -4,3 +4,10 @@ from netlib.version import VERSION, IVERSION
NAME = "mitmproxy"
NAMEVERSION = NAME + " " + VERSION
+
+__all__ = [
+ "NAME",
+ "NAMEVERSION",
+ "VERSION",
+ "IVERSION",
+]
diff --git a/mitmproxy/web/app.py b/mitmproxy/web/app.py
index 23a77cb0..df235ee1 100644
--- a/mitmproxy/web/app.py
+++ b/mitmproxy/web/app.py
@@ -112,7 +112,8 @@ class RequestHandler(BasicAuth, tornado.web.RequestHandler):
class IndexHandler(RequestHandler):
def get(self):
- _ = self.xsrf_token # https://github.com/tornadoweb/tornado/issues/645
+ token = self.xsrf_token # https://github.com/tornadoweb/tornado/issues/645
+ assert token
self.render("index.html")
diff --git a/netlib/http/headers.py b/netlib/http/headers.py
index 6067ff5e..5cf15b6f 100644
--- a/netlib/http/headers.py
+++ b/netlib/http/headers.py
@@ -97,7 +97,7 @@ class Headers(MultiDict):
headers = {
_always_bytes(name).replace(b"_", b"-"): _always_bytes(value)
for name, value in six.iteritems(headers)
- }
+ }
self.update(headers)
@staticmethod
diff --git a/netlib/http/request.py b/netlib/http/request.py
index a6e2a5ef..fa8d54aa 100644
--- a/netlib/http/request.py
+++ b/netlib/http/request.py
@@ -240,7 +240,7 @@ class Request(Message):
query = utils.urlencode(value)
scheme, netloc, path, params, _, fragment = urllib.parse.urlparse(self.url)
_, _, _, self.path = utils.parse_url(
- urllib.parse.urlunparse([scheme, netloc, path, params, query, fragment]))
+ urllib.parse.urlunparse([scheme, netloc, path, params, query, fragment]))
@query.setter
def query(self, value):
@@ -288,7 +288,7 @@ class Request(Message):
path = "/" + "/".join(components)
scheme, netloc, _, params, query, fragment = urllib.parse.urlparse(self.url)
_, _, _, self.path = utils.parse_url(
- urllib.parse.urlunparse([scheme, netloc, path, params, query, fragment]))
+ urllib.parse.urlunparse([scheme, netloc, path, params, query, fragment]))
def anticache(self):
"""
diff --git a/netlib/websockets/__init__.py b/netlib/websockets/__init__.py
index 1c143919..fea696d9 100644
--- a/netlib/websockets/__init__.py
+++ b/netlib/websockets/__init__.py
@@ -1,2 +1,11 @@
-from .frame import *
-from .protocol import *
+from __future__ import absolute_import, print_function, division
+from .frame import FrameHeader, Frame, OPCODE
+from .protocol import Masker, WebsocketsProtocol
+
+__all__ = [
+ "FrameHeader",
+ "Frame",
+ "Masker",
+ "WebsocketsProtocol",
+ "OPCODE",
+]
diff --git a/pathod/language/__init__.py b/pathod/language/__init__.py
index 10da93ba..399baa3e 100644
--- a/pathod/language/__init__.py
+++ b/pathod/language/__init__.py
@@ -7,9 +7,13 @@ import pyparsing as pp
from . import http, http2, websockets, writer, exceptions
-from .exceptions import *
+from .exceptions import RenderError, FileAccessDenied, ParseException
from .base import Settings
-assert Settings # prevent pyflakes from messing with this
+
+__all__ = [
+ "RenderError", "FileAccessDenied", "ParseException",
+ "Settings",
+]
def expand(msg):
diff --git a/pathod/language/exceptions.py b/pathod/language/exceptions.py
index 84ad3c02..eb22bed2 100644
--- a/pathod/language/exceptions.py
+++ b/pathod/language/exceptions.py
@@ -1,4 +1,3 @@
-
class RenderError(Exception):
pass
diff --git a/pathod/protocols/__init__.py b/pathod/protocols/__init__.py
index 1a8c7dab..f8f3008f 100644
--- a/pathod/protocols/__init__.py
+++ b/pathod/protocols/__init__.py
@@ -1 +1,7 @@
from . import http, http2, websockets
+
+__all__ = [
+ "http",
+ "http2",
+ "websockets",
+]
diff --git a/pathod/version.py b/pathod/version.py
index 2da7637d..3441be92 100644
--- a/pathod/version.py
+++ b/pathod/version.py
@@ -4,3 +4,10 @@ from netlib.version import VERSION, IVERSION
NAME = "pathod"
NAMEVERSION = NAME + " " + VERSION
+
+__all__ = [
+ "NAME",
+ "NAMEVERSION",
+ "VERSION",
+ "IVERSION",
+]
diff --git a/setup.cfg b/setup.cfg
index 571f826f..908dbe48 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,8 +1,8 @@
[flake8]
-max-line-length = 130
+max-line-length = 140
max-complexity = 25
ignore = E251,C901
-exclude = mitmproxy/contrib/*
+exclude = mitmproxy/contrib/*,test/mitmproxy/data/*
[pytest]
testpaths = test
diff --git a/test/mitmproxy/console/__init__.py b/test/mitmproxy/console/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/mitmproxy/console/__init__.py
diff --git a/test/mitmproxy/test_console_common.py b/test/mitmproxy/console/test_common.py
index 219200e0..ac4e0209 100644
--- a/test/mitmproxy/test_console_common.py
+++ b/test/mitmproxy/console/test_common.py
@@ -1,13 +1,8 @@
-import os
-from unittest.case import SkipTest
-if os.name == "nt":
- raise SkipTest("Skipped on Windows.")
-
-
import mitmproxy.console.common as common
-from . import tutils
+from .. import tutils
+@tutils.skip_appveyor
def test_format_flow():
f = tutils.tflow(resp=True)
assert common.format_flow(f, True)
diff --git a/test/mitmproxy/test_console.py b/test/mitmproxy/console/test_console.py
index 58a812a6..b68dd811 100644
--- a/test/mitmproxy/test_console.py
+++ b/test/mitmproxy/console/test_console.py
@@ -4,7 +4,7 @@ import netlib.tutils
from mitmproxy import console
from mitmproxy.console import common
-from . import tutils
+from .. import tutils
class TestConsoleState:
diff --git a/test/mitmproxy/test_console_help.py b/test/mitmproxy/console/test_help.py
index 0589bd68..3c1cc57c 100644
--- a/test/mitmproxy/test_console_help.py
+++ b/test/mitmproxy/console/test_help.py
@@ -1,11 +1,8 @@
-import os
-from unittest.case import SkipTest
-if os.name == "nt":
- raise SkipTest("Skipped on Windows.")
-
import mitmproxy.console.help as help
+from .. import tutils
+@tutils.skip_appveyor
class TestHelp:
def test_helptext(self):
diff --git a/test/mitmproxy/test_console_palettes.py b/test/mitmproxy/console/test_palettes.py
index b5d84ddd..a99730fa 100644
--- a/test/mitmproxy/test_console_palettes.py
+++ b/test/mitmproxy/console/test_palettes.py
@@ -1,10 +1,8 @@
-import os
-from unittest.case import SkipTest
-if os.name == "nt":
- raise SkipTest("Skipped on Windows.")
import mitmproxy.console.palettes as palettes
+from .. import tutils
+@tutils.skip_appveyor
class TestPalette:
def test_helptext(self):
diff --git a/test/mitmproxy/test_console_pathedit.py b/test/mitmproxy/console/test_pathedit.py
index e2c27b7c..107a48ac 100644
--- a/test/mitmproxy/test_console_pathedit.py
+++ b/test/mitmproxy/console/test_pathedit.py
@@ -2,7 +2,7 @@ import os
from os.path import normpath
from mitmproxy.console import pathedit
-from . import tutils
+from .. import tutils
class TestPathCompleter:
diff --git a/test/mitmproxy/scripts/a.py b/test/mitmproxy/data/scripts/a.py
index d4272ac8..d4272ac8 100644
--- a/test/mitmproxy/scripts/a.py
+++ b/test/mitmproxy/data/scripts/a.py
diff --git a/test/mitmproxy/scripts/a_helper.py b/test/mitmproxy/data/scripts/a_helper.py
index e1f1c649..e1f1c649 100644
--- a/test/mitmproxy/scripts/a_helper.py
+++ b/test/mitmproxy/data/scripts/a_helper.py
diff --git a/test/mitmproxy/scripts/all.py b/test/mitmproxy/data/scripts/all.py
index dad2aade..dad2aade 100644
--- a/test/mitmproxy/scripts/all.py
+++ b/test/mitmproxy/data/scripts/all.py
diff --git a/test/mitmproxy/scripts/concurrent_decorator.py b/test/mitmproxy/data/scripts/concurrent_decorator.py
index cf3ab512..e017f605 100644
--- a/test/mitmproxy/scripts/concurrent_decorator.py
+++ b/test/mitmproxy/data/scripts/concurrent_decorator.py
@@ -1,6 +1,7 @@
import time
from mitmproxy.script import concurrent
+
@concurrent
def request(context, flow):
time.sleep(0.1)
diff --git a/test/mitmproxy/scripts/concurrent_decorator_err.py b/test/mitmproxy/data/scripts/concurrent_decorator_err.py
index 071b8889..071b8889 100644
--- a/test/mitmproxy/scripts/concurrent_decorator_err.py
+++ b/test/mitmproxy/data/scripts/concurrent_decorator_err.py
diff --git a/test/mitmproxy/scripts/duplicate_flow.py b/test/mitmproxy/data/scripts/duplicate_flow.py
index e13af786..e13af786 100644
--- a/test/mitmproxy/scripts/duplicate_flow.py
+++ b/test/mitmproxy/data/scripts/duplicate_flow.py
diff --git a/test/mitmproxy/scripts/loaderr.py b/test/mitmproxy/data/scripts/loaderr.py
index 8dc4d56d..8dc4d56d 100644
--- a/test/mitmproxy/scripts/loaderr.py
+++ b/test/mitmproxy/data/scripts/loaderr.py
diff --git a/test/mitmproxy/scripts/reqerr.py b/test/mitmproxy/data/scripts/reqerr.py
index e7c503a8..e7c503a8 100644
--- a/test/mitmproxy/scripts/reqerr.py
+++ b/test/mitmproxy/data/scripts/reqerr.py
diff --git a/test/mitmproxy/scripts/starterr.py b/test/mitmproxy/data/scripts/starterr.py
index b217bdfe..b217bdfe 100644
--- a/test/mitmproxy/scripts/starterr.py
+++ b/test/mitmproxy/data/scripts/starterr.py
diff --git a/test/mitmproxy/scripts/stream_modify.py b/test/mitmproxy/data/scripts/stream_modify.py
index e26d83f1..e26d83f1 100644
--- a/test/mitmproxy/scripts/stream_modify.py
+++ b/test/mitmproxy/data/scripts/stream_modify.py
diff --git a/test/mitmproxy/scripts/syntaxerr.py b/test/mitmproxy/data/scripts/syntaxerr.py
index 219d6b84..219d6b84 100644
--- a/test/mitmproxy/scripts/syntaxerr.py
+++ b/test/mitmproxy/data/scripts/syntaxerr.py
diff --git a/test/mitmproxy/scripts/tcp_stream_modify.py b/test/mitmproxy/data/scripts/tcp_stream_modify.py
index d7953ef9..d7953ef9 100644
--- a/test/mitmproxy/scripts/tcp_stream_modify.py
+++ b/test/mitmproxy/data/scripts/tcp_stream_modify.py
diff --git a/test/mitmproxy/scripts/unloaderr.py b/test/mitmproxy/data/scripts/unloaderr.py
index fba02734..fba02734 100644
--- a/test/mitmproxy/scripts/unloaderr.py
+++ b/test/mitmproxy/data/scripts/unloaderr.py
diff --git a/test/mitmproxy/test_flow_export/locust_get.py b/test/mitmproxy/data/test_flow_export/locust_get.py
index 632d5d53..632d5d53 100644
--- a/test/mitmproxy/test_flow_export/locust_get.py
+++ b/test/mitmproxy/data/test_flow_export/locust_get.py
diff --git a/test/mitmproxy/test_flow_export/locust_patch.py b/test/mitmproxy/data/test_flow_export/locust_patch.py
index f64e0857..f64e0857 100644
--- a/test/mitmproxy/test_flow_export/locust_patch.py
+++ b/test/mitmproxy/data/test_flow_export/locust_patch.py
diff --git a/test/mitmproxy/test_flow_export/locust_post.py b/test/mitmproxy/data/test_flow_export/locust_post.py
index df23476a..df23476a 100644
--- a/test/mitmproxy/test_flow_export/locust_post.py
+++ b/test/mitmproxy/data/test_flow_export/locust_post.py
diff --git a/test/mitmproxy/test_flow_export/locust_task_get.py b/test/mitmproxy/data/test_flow_export/locust_task_get.py
index 03821cd8..03821cd8 100644
--- a/test/mitmproxy/test_flow_export/locust_task_get.py
+++ b/test/mitmproxy/data/test_flow_export/locust_task_get.py
diff --git a/test/mitmproxy/test_flow_export/locust_task_patch.py b/test/mitmproxy/data/test_flow_export/locust_task_patch.py
index d425209c..d425209c 100644
--- a/test/mitmproxy/test_flow_export/locust_task_patch.py
+++ b/test/mitmproxy/data/test_flow_export/locust_task_patch.py
diff --git a/test/mitmproxy/test_flow_export/locust_task_post.py b/test/mitmproxy/data/test_flow_export/locust_task_post.py
index 989df455..989df455 100644
--- a/test/mitmproxy/test_flow_export/locust_task_post.py
+++ b/test/mitmproxy/data/test_flow_export/locust_task_post.py
diff --git a/test/mitmproxy/test_flow_export/python_get.py b/test/mitmproxy/data/test_flow_export/python_get.py
index af8f7c81..af8f7c81 100644
--- a/test/mitmproxy/test_flow_export/python_get.py
+++ b/test/mitmproxy/data/test_flow_export/python_get.py
diff --git a/test/mitmproxy/test_flow_export/python_patch.py b/test/mitmproxy/data/test_flow_export/python_patch.py
index 159e802f..159e802f 100644
--- a/test/mitmproxy/test_flow_export/python_patch.py
+++ b/test/mitmproxy/data/test_flow_export/python_patch.py
diff --git a/test/mitmproxy/test_flow_export/python_post.py b/test/mitmproxy/data/test_flow_export/python_post.py
index b13f6441..b13f6441 100644
--- a/test/mitmproxy/test_flow_export/python_post.py
+++ b/test/mitmproxy/data/test_flow_export/python_post.py
diff --git a/test/mitmproxy/test_flow_export/python_post_json.py b/test/mitmproxy/data/test_flow_export/python_post_json.py
index 7e105bf6..7e105bf6 100644
--- a/test/mitmproxy/test_flow_export/python_post_json.py
+++ b/test/mitmproxy/data/test_flow_export/python_post_json.py
diff --git a/test/mitmproxy/script/test_concurrent.py b/test/mitmproxy/script/test_concurrent.py
index a9c9e153..c2f169ad 100644
--- a/test/mitmproxy/script/test_concurrent.py
+++ b/test/mitmproxy/script/test_concurrent.py
@@ -11,7 +11,7 @@ class Dummy:
@tutils.skip_appveyor
def test_concurrent():
- with Script(tutils.test_data.path("scripts/concurrent_decorator.py"), None) as s:
+ with Script(tutils.test_data.path("data/scripts/concurrent_decorator.py"), None) as s:
def reply():
reply.acked.set()
reply.acked = Event()
@@ -27,6 +27,6 @@ def test_concurrent():
def test_concurrent_err():
- s = Script(tutils.test_data.path("scripts/concurrent_decorator_err.py"), None)
+ s = Script(tutils.test_data.path("data/scripts/concurrent_decorator_err.py"), None)
with tutils.raises("Concurrent decorator not supported for 'start' method"):
s.load()
diff --git a/test/mitmproxy/script/test_script.py b/test/mitmproxy/script/test_script.py
index a9b55977..b27e82c0 100644
--- a/test/mitmproxy/script/test_script.py
+++ b/test/mitmproxy/script/test_script.py
@@ -21,9 +21,9 @@ class TestParseCommand:
def test_parse_args(self):
with tutils.chdir(tutils.test_data.dirname):
- assert Script.parse_command("scripts/a.py") == ["scripts/a.py"]
- assert Script.parse_command("scripts/a.py foo bar") == ["scripts/a.py", "foo", "bar"]
- assert Script.parse_command("scripts/a.py 'foo bar'") == ["scripts/a.py", "foo bar"]
+ assert Script.parse_command("data/scripts/a.py") == ["data/scripts/a.py"]
+ assert Script.parse_command("data/scripts/a.py foo bar") == ["data/scripts/a.py", "foo", "bar"]
+ assert Script.parse_command("data/scripts/a.py 'foo bar'") == ["data/scripts/a.py", "foo bar"]
@tutils.skip_not_windows
def test_parse_windows(self):
@@ -33,7 +33,7 @@ class TestParseCommand:
def test_simple():
- with tutils.chdir(tutils.test_data.path("scripts")):
+ with tutils.chdir(tutils.test_data.path("data/scripts")):
s = Script("a.py --var 42", None)
assert s.filename == "a.py"
assert s.ns is None
@@ -55,7 +55,7 @@ def test_simple():
def test_script_exception():
- with tutils.chdir(tutils.test_data.path("scripts")):
+ with tutils.chdir(tutils.test_data.path("data/scripts")):
s = Script("syntaxerr.py", None)
with tutils.raises(ScriptException):
s.load()
diff --git a/test/mitmproxy/test_app.py b/test/mitmproxy/test_app.py
index 8d8ce271..4c9eff08 100644
--- a/test/mitmproxy/test_app.py
+++ b/test/mitmproxy/test_app.py
@@ -1,4 +1,4 @@
-from . import tutils, tservers
+from . import tservers
class TestApp(tservers.HTTPProxyTest):
@@ -7,8 +7,7 @@ class TestApp(tservers.HTTPProxyTest):
assert self.app("/").status_code == 200
def test_cert(self):
- with tutils.tmpdir() as d:
- for ext in ["pem", "p12"]:
- resp = self.app("/cert/%s" % ext)
- assert resp.status_code == 200
- assert resp.content
+ for ext in ["pem", "p12"]:
+ resp = self.app("/cert/%s" % ext)
+ assert resp.status_code == 200
+ assert resp.content
diff --git a/test/mitmproxy/test_dump.py b/test/mitmproxy/test_dump.py
index 7d625c34..36b78168 100644
--- a/test/mitmproxy/test_dump.py
+++ b/test/mitmproxy/test_dump.py
@@ -218,7 +218,7 @@ class TestDumpMaster:
def test_script(self):
ret = self._dummy_cycle(
1, None, "",
- scripts=[tutils.test_data.path("scripts/all.py")], verbosity=1
+ scripts=[tutils.test_data.path("data/scripts/all.py")], verbosity=1
)
assert "XCLIENTCONNECT" in ret
assert "XSERVERCONNECT" in ret
diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py
index b6debd17..1b1f03f9 100644
--- a/test/mitmproxy/test_flow.py
+++ b/test/mitmproxy/test_flow.py
@@ -761,13 +761,13 @@ class TestFlowMaster:
s = flow.State()
fm = flow.FlowMaster(None, s)
- fm.load_script(tutils.test_data.path("scripts/a.py"))
- fm.load_script(tutils.test_data.path("scripts/a.py"))
+ fm.load_script(tutils.test_data.path("data/scripts/a.py"))
+ fm.load_script(tutils.test_data.path("data/scripts/a.py"))
fm.unload_scripts()
with tutils.raises(ScriptException):
fm.load_script("nonexistent")
try:
- fm.load_script(tutils.test_data.path("scripts/starterr.py"))
+ fm.load_script(tutils.test_data.path("data/scripts/starterr.py"))
except ScriptException as e:
assert "ValueError" in str(e)
assert len(fm.scripts) == 0
@@ -796,7 +796,7 @@ class TestFlowMaster:
def test_script_reqerr(self):
s = flow.State()
fm = flow.FlowMaster(None, s)
- fm.load_script(tutils.test_data.path("scripts/reqerr.py"))
+ fm.load_script(tutils.test_data.path("data/scripts/reqerr.py"))
f = tutils.tflow()
fm.clientconnect(f.client_conn)
assert fm.request(f)
@@ -804,7 +804,7 @@ class TestFlowMaster:
def test_script(self):
s = flow.State()
fm = flow.FlowMaster(None, s)
- fm.load_script(tutils.test_data.path("scripts/all.py"))
+ fm.load_script(tutils.test_data.path("data/scripts/all.py"))
f = tutils.tflow(resp=True)
fm.clientconnect(f.client_conn)
@@ -816,7 +816,7 @@ class TestFlowMaster:
fm.response(f)
assert fm.scripts[0].ns["log"][-1] == "response"
# load second script
- fm.load_script(tutils.test_data.path("scripts/all.py"))
+ fm.load_script(tutils.test_data.path("data/scripts/all.py"))
assert len(fm.scripts) == 2
fm.clientdisconnect(f.server_conn)
assert fm.scripts[0].ns["log"][-1] == "clientdisconnect"
@@ -825,7 +825,7 @@ class TestFlowMaster:
# unload first script
fm.unload_scripts()
assert len(fm.scripts) == 0
- fm.load_script(tutils.test_data.path("scripts/all.py"))
+ fm.load_script(tutils.test_data.path("data/scripts/all.py"))
f.error = tutils.terr()
fm.error(f)
@@ -868,7 +868,7 @@ class TestFlowMaster:
f.error.reply = controller.DummyReply()
fm.error(f)
- fm.load_script(tutils.test_data.path("scripts/a.py"))
+ fm.load_script(tutils.test_data.path("data/scripts/a.py"))
fm.shutdown()
def test_client_playback(self):
diff --git a/test/mitmproxy/test_flow_export.py b/test/mitmproxy/test_flow_export.py
index af3713de..03405757 100644
--- a/test/mitmproxy/test_flow_export.py
+++ b/test/mitmproxy/test_flow_export.py
@@ -20,11 +20,16 @@ def python_equals(testdata, text):
assert clean_blanks(text).rstrip() == clean_blanks(d).rstrip()
-req_get = lambda: netlib.tutils.treq(method='GET', content='', path=b"/path?a=foo&a=bar&b=baz")
+def req_get():
+ return netlib.tutils.treq(method='GET', content='', path=b"/path?a=foo&a=bar&b=baz")
-req_post = lambda: netlib.tutils.treq(method='POST', headers=())
-req_patch = lambda: netlib.tutils.treq(method='PATCH', path=b"/path?query=param")
+def req_post():
+ return netlib.tutils.treq(method='POST', headers=())
+
+
+def req_patch():
+ return netlib.tutils.treq(method='PATCH', path=b"/path?query=param")
class TestExportCurlCommand():
@@ -47,22 +52,22 @@ class TestExportCurlCommand():
class TestExportPythonCode():
def test_get(self):
flow = tutils.tflow(req=req_get())
- python_equals("test_flow_export/python_get.py", flow_export.python_code(flow))
+ python_equals("data/test_flow_export/python_get.py", flow_export.python_code(flow))
def test_post(self):
flow = tutils.tflow(req=req_post())
- python_equals("test_flow_export/python_post.py", flow_export.python_code(flow))
+ python_equals("data/test_flow_export/python_post.py", flow_export.python_code(flow))
def test_post_json(self):
p = req_post()
p.content = '{"name": "example", "email": "example@example.com"}'
p.headers = Headers(content_type="application/json")
flow = tutils.tflow(req=p)
- python_equals("test_flow_export/python_post_json.py", flow_export.python_code(flow))
+ python_equals("data/test_flow_export/python_post_json.py", flow_export.python_code(flow))
def test_patch(self):
flow = tutils.tflow(req=req_patch())
- python_equals("test_flow_export/python_patch.py", flow_export.python_code(flow))
+ python_equals("data/test_flow_export/python_patch.py", flow_export.python_code(flow))
class TestRawRequest():
@@ -103,32 +108,32 @@ class TestRawRequest():
class TestExportLocustCode():
def test_get(self):
flow = tutils.tflow(req=req_get())
- python_equals("test_flow_export/locust_get.py", flow_export.locust_code(flow))
+ python_equals("data/test_flow_export/locust_get.py", flow_export.locust_code(flow))
def test_post(self):
p = req_post()
p.content = '''content'''
p.headers = ''
flow = tutils.tflow(req=p)
- python_equals("test_flow_export/locust_post.py", flow_export.locust_code(flow))
+ python_equals("data/test_flow_export/locust_post.py", flow_export.locust_code(flow))
def test_patch(self):
flow = tutils.tflow(req=req_patch())
- python_equals("test_flow_export/locust_patch.py", flow_export.locust_code(flow))
+ python_equals("data/test_flow_export/locust_patch.py", flow_export.locust_code(flow))
class TestExportLocustTask():
def test_get(self):
flow = tutils.tflow(req=req_get())
- python_equals("test_flow_export/locust_task_get.py", flow_export.locust_task(flow))
+ python_equals("data/test_flow_export/locust_task_get.py", flow_export.locust_task(flow))
def test_post(self):
flow = tutils.tflow(req=req_post())
- python_equals("test_flow_export/locust_task_post.py", flow_export.locust_task(flow))
+ python_equals("data/test_flow_export/locust_task_post.py", flow_export.locust_task(flow))
def test_patch(self):
flow = tutils.tflow(req=req_patch())
- python_equals("test_flow_export/locust_task_patch.py", flow_export.locust_task(flow))
+ python_equals("data/test_flow_export/locust_task_patch.py", flow_export.locust_task(flow))
class TestIsJson():
@@ -144,7 +149,7 @@ class TestIsJson():
j = flow_export.is_json(headers, '{"name": "example", "email": "example@example.com"}')
assert j is False
- def test_valid(self):
+ def test_valid2(self):
headers = Headers(content_type="application/json")
j = flow_export.is_json(headers, '{"name": "example", "email": "example@example.com"}')
assert isinstance(j, dict)
diff --git a/test/mitmproxy/test_protocol_http2.py b/test/mitmproxy/test_protocol_http2.py
index ee7ccd45..07f67b74 100644
--- a/test/mitmproxy/test_protocol_http2.py
+++ b/test/mitmproxy/test_protocol_http2.py
@@ -164,12 +164,21 @@ class TestSimple(_Http2TestBase, _Http2ServerBase):
assert ('client-foo', 'client-bar-1') in event.headers
assert ('client-foo', 'client-bar-2') in event.headers
- h2_conn.send_headers(event.stream_id, [
- (':status', '200'),
- ('server-foo', 'server-bar'),
- ('föo', 'bär'),
- ('X-Stream-ID', str(event.stream_id)),
- ])
+ import warnings
+ with warnings.catch_warnings():
+ # Ignore UnicodeWarning:
+ # h2/utilities.py:64: UnicodeWarning: Unicode equal comparison
+ # failed to convert both arguments to Unicode - interpreting
+ # them as being unequal.
+ # elif header[0] in (b'cookie', u'cookie') and len(header[1]) < 20:
+
+ warnings.simplefilter("ignore")
+ h2_conn.send_headers(event.stream_id, [
+ (':status', '200'),
+ ('server-foo', 'server-bar'),
+ ('föo', 'bär'),
+ ('X-Stream-ID', str(event.stream_id)),
+ ])
h2_conn.send_data(event.stream_id, b'foobar')
h2_conn.end_stream(event.stream_id)
wfile.write(h2_conn.data_to_send())
@@ -434,6 +443,7 @@ class TestPushPromise(_Http2TestBase, _Http2ServerBase):
assert b'regular_stream' in bodies
# the other two bodies might not be transmitted before the reset
+
@requires_alpn
class TestConnectionLost(_Http2TestBase, _Http2ServerBase):
diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py
index e0897135..49c9c909 100644
--- a/test/mitmproxy/test_proxy.py
+++ b/test/mitmproxy/test_proxy.py
@@ -113,11 +113,10 @@ class TestProcessProxyOptions:
"nonexistent")
def test_certs(self):
- with tutils.tmpdir() as cadir:
- self.assert_noerr(
- "--cert",
- tutils.test_data.path("data/testkey.pem"))
- self.assert_err("does not exist", "--cert", "nonexistent")
+ self.assert_noerr(
+ "--cert",
+ tutils.test_data.path("data/testkey.pem"))
+ self.assert_err("does not exist", "--cert", "nonexistent")
def test_auth(self):
p = self.assert_noerr("--nonanonymous")
diff --git a/test/mitmproxy/test_script.py b/test/mitmproxy/test_script.py
index dd6f51ae..81994780 100644
--- a/test/mitmproxy/test_script.py
+++ b/test/mitmproxy/test_script.py
@@ -5,7 +5,7 @@ from . import tutils
def test_duplicate_flow():
s = flow.State()
fm = flow.FlowMaster(None, s)
- fm.load_script(tutils.test_data.path("scripts/duplicate_flow.py"))
+ fm.load_script(tutils.test_data.path("data/scripts/duplicate_flow.py"))
f = tutils.tflow()
fm.request(f)
assert fm.state.flow_count() == 2
diff --git a/test/mitmproxy/test_server.py b/test/mitmproxy/test_server.py
index bb4949e1..b58c4f44 100644
--- a/test/mitmproxy/test_server.py
+++ b/test/mitmproxy/test_server.py
@@ -286,7 +286,7 @@ class TestHTTP(tservers.HTTPProxyTest, CommonMixin, AppMixin):
self.master.set_stream_large_bodies(None)
def test_stream_modify(self):
- self.master.load_script(tutils.test_data.path("scripts/stream_modify.py"))
+ self.master.load_script(tutils.test_data.path("data/scripts/stream_modify.py"))
d = self.pathod('200:b"foo"')
assert d.content == "bar"
self.master.unload_scripts()
@@ -511,7 +511,7 @@ class TestTransparent(tservers.TransparentProxyTest, CommonMixin, TcpMixin):
ssl = False
def test_tcp_stream_modify(self):
- self.master.load_script(tutils.test_data.path("scripts/tcp_stream_modify.py"))
+ self.master.load_script(tutils.test_data.path("data/scripts/tcp_stream_modify.py"))
self._tcpproxy_on()
d = self.pathod('200:b"foo"')
diff --git a/test/mitmproxy/tutils.py b/test/mitmproxy/tutils.py
index c1b258a2..d0a09035 100644
--- a/test/mitmproxy/tutils.py
+++ b/test/mitmproxy/tutils.py
@@ -156,6 +156,7 @@ def chdir(dir):
yield
os.chdir(orig_dir)
+
@contextmanager
def tmpdir(*args, **kwargs):
temp_workdir = tempfile.mkdtemp(*args, **kwargs)
diff --git a/test/netlib/data/verificationcerts/generate.py b/test/netlib/data/verificationcerts/generate.py
index 9203abbb..6d4d8550 100644
--- a/test/netlib/data/verificationcerts/generate.py
+++ b/test/netlib/data/verificationcerts/generate.py
@@ -64,5 +64,3 @@ do("openssl req -x509 -new -nodes -batch "
"-days 1024 "
"-out self-signed.crt".format(SUBJECT)
)
-
-
diff --git a/test/netlib/http/test_authentication.py b/test/netlib/http/test_authentication.py
index 1df7cd9c..95d72447 100644
--- a/test/netlib/http/test_authentication.py
+++ b/test/netlib/http/test_authentication.py
@@ -78,7 +78,7 @@ class TestBasicProxyAuth:
assert ba.authenticate(headers)
ba.clean(headers)
- assert not ba.AUTH_HEADER in headers
+ assert ba.AUTH_HEADER not in headers
headers[ba.AUTH_HEADER] = ""
assert not ba.authenticate(headers)
diff --git a/test/netlib/http/test_cookies.py b/test/netlib/http/test_cookies.py
index 6f84c4ce..83b85656 100644
--- a/test/netlib/http/test_cookies.py
+++ b/test/netlib/http/test_cookies.py
@@ -184,7 +184,7 @@ def test_parse_set_cookie_pairs():
assert ret == lst
s2 = cookies._format_set_cookie_pairs(ret)
ret2 = cookies._parse_set_cookie_pairs(s2)
- assert ret2 == lst
+ assert ret2 == lst
def test_parse_set_cookie_header():
diff --git a/test/netlib/http/test_response.py b/test/netlib/http/test_response.py
index 5eac2a15..1faef7ec 100644
--- a/test/netlib/http/test_response.py
+++ b/test/netlib/http/test_response.py
@@ -59,7 +59,8 @@ class TestResponseUtils(object):
def test_get_cookies_with_parameters(self):
resp = tresp()
- resp.headers = Headers(set_cookie="cookiename=cookievalue;domain=example.com;expires=Wed Oct 21 16:29:41 2015;path=/; HttpOnly")
+ cookie = "cookiename=cookievalue;domain=example.com;expires=Wed Oct 21 16:29:41 2015;path=/; HttpOnly"
+ resp.headers = Headers(set_cookie=cookie)
result = resp.cookies
assert len(result) == 1
assert "cookiename" in result
diff --git a/test/netlib/test_multidict.py b/test/netlib/test_multidict.py
index 5bb65e3f..7319f1c5 100644
--- a/test/netlib/test_multidict.py
+++ b/test/netlib/test_multidict.py
@@ -49,7 +49,7 @@ class TestMultiDict(object):
assert md["foo"] == "bar"
with tutils.raises(KeyError):
- _ = md["bar"]
+ md["bar"]
md_multi = TMultiDict(
[("foo", "a"), ("foo", "b")]
diff --git a/test/netlib/test_tcp.py b/test/netlib/test_tcp.py
index 80cdba36..083360b4 100644
--- a/test/netlib/test_tcp.py
+++ b/test/netlib/test_tcp.py
@@ -15,6 +15,7 @@ from netlib.exceptions import InvalidCertificateException, TcpReadIncomplete, Tl
from . import tservers
+
class EchoHandler(tcp.BaseHandler):
sni = None
diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py
index fce1d0a7..e4c81a48 100644
--- a/test/netlib/test_utils.py
+++ b/test/netlib/test_utils.py
@@ -1,7 +1,9 @@
# coding=utf-8
+
from netlib import utils, tutils
from netlib.http import Headers
+
def test_bidi():
b = utils.BiDi(a=1, b=2)
assert b.a == 1
@@ -189,4 +191,4 @@ def test_escaped_str_to_bytes():
assert utils.escaped_str_to_bytes("ü") == b'\xc3\xbc'
assert utils.escaped_str_to_bytes(u"\\x08") == b"\b"
assert utils.escaped_str_to_bytes(u"&!?=\\\\)") == br"&!?=\)"
- assert utils.escaped_str_to_bytes(u"ü") == b'\xc3\xbc' \ No newline at end of file
+ assert utils.escaped_str_to_bytes(u"ü") == b'\xc3\xbc'
diff --git a/test/netlib/test_wsgi.py b/test/netlib/test_wsgi.py
index 8c782b27..5c61f81c 100644
--- a/test/netlib/test_wsgi.py
+++ b/test/netlib/test_wsgi.py
@@ -11,7 +11,7 @@ def tflow():
class ExampleApp:
-
+
def __init__(self):
self.called = False
diff --git a/test/netlib/websockets/test_websockets.py b/test/netlib/websockets/test_websockets.py
index 024544f5..50fa26e6 100644
--- a/test/netlib/websockets/test_websockets.py
+++ b/test/netlib/websockets/test_websockets.py
@@ -120,8 +120,8 @@ class TestWebSockets(tservers.ServerTestBase):
default builder should always generate valid frames
"""
msg = self.random_bytes()
- client_frame = websockets.Frame.default(msg, from_client=True)
- server_frame = websockets.Frame.default(msg, from_client=False)
+ assert websockets.Frame.default(msg, from_client=True)
+ assert websockets.Frame.default(msg, from_client=False)
def test_serialization_bijection(self):
"""
diff --git a/test/pathod/test_language_actions.py b/test/pathod/test_language_actions.py
index c2e15189..81d2155d 100644
--- a/test/pathod/test_language_actions.py
+++ b/test/pathod/test_language_actions.py
@@ -68,9 +68,9 @@ class TestInject:
def test_spec(self):
e = actions.InjectAt.expr()
v = e.parseString("i0,'foo'")[0]
- assert v.spec() == 'i0,"foo"'
+ assert v.spec() == "i0,'foo'"
- def test_spec(self):
+ def test_spec2(self):
e = actions.InjectAt.expr()
v = e.parseString("i0,@100")[0]
v2 = v.freeze({})
diff --git a/test/pathod/test_language_base.py b/test/pathod/test_language_base.py
index 2e5d9041..22355a3a 100644
--- a/test/pathod/test_language_base.py
+++ b/test/pathod/test_language_base.py
@@ -178,7 +178,7 @@ class TestMisc:
assert base.TokValue.parseString('"val"')[0].val == "val"
assert base.TokValue.parseString('"\'val\'"')[0].val == "'val'"
- def test_value(self):
+ def test_value2(self):
class TT(base.Value):
preamble = "m"
e = TT.expr()
diff --git a/test/pathod/test_pathod.py b/test/pathod/test_pathod.py
index 13b36e36..4d969158 100644
--- a/test/pathod/test_pathod.py
+++ b/test/pathod/test_pathod.py
@@ -51,7 +51,7 @@ class TestNoApi(tutils.DaemonTests):
assert self.getpath("/log").status_code == 404
r = self.getpath("/")
assert r.status_code == 200
- assert not "Log" in r.content
+ assert "Log" not in r.content
class TestNotAfterConnect(tutils.DaemonTests):
@@ -110,7 +110,7 @@ class TestHexdump(tutils.DaemonTests):
hexdump = True
def test_hexdump(self):
- r = self.get(r"200:b'\xf0'")
+ assert self.get(r"200:b'\xf0'")
class TestNocraft(tutils.DaemonTests):
@@ -125,8 +125,8 @@ class TestNocraft(tutils.DaemonTests):
class CommonTests(tutils.DaemonTests):
def test_binarydata(self):
- r = self.get(r"200:b'\xf0'")
- l = self.d.last_log()
+ assert self.get(r"200:b'\xf0'")
+ assert self.d.last_log()
# FIXME: Other binary data elements
@pytest.mark.skip(reason="race condition")
@@ -147,7 +147,7 @@ class CommonTests(tutils.DaemonTests):
def test_logs(self):
assert self.d.clear_log()
assert not self.d.last_log()
- rsp = self.get("202:da")
+ assert self.get("202:da")
assert len(self.d.log()) == 1
assert self.d.clear_log()
assert len(self.d.log()) == 0