diff options
author | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2017-02-01 16:17:22 +0100 |
---|---|---|
committer | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2017-02-02 12:59:01 +0100 |
commit | ec92d7f67e3c5960d9b30e067fb4ed1ae3fc8884 (patch) | |
tree | 22f48c7eab85ee2e58ac8e7127e198155dbeb62f /test | |
parent | c1bc1ea584d4bb47c1b754dfa7f10ab4dfc380a3 (diff) | |
download | mitmproxy-ec92d7f67e3c5960d9b30e067fb4ed1ae3fc8884.tar.gz mitmproxy-ec92d7f67e3c5960d9b30e067fb4ed1ae3fc8884.tar.bz2 mitmproxy-ec92d7f67e3c5960d9b30e067fb4ed1ae3fc8884.zip |
cleanup test utils
Diffstat (limited to 'test')
-rw-r--r-- | test/conftest.py | 15 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_script.py | 8 | ||||
-rw-r--r-- | test/mitmproxy/console/test_common.py | 5 | ||||
-rw-r--r-- | test/mitmproxy/console/test_help.py | 5 | ||||
-rw-r--r-- | test/mitmproxy/console/test_palettes.py | 5 | ||||
-rw-r--r-- | test/mitmproxy/test_flowfilter.py | 5 | ||||
-rw-r--r-- | test/mitmproxy/test_proxy.py | 13 | ||||
-rw-r--r-- | test/mitmproxy/test_server.py | 8 | ||||
-rw-r--r-- | test/mitmproxy/tutils.py | 68 |
9 files changed, 40 insertions, 92 deletions
diff --git a/test/conftest.py b/test/conftest.py index 4d779b01..3f623c51 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -9,6 +9,21 @@ requires_alpn = pytest.mark.skipif( not mitmproxy.net.tcp.HAS_ALPN, reason='requires OpenSSL with ALPN support') +skip_windows = pytest.mark.skipif( + os.name == "nt", + reason='Skipping due to Windows' +) + +skip_not_windows = pytest.mark.skipif( + os.name != "nt", + reason='Skipping due to not Windows' +) + +skip_appveyor = pytest.mark.skipif( + "APPVEYOR" in os.environ, + reason='Skipping due to Appveyor' +) + @pytest.fixture() def disable_alpn(monkeypatch): diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py index f578867d..ad0c41c3 100644 --- a/test/mitmproxy/addons/test_script.py +++ b/test/mitmproxy/addons/test_script.py @@ -2,6 +2,7 @@ import traceback import sys import time import re +import watchdog.events from mitmproxy.test import tflow from mitmproxy.test import tutils @@ -11,12 +12,9 @@ from mitmproxy import options from mitmproxy import proxy from mitmproxy import master from mitmproxy import utils - from mitmproxy.addons import script -import watchdog.events - -from .. import tutils as ttutils +from ...conftest import skip_not_windows def test_scriptenv(): @@ -84,7 +82,7 @@ class TestParseCommand: "mitmproxy/data/addonscripts/recorder.py 'foo bar'" ) == ("mitmproxy/data/addonscripts/recorder.py", ["foo bar"]) - @ttutils.skip_not_windows + @skip_not_windows def test_parse_windows(self): with utils.chdir(tutils.test_data.dirname): assert script.parse_command( diff --git a/test/mitmproxy/console/test_common.py b/test/mitmproxy/console/test_common.py index 49ce35b7..236ebb41 100644 --- a/test/mitmproxy/console/test_common.py +++ b/test/mitmproxy/console/test_common.py @@ -1,9 +1,10 @@ from mitmproxy.test import tflow from mitmproxy.tools.console import common -from .. import tutils +from ...conftest import skip_appveyor -@tutils.skip_appveyor + +@skip_appveyor def test_format_flow(): f = tflow.tflow(resp=True) assert common.format_flow(f, True) diff --git a/test/mitmproxy/console/test_help.py b/test/mitmproxy/console/test_help.py index d34f3f5d..86b842d8 100644 --- a/test/mitmproxy/console/test_help.py +++ b/test/mitmproxy/console/test_help.py @@ -1,8 +1,9 @@ import mitmproxy.tools.console.help as help -from .. import tutils +from ...conftest import skip_appveyor -@tutils.skip_appveyor + +@skip_appveyor class TestHelp: def test_helptext(self): diff --git a/test/mitmproxy/console/test_palettes.py b/test/mitmproxy/console/test_palettes.py index 7490bae0..3892797d 100644 --- a/test/mitmproxy/console/test_palettes.py +++ b/test/mitmproxy/console/test_palettes.py @@ -1,8 +1,9 @@ import mitmproxy.tools.console.palettes as palettes -from .. import tutils +from ...conftest import skip_appveyor -@tutils.skip_appveyor + +@skip_appveyor class TestPalette: def test_helptext(self): diff --git a/test/mitmproxy/test_flowfilter.py b/test/mitmproxy/test_flowfilter.py index 1fb97126..bfce265e 100644 --- a/test/mitmproxy/test_flowfilter.py +++ b/test/mitmproxy/test_flowfilter.py @@ -4,7 +4,6 @@ from unittest.mock import patch from mitmproxy.test import tflow from mitmproxy import flowfilter -from . import tutils as ttutils class TestParsing: @@ -382,10 +381,10 @@ class TestMatchingTCPFlow: class TestMatchingDummyFlow: def flow(self): - return ttutils.tdummyflow() + return tflow.tdummyflow() def err(self): - return ttutils.tdummyflow(err=True) + return tflow.tdummyflow(err=True) def q(self, q, o): return flowfilter.parse(q)(o) diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py index 6e0ef846..ff1e2df0 100644 --- a/test/mitmproxy/test_proxy.py +++ b/test/mitmproxy/test_proxy.py @@ -15,8 +15,7 @@ from pathod import test from mitmproxy.net.http import http1 from mitmproxy.test import tutils -from . import tutils as ttutils - +from ..conftest import skip_windows class TestServerConnection: @@ -149,7 +148,7 @@ class TestProcessProxyOptions: class TestProxyServer: # binding to 0.0.0.0:1 works without special permissions on Windows - @ttutils.skip_windows + @skip_windows def test_err(self): conf = ProxyConfig( options.Options(listen_port=1), @@ -173,7 +172,7 @@ class TestDummyServer: class TestConnectionHandler: - def test_fatal_error(self): + def test_fatal_error(self, capsys): config = mock.Mock() root_layer = mock.Mock() root_layer.side_effect = RuntimeError @@ -189,5 +188,7 @@ class TestConnectionHandler: config, channel ) - with ttutils.capture_stderr(c.handle) as output: - assert "mitmproxy has crashed" in output + c.handle() + + _, err = capsys.readouterr() + assert "mitmproxy has crashed" in err diff --git a/test/mitmproxy/test_server.py b/test/mitmproxy/test_server.py index 1388a4d8..f060b991 100644 --- a/test/mitmproxy/test_server.py +++ b/test/mitmproxy/test_server.py @@ -21,9 +21,9 @@ from mitmproxy.net.tcp import Address from pathod import pathoc from pathod import pathod -from . import tutils as ttutils - from . import tservers +from ..conftest import skip_appveyor + """ Note that the choice of response code in these tests matters more than you @@ -611,7 +611,7 @@ class TestProxy(tservers.HTTPProxyTest): assert "host" in f.request.headers assert f.response.status_code == 304 - @ttutils.skip_appveyor + @skip_appveyor def test_response_timestamps(self): # test that we notice at least 1 sec delay between timestamps # in response object @@ -622,7 +622,7 @@ class TestProxy(tservers.HTTPProxyTest): # timestamp_start might fire a bit late, so we play safe and only require 300ms. assert 0.3 <= response.timestamp_end - response.timestamp_start - @ttutils.skip_appveyor + @skip_appveyor def test_request_timestamps(self): # test that we notice a delay between timestamps in request object connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) diff --git a/test/mitmproxy/tutils.py b/test/mitmproxy/tutils.py deleted file mode 100644 index 35e3295d..00000000 --- a/test/mitmproxy/tutils.py +++ /dev/null @@ -1,68 +0,0 @@ -import sys -from contextlib import contextmanager -from unittest.case import SkipTest - -import io -import mitmproxy.test.tutils -import os -from mitmproxy import controller -from mitmproxy import flow -import mitmproxy.test.tflow - - -def _skip_windows(*args): - raise SkipTest("Skipped on Windows.") - - -def skip_windows(fn): - if os.name == "nt": - return _skip_windows - else: - return fn - - -def skip_not_windows(fn): - if os.name == "nt": - return fn - else: - return _skip_windows - - -def _skip_appveyor(*args): - raise SkipTest("Skipped on AppVeyor.") - - -def skip_appveyor(fn): - if "APPVEYOR" in os.environ: - return _skip_appveyor - else: - return fn - - -class DummyFlow(flow.Flow): - """A flow that is neither HTTP nor TCP.""" - - def __init__(self, client_conn, server_conn, live=None): - super().__init__("dummy", client_conn, server_conn, live) - - -def tdummyflow(client_conn=True, server_conn=True, err=None): - if client_conn is True: - client_conn = mitmproxy.test.tflow.tclient_conn() - if server_conn is True: - server_conn = mitmproxy.test.tflow.tserver_conn() - if err is True: - err = mitmproxy.test.tflow.terr() - - f = DummyFlow(client_conn, server_conn) - f.error = err - f.reply = controller.DummyReply() - return f - - -@contextmanager -def capture_stderr(command, *args, **kwargs): - out, sys.stderr = sys.stderr, io.StringIO() - command(*args, **kwargs) - yield sys.stderr.getvalue() - sys.stderr = out |