diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/helper_tools/typehints_for_options.py | 34 | ||||
-rw-r--r-- | test/mitmproxy/test_addonmanager.py | 5 | ||||
-rw-r--r-- | test/mitmproxy/test_optmanager.py | 4 |
3 files changed, 43 insertions, 0 deletions
diff --git a/test/helper_tools/typehints_for_options.py b/test/helper_tools/typehints_for_options.py new file mode 100644 index 00000000..8c7d006c --- /dev/null +++ b/test/helper_tools/typehints_for_options.py @@ -0,0 +1,34 @@ +import typing +from unittest import mock + +from mitmproxy import proxy, options +from mitmproxy.tools import dump, console, web + + +def print_typehints(opts): + for name, option in sorted(opts.items()): + print( + # For Python 3.6, we can just use "{}: {}". + "{} = None # type: {}".format( + name, + { + int: "int", + str: "str", + bool: "bool", + typing.Optional[str]: "Optional[str]", + typing.Sequence[str]: "Sequence[str]" + }[option.typespec] + ) + ) + + +if __name__ == "__main__": + opts = options.Options() + server = proxy.server.DummyServer(None) + + # initialize with all three tools here to capture tool-specific options defined in addons. + dump.DumpMaster(opts, server) + with mock.patch("sys.stdout.isatty", lambda: True): + console.master.ConsoleMaster(opts, server) + web.master.WebMaster(opts, server) + print_typehints(opts) diff --git a/test/mitmproxy/test_addonmanager.py b/test/mitmproxy/test_addonmanager.py index 7295a468..722d108b 100644 --- a/test/mitmproxy/test_addonmanager.py +++ b/test/mitmproxy/test_addonmanager.py @@ -117,6 +117,11 @@ def test_simple(): a.trigger("tick") assert tctx.master.has_log("not callable") + tctx.master.clear() + a.get("one").tick = addons + a.trigger("tick") + assert not tctx.master.has_log("not callable") + a.remove(a.get("one")) assert not a.get("one") diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py index 7b4ffb8b..fe72e6bb 100644 --- a/test/mitmproxy/test_optmanager.py +++ b/test/mitmproxy/test_optmanager.py @@ -229,6 +229,10 @@ def test_simple(): assert "one" in TO() +def test_items(): + assert TO().items() + + def test_serialize(): o = TD2() o.three = "set" |