From 42094b29ff5e042b3cf3c2544fc7a60555cd3c26 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 24 Feb 2018 12:33:48 +1300 Subject: [PATCH] Clean up un-necessary arguments to taddons.context Also test coverage ++ --- test/helper_tools/dumperview.py | 3 +-- test/mitmproxy/addons/test_dumper.py | 15 +++++++-------- test/mitmproxy/addons/test_intercept.py | 3 +-- test/mitmproxy/addons/test_save.py | 3 +-- test/mitmproxy/test_optmanager.py | 7 +++++-- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/test/helper_tools/dumperview.py b/test/helper_tools/dumperview.py index d417d767b..e17dc77bb 100755 --- a/test/helper_tools/dumperview.py +++ b/test/helper_tools/dumperview.py @@ -4,12 +4,11 @@ import click from mitmproxy.addons import dumper from mitmproxy.test import tflow from mitmproxy.test import taddons -from mitmproxy.tools import options def show(flow_detail, flows): d = dumper.Dumper() - with taddons.context(options=options.Options()) as ctx: + with taddons.context() as ctx: ctx.configure(d, flow_detail=flow_detail) for f in flows: ctx.cycle(d, f) diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py index fb80f3cee..9774e1316 100644 --- a/test/mitmproxy/addons/test_dumper.py +++ b/test/mitmproxy/addons/test_dumper.py @@ -10,12 +10,11 @@ from mitmproxy.test import tutils from mitmproxy.addons import dumper from mitmproxy import exceptions from mitmproxy import http -from mitmproxy import options def test_configure(): d = dumper.Dumper() - with taddons.context(options=options.Options()) as ctx: + with taddons.context() as ctx: ctx.configure(d, view_filter="~b foo") assert d.filter @@ -34,7 +33,7 @@ def test_configure(): def test_simple(): sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context(options=options.Options()) as ctx: + with taddons.context() as ctx: ctx.configure(d, flow_detail=0) d.response(tflow.tflow(resp=True)) assert not sio.getvalue() @@ -102,7 +101,7 @@ def test_echo_body(): sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context(options=options.Options()) as ctx: + with taddons.context() as ctx: ctx.configure(d, flow_detail=3) d._echo_message(f.response) t = sio.getvalue() @@ -112,7 +111,7 @@ def test_echo_body(): def test_echo_request_line(): sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context(options=options.Options()) as ctx: + with taddons.context() as ctx: ctx.configure(d, flow_detail=3, showhost=True) f = tflow.tflow(client_conn=None, server_conn=True, resp=True) f.request.is_replay = True @@ -147,7 +146,7 @@ class TestContentView: view_auto.side_effect = exceptions.ContentViewException("") sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context(options=options.Options()) as ctx: + with taddons.context() as ctx: ctx.configure(d, flow_detail=4, verbosity='debug') d.response(tflow.tflow()) assert ctx.master.has_log("content viewer failed") @@ -156,7 +155,7 @@ class TestContentView: def test_tcp(): sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context(options=options.Options()) as ctx: + with taddons.context() as ctx: ctx.configure(d, flow_detail=3, showhost=True) f = tflow.ttcpflow() d.tcp_message(f) @@ -171,7 +170,7 @@ def test_tcp(): def test_websocket(): sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context(options=options.Options()) as ctx: + with taddons.context() as ctx: ctx.configure(d, flow_detail=3, showhost=True) f = tflow.twebsocketflow() d.websocket_message(f) diff --git a/test/mitmproxy/addons/test_intercept.py b/test/mitmproxy/addons/test_intercept.py index d4999eb5f..d95981010 100644 --- a/test/mitmproxy/addons/test_intercept.py +++ b/test/mitmproxy/addons/test_intercept.py @@ -1,7 +1,6 @@ import pytest from mitmproxy.addons import intercept -from mitmproxy import options from mitmproxy import exceptions from mitmproxy.test import taddons from mitmproxy.test import tflow @@ -9,7 +8,7 @@ from mitmproxy.test import tflow def test_simple(): r = intercept.Intercept() - with taddons.context(options=options.Options()) as tctx: + with taddons.context() as tctx: assert not r.filt tctx.configure(r, intercept="~q") assert r.filt diff --git a/test/mitmproxy/addons/test_save.py b/test/mitmproxy/addons/test_save.py index 2dee708fb..4486ff783 100644 --- a/test/mitmproxy/addons/test_save.py +++ b/test/mitmproxy/addons/test_save.py @@ -5,14 +5,13 @@ from mitmproxy.test import tflow from mitmproxy import io from mitmproxy import exceptions -from mitmproxy import options from mitmproxy.addons import save from mitmproxy.addons import view def test_configure(tmpdir): sa = save.Save() - with taddons.context(options=options.Options()) as tctx: + with taddons.context() as tctx: with pytest.raises(exceptions.OptionsError): tctx.configure(sa, save_stream_file=str(tmpdir)) with pytest.raises(Exception, match="Invalid filter"): diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py index cd8857cab..1c49c0b80 100644 --- a/test/mitmproxy/test_optmanager.py +++ b/test/mitmproxy/test_optmanager.py @@ -376,8 +376,11 @@ def test_make_parser(): opts.make_parser(parser, "seqstr", short="d") opts.make_parser(parser, "bool_on", short="e") - # No error for nonexistent options - opts.make_parser(parser, "xxxxxxx") + with pytest.raises(ValueError): + opts.make_parser(parser, "unknown") + + # Nonexistent options ignore + opts.make_parser(parser, "nonexistentxxx") def test_set():