From c7ffc228194574d1cff2c2fbb05fc3419c4805f4 Mon Sep 17 00:00:00 2001 From: Henrique Date: Tue, 12 Nov 2019 18:57:39 -0500 Subject: Fix for issues when using \ and " on the commander bar --- test/mitmproxy/test_command.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index d9dcf5f9..2785e28f 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -249,10 +249,10 @@ class TestCommand: ["str"] ], [ - "flow \"one two\"", + "flow \"three four\"", [ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = "one two", type = flow.Flow, valid = False), + command.ParseResult(value = '"three four"', type = flow.Flow, valid = False), ], ["str"] ], @@ -270,7 +270,7 @@ def test_simple(): c = command.CommandManager(tctx.master) a = TAddon() c.add("one.two", a.cmd1) - assert c.commands["one.two"].help == "cmd1 help" + assert(c.commands["one.two"].help == "cmd1 help") assert(c.execute("one.two foo") == "ret foo") assert(c.call("one.two", "foo") == "ret foo") with pytest.raises(exceptions.CommandError, match="Unknown"): @@ -281,7 +281,7 @@ def test_simple(): c.execute("one.two too many args") with pytest.raises(exceptions.CommandError, match="Unknown"): c.call("nonexistent") - with pytest.raises(exceptions.CommandError, match="No escaped"): + with pytest.raises(exceptions.CommandError, match="Unknown"): c.execute("\\") c.add("empty", a.empty) -- cgit v1.2.3 From 561d6d91d126d644a5183af3deadf9f90e5dfc7f Mon Sep 17 00:00:00 2001 From: Henrique Date: Tue, 12 Nov 2019 22:08:10 -0500 Subject: Fixed test to use the new method to get the lexer --- test/mitmproxy/tools/console/test_defaultkeys.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/tools/console/test_defaultkeys.py b/test/mitmproxy/tools/console/test_defaultkeys.py index 52075c84..be8e39f8 100644 --- a/test/mitmproxy/tools/console/test_defaultkeys.py +++ b/test/mitmproxy/tools/console/test_defaultkeys.py @@ -6,7 +6,6 @@ from mitmproxy import command import pytest - @pytest.mark.asyncio async def test_commands_exist(): km = keymap.Keymap(None) @@ -16,7 +15,8 @@ async def test_commands_exist(): await m.load_flow(tflow()) for binding in km.bindings: - cmd, *args = command.lexer(binding.command) + cmd, *args = command.get_lexer(binding.command) + assert cmd in m.commands.commands cmd_obj = m.commands.commands[cmd] -- cgit v1.2.3 From 578eb7239cf073ee9dd526542ca19ff6c23ae61c Mon Sep 17 00:00:00 2001 From: Henrique Date: Tue, 12 Nov 2019 22:09:04 -0500 Subject: Tests for the new lexer --- test/mitmproxy/test_lexer.py | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 test/mitmproxy/test_lexer.py (limited to 'test') diff --git a/test/mitmproxy/test_lexer.py b/test/mitmproxy/test_lexer.py new file mode 100644 index 00000000..c8b30fc6 --- /dev/null +++ b/test/mitmproxy/test_lexer.py @@ -0,0 +1,64 @@ +from mitmproxy import lexer +import pytest + + +class TestScripts: + + def test_simple(self): + + cases = [ + { + "text": r'abc', + "result": ['abc'] + }, + { + "text": r'"Hello \" Double Quotes"', + "result": ['"Hello \\" Double Quotes"'] + }, + { + "text": r"'Hello \' Single Quotes'", + "result": ["'Hello \\' Single Quotes'"] + }, + { + "text": r'"\""', + "result": ['"\\""'] + }, + { + "text": r'abc "def\" \x bla \z \\ \e \ " xpto', + "result": ['abc', '"def\\" \\x bla \\z \\\\ \\e \\ "', 'xpto'] + }, + { + "text": r'', + "result": [] + }, + { + "text": r' ', + "result": [] + }, + { + "text": r' ', + "result": [] + }, + { + "text": r'Space in the end ', + "result": ['Space', 'in', 'the', 'end'] + }, + { + "text": '\n\n\rHello\n World With Spaces\n\n', + "result": ['Hello', 'World', 'With', 'Spaces'] + }, + ] + + for t in cases: + + lex = lexer.Lexer(t['text']) + tokens = list(lex) + result = t['result'] + assert(tokens == result) + + def test_fail(self): + text = r'"should fail with missing closing quote' + lex = lexer.Lexer(text) + with pytest.raises(ValueError, match="No closing quotation"): + assert list(lex) + -- cgit v1.2.3 From eee4b24e98b76b1eb33804d21264c5117a5c913c Mon Sep 17 00:00:00 2001 From: Henrique Date: Tue, 12 Nov 2019 22:50:33 -0500 Subject: Fixing issues reported by the linter --- test/mitmproxy/test_lexer.py | 1 - test/mitmproxy/tools/console/test_defaultkeys.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/mitmproxy/test_lexer.py b/test/mitmproxy/test_lexer.py index c8b30fc6..ae706407 100644 --- a/test/mitmproxy/test_lexer.py +++ b/test/mitmproxy/test_lexer.py @@ -61,4 +61,3 @@ class TestScripts: lex = lexer.Lexer(text) with pytest.raises(ValueError, match="No closing quotation"): assert list(lex) - diff --git a/test/mitmproxy/tools/console/test_defaultkeys.py b/test/mitmproxy/tools/console/test_defaultkeys.py index be8e39f8..035f71f7 100644 --- a/test/mitmproxy/tools/console/test_defaultkeys.py +++ b/test/mitmproxy/tools/console/test_defaultkeys.py @@ -6,6 +6,7 @@ from mitmproxy import command import pytest + @pytest.mark.asyncio async def test_commands_exist(): km = keymap.Keymap(None) -- cgit v1.2.3 From d90262ad35b25a7a4ec0e01a2dd4d4c813729030 Mon Sep 17 00:00:00 2001 From: Henrique Date: Tue, 12 Nov 2019 23:16:52 -0500 Subject: Getting 100% coverage in the lexer --- test/mitmproxy/test_lexer.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/mitmproxy/test_lexer.py b/test/mitmproxy/test_lexer.py index ae706407..a1898620 100644 --- a/test/mitmproxy/test_lexer.py +++ b/test/mitmproxy/test_lexer.py @@ -1,5 +1,6 @@ from mitmproxy import lexer import pytest +import io class TestScripts: @@ -47,6 +48,10 @@ class TestScripts: "text": '\n\n\rHello\n World With Spaces\n\n', "result": ['Hello', 'World', 'With', 'Spaces'] }, + { + "text": r'\" Escaping characters without reason', + "result": ['\\"', 'Escaping', 'characters', 'without', 'reason'] + }, ] for t in cases: @@ -61,3 +66,12 @@ class TestScripts: lex = lexer.Lexer(text) with pytest.raises(ValueError, match="No closing quotation"): assert list(lex) + + def test_stringio_text(self): + text = io.StringIO(r'Increase test coverage') + lex = lexer.Lexer(text) + tokens = list(lex) + result = ['Increase', 'test', 'coverage'] + assert(tokens == result) + + -- cgit v1.2.3 From 875adb2ba82bb6b94fec755d4f2ac9800066c47d Mon Sep 17 00:00:00 2001 From: Henrique Date: Wed, 13 Nov 2019 09:32:51 -0500 Subject: Added tests to reach 100% coverage --- test/mitmproxy/test_command.py | 6 +++++- test/mitmproxy/test_lexer.py | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index 2785e28f..ad475fba 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -139,7 +139,7 @@ class TestCommand: ], [ "", - [command.ParseResult(value = "", type = mitmproxy.types.Cmd, valid = False)], + [], [] ], [ @@ -283,6 +283,10 @@ def test_simple(): c.call("nonexistent") with pytest.raises(exceptions.CommandError, match="Unknown"): c.execute("\\") + with pytest.raises(exceptions.CommandError, match="Unknown"): + c.execute(r"\'") + with pytest.raises(exceptions.CommandError, match="Unknown"): + c.execute(r"\"") c.add("empty", a.empty) c.execute("empty") diff --git a/test/mitmproxy/test_lexer.py b/test/mitmproxy/test_lexer.py index a1898620..19ef155b 100644 --- a/test/mitmproxy/test_lexer.py +++ b/test/mitmproxy/test_lexer.py @@ -73,5 +73,3 @@ class TestScripts: tokens = list(lex) result = ['Increase', 'test', 'coverage'] assert(tokens == result) - - -- cgit v1.2.3 From f2b118817efa16c0d019b98cf2d6519b67fe7323 Mon Sep 17 00:00:00 2001 From: Henrique Date: Wed, 13 Nov 2019 10:32:17 -0500 Subject: Added a new test to test that the issue from the previous commit won't happen anymore --- test/mitmproxy/tools/console/test_commander.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index b5e226fe..81e007f0 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -1,6 +1,6 @@ - from mitmproxy.tools.console.commander import commander from mitmproxy.test import taddons +import pytest class TestListCompleter: @@ -28,6 +28,18 @@ class TestListCompleter: assert c.cycle() == expected +class TestCommandEdit: + def test_open_command_bar(self): + with taddons.context() as tctx: + history = commander.CommandHistory(tctx.master, size=3) + edit = commander.CommandEdit(tctx.master, '', history) + + try: + edit.update() + except IndexError: + pytest.faied("Unexpected IndexError") + + class TestCommandHistory: def fill_history(self, commands): with taddons.context() as tctx: -- cgit v1.2.3 From 8972250167cfd55dcfcb93b2d3d7b33e0546629d Mon Sep 17 00:00:00 2001 From: Henrique Date: Fri, 15 Nov 2019 13:07:12 -0500 Subject: Removed the custom lexer in favor of using pyparsing. --- test/mitmproxy/test_command.py | 153 ++++++++++++++++++----- test/mitmproxy/test_lexer.py | 75 ----------- test/mitmproxy/tools/console/test_commander.py | 5 - test/mitmproxy/tools/console/test_defaultkeys.py | 12 +- 4 files changed, 134 insertions(+), 111 deletions(-) delete mode 100644 test/mitmproxy/test_lexer.py (limited to 'test') diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index ad475fba..ae4c400c 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -115,12 +115,9 @@ class TestCommand: [ "foo bar", [ - command.ParseResult( - value = "foo", type = mitmproxy.types.Cmd, valid = False - ), - command.ParseResult( - value = "bar", type = mitmproxy.types.Unknown, valid = False - ) + command.ParseResult(value = "foo", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = "bar", type = mitmproxy.types.Unknown, valid = False) ], [], ], @@ -128,6 +125,7 @@ class TestCommand: "cmd1 'bar", [ command.ParseResult(value = "cmd1", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), command.ParseResult(value = "'bar", type = str, valid = True) ], [], @@ -146,6 +144,7 @@ class TestCommand: "cmd3 1", [ command.ParseResult(value = "cmd3", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), command.ParseResult(value = "1", type = int, valid = True), ], [] @@ -154,28 +153,27 @@ class TestCommand: "cmd3 ", [ command.ParseResult(value = "cmd3", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = "", type = int, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), ], - [] + ['int'] ], [ "subcommand ", [ - command.ParseResult( - value = "subcommand", type = mitmproxy.types.Cmd, valid = True, - ), - command.ParseResult(value = "", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = "subcommand", type = mitmproxy.types.Cmd, valid = True,), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), ], - ["arg"], + ["cmd", "arg"], ], [ "subcommand cmd3 ", [ command.ParseResult(value = "subcommand", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), command.ParseResult(value = "cmd3", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = "", type = int, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), ], - [] + ["int"] ], [ "cmd4", @@ -188,22 +186,15 @@ class TestCommand: "cmd4 ", [ command.ParseResult(value = "cmd4", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = "", type = int, valid = False), - ], - ["str", "path"] - ], - [ - "cmd4 1", - [ - command.ParseResult(value = "cmd4", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = "1", type = int, valid = True), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), ], - ["str", "path"] + ["int", "str", "path"] ], [ "cmd4 1", [ command.ParseResult(value = "cmd4", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), command.ParseResult(value = "1", type = int, valid = True), ], ["str", "path"] @@ -219,14 +210,15 @@ class TestCommand: "flow ", [ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = "", type = flow.Flow, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), ], - ["str"] + ["flow", "str"] ], [ "flow x", [ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), command.ParseResult(value = "x", type = flow.Flow, valid = False), ], ["str"] @@ -235,15 +227,17 @@ class TestCommand: "flow x ", [ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), command.ParseResult(value = "x", type = flow.Flow, valid = False), - command.ParseResult(value = "", type = str, valid = True), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), ], - [] + ["str"] ], [ "flow \"one two", [ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), command.ParseResult(value = "\"one two", type = flow.Flow, valid = False), ], ["str"] @@ -252,11 +246,112 @@ class TestCommand: "flow \"three four\"", [ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), command.ParseResult(value = '"three four"', type = flow.Flow, valid = False), ], ["str"] ], + [ + "spaces ' '", + [ + command.ParseResult(value = "spaces", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = "' '", type = mitmproxy.types.Unknown, valid = False) + ], + [], + ], + [ + 'spaces2 " "', + [ + command.ParseResult(value = "spaces2", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = '" "', type = mitmproxy.types.Unknown, valid = False) + ], + [], + ], + [ + '"abc"', + [ + command.ParseResult(value = '"abc"', type = mitmproxy.types.Cmd, valid = False), + ], + [], + ], + [ + "'def'", + [ + command.ParseResult(value = "'def'", type = mitmproxy.types.Cmd, valid = False), + ], + [], + ], + [ + "cmd10 'a' \"b\" c", + [ + command.ParseResult(value = "cmd10", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = "'a'", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = '"b"', type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = "c", type = mitmproxy.types.Unknown, valid = False), + ], + [], + ], + [ + "cmd11 'a \"b\" c'", + [ + command.ParseResult(value = "cmd11", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = "'a \"b\" c'", type = mitmproxy.types.Unknown, valid = False), + ], + [], + ], + [ + 'cmd12 "a \'b\' c"', + [ + command.ParseResult(value = "cmd12", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = '"a \'b\' c"', type = mitmproxy.types.Unknown, valid = False), + ], + [], + ], + [ + r'cmd13 "a \"b\" c"', + [ + command.ParseResult(value = "cmd13", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = r'"a \"b\" c"', type = mitmproxy.types.Unknown, valid = False), + ], + [], + ], + [ + r"cmd14 'a \'b\' c'", + [ + command.ParseResult(value = "cmd14", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = r"'a \'b\' c'", type = mitmproxy.types.Unknown, valid = False), + ], + [], + ], + [ + " spaces_at_the_begining_are_stripped", + [ + command.ParseResult(value = "spaces_at_the_begining_are_stripped", type = mitmproxy.types.Cmd, valid = False), + ], + [], + ], + [ + " spaces_at_the_begining_are_stripped but_not_at_the_end ", + [ + command.ParseResult(value = "spaces_at_the_begining_are_stripped", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = "but_not_at_the_end", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + ], + [], + ], + ] + with taddons.context() as tctx: tctx.master.addons.add(TAddon()) for s, expected, expectedremain in tests: diff --git a/test/mitmproxy/test_lexer.py b/test/mitmproxy/test_lexer.py deleted file mode 100644 index 19ef155b..00000000 --- a/test/mitmproxy/test_lexer.py +++ /dev/null @@ -1,75 +0,0 @@ -from mitmproxy import lexer -import pytest -import io - - -class TestScripts: - - def test_simple(self): - - cases = [ - { - "text": r'abc', - "result": ['abc'] - }, - { - "text": r'"Hello \" Double Quotes"', - "result": ['"Hello \\" Double Quotes"'] - }, - { - "text": r"'Hello \' Single Quotes'", - "result": ["'Hello \\' Single Quotes'"] - }, - { - "text": r'"\""', - "result": ['"\\""'] - }, - { - "text": r'abc "def\" \x bla \z \\ \e \ " xpto', - "result": ['abc', '"def\\" \\x bla \\z \\\\ \\e \\ "', 'xpto'] - }, - { - "text": r'', - "result": [] - }, - { - "text": r' ', - "result": [] - }, - { - "text": r' ', - "result": [] - }, - { - "text": r'Space in the end ', - "result": ['Space', 'in', 'the', 'end'] - }, - { - "text": '\n\n\rHello\n World With Spaces\n\n', - "result": ['Hello', 'World', 'With', 'Spaces'] - }, - { - "text": r'\" Escaping characters without reason', - "result": ['\\"', 'Escaping', 'characters', 'without', 'reason'] - }, - ] - - for t in cases: - - lex = lexer.Lexer(t['text']) - tokens = list(lex) - result = t['result'] - assert(tokens == result) - - def test_fail(self): - text = r'"should fail with missing closing quote' - lex = lexer.Lexer(text) - with pytest.raises(ValueError, match="No closing quotation"): - assert list(lex) - - def test_stringio_text(self): - text = io.StringIO(r'Increase test coverage') - lex = lexer.Lexer(text) - tokens = list(lex) - result = ['Increase', 'test', 'coverage'] - assert(tokens == result) diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index 81e007f0..798ca5fe 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -165,8 +165,3 @@ class TestCommandBuffer: cb = commander.CommandBuffer(tctx.master) cb.text = "foo" assert cb.render() - - def test_flatten(self): - with taddons.context() as tctx: - cb = commander.CommandBuffer(tctx.master) - assert cb.flatten("foo bar") == "foo bar" diff --git a/test/mitmproxy/tools/console/test_defaultkeys.py b/test/mitmproxy/tools/console/test_defaultkeys.py index 035f71f7..7e8df6b6 100644 --- a/test/mitmproxy/tools/console/test_defaultkeys.py +++ b/test/mitmproxy/tools/console/test_defaultkeys.py @@ -3,12 +3,14 @@ from mitmproxy.tools.console import defaultkeys from mitmproxy.tools.console import keymap from mitmproxy.tools.console import master from mitmproxy import command - +from mitmproxy import ctx import pytest @pytest.mark.asyncio async def test_commands_exist(): + command_manager = command.CommandManager(ctx) + km = keymap.Keymap(None) defaultkeys.map(km) assert km.bindings @@ -16,7 +18,10 @@ async def test_commands_exist(): await m.load_flow(tflow()) for binding in km.bindings: - cmd, *args = command.get_lexer(binding.command) + results = command_manager.parse_partial(binding.command) + + cmd = results[0][0].value + args = [a.value for a in results[0][1:]] assert cmd in m.commands.commands @@ -24,4 +29,7 @@ async def test_commands_exist(): try: cmd_obj.prepare_args(args) except Exception as e: + + import pdb + pdb.set_trace() raise ValueError("Invalid command: {}".format(binding.command)) from e -- cgit v1.2.3 From 79caf3a458a221763cbf389f8ac5cccd9221e290 Mon Sep 17 00:00:00 2001 From: Henrique Date: Sat, 16 Nov 2019 09:16:50 -0500 Subject: Fixing issues pointed during PR review --- test/mitmproxy/test_command.py | 14 +++++++------- test/mitmproxy/tools/console/test_commander.py | 18 ++++++++++++++++++ test/mitmproxy/tools/console/test_defaultkeys.py | 3 --- 3 files changed, 25 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index ae4c400c..f5a641a8 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -92,8 +92,6 @@ class TestCommand: c = command.Command(cm, "varargs", a.varargs) assert c.signature_help() == "varargs str *str -> [str]" assert c.call(["one", "two", "three"]) == ["two", "three"] - with pytest.raises(exceptions.CommandError): - c.call(["one", "two", 3]) def test_call(self): with taddons.context() as tctx: @@ -333,18 +331,20 @@ class TestCommand: [], ], [ - " spaces_at_the_begining_are_stripped", + " spaces_at_the_begining_are_not_stripped", [ - command.ParseResult(value = "spaces_at_the_begining_are_stripped", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = "spaces_at_the_begining_are_not_stripped", type = mitmproxy.types.Cmd, valid = False), ], [], ], [ - " spaces_at_the_begining_are_stripped but_not_at_the_end ", + " spaces_at_the_begining_are_not_stripped neither_at_the_end ", [ - command.ParseResult(value = "spaces_at_the_begining_are_stripped", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = "spaces_at_the_begining_are_not_stripped", type = mitmproxy.types.Cmd, valid = False), command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "but_not_at_the_end", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value = "neither_at_the_end", type = mitmproxy.types.Unknown, valid = False), command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), ], [], diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index 798ca5fe..8c3e6839 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -165,3 +165,21 @@ class TestCommandBuffer: cb = commander.CommandBuffer(tctx.master) cb.text = "foo" assert cb.render() + + cb.text = 'set view_filter=~bq test' + ret = cb.render() + assert ret[0] == ('commander_command', 'set') + assert ret[1] == ('commander_invalid', ' ') + assert ret[2] == ('text', 'view_filter=~bq') + assert ret[3] == ('commander_invalid', ' ') + assert ret[4] == ('commander_invalid', 'test') + + cb.text = "set" + ret = cb.render() + assert ret[0] == ('commander_command', 'set') + assert ret[1] == ('text', ' ') + assert ret[2] == ('commander_hint', 'str ') + + # import pdb + # pdb.set_trace() + # print('x') diff --git a/test/mitmproxy/tools/console/test_defaultkeys.py b/test/mitmproxy/tools/console/test_defaultkeys.py index 7e8df6b6..40e536b0 100644 --- a/test/mitmproxy/tools/console/test_defaultkeys.py +++ b/test/mitmproxy/tools/console/test_defaultkeys.py @@ -29,7 +29,4 @@ async def test_commands_exist(): try: cmd_obj.prepare_args(args) except Exception as e: - - import pdb - pdb.set_trace() raise ValueError("Invalid command: {}".format(binding.command)) from e -- cgit v1.2.3 From 7779eef572e8deeae895ea6d700265e6f9b432c8 Mon Sep 17 00:00:00 2001 From: Henrique Date: Sat, 16 Nov 2019 17:01:47 -0500 Subject: Various changes to address PR comments Made a change to make `CommandManager.execute` the main entry point for executing commands and made `call_strings` into a private method. --- test/mitmproxy/addons/test_save.py | 2 +- test/mitmproxy/tools/console/test_defaultkeys.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/addons/test_save.py b/test/mitmproxy/addons/test_save.py index 4aa1f648..6727a96f 100644 --- a/test/mitmproxy/addons/test_save.py +++ b/test/mitmproxy/addons/test_save.py @@ -73,7 +73,7 @@ def test_save_command(tmpdir): v = view.View() tctx.master.addons.add(v) tctx.master.addons.add(sa) - tctx.master.commands.call_strings("save.file", ["@shown", p]) + tctx.master.commands.execute("save.file @shown %s" % p) def test_simple(tmpdir): diff --git a/test/mitmproxy/tools/console/test_defaultkeys.py b/test/mitmproxy/tools/console/test_defaultkeys.py index 40e536b0..9c79525b 100644 --- a/test/mitmproxy/tools/console/test_defaultkeys.py +++ b/test/mitmproxy/tools/console/test_defaultkeys.py @@ -18,7 +18,7 @@ async def test_commands_exist(): await m.load_flow(tflow()) for binding in km.bindings: - results = command_manager.parse_partial(binding.command) + results = command_manager.parse_partial(binding.command.strip()) cmd = results[0][0].value args = [a.value for a in results[0][1:]] -- cgit v1.2.3 From 13fe07f48f4fa191b8596aa94cbe743a3c3344fa Mon Sep 17 00:00:00 2001 From: Henrique Date: Sat, 16 Nov 2019 20:14:38 -0500 Subject: Brought coverage up to 94% on test_commander.py --- test/mitmproxy/tools/console/test_commander.py | 107 ++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index 8c3e6839..9a2ec102 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -39,6 +39,100 @@ class TestCommandEdit: except IndexError: pytest.faied("Unexpected IndexError") + def test_insert(self): + with taddons.context() as tctx: + history = commander.CommandHistory(tctx.master, size=3) + edit = commander.CommandEdit(tctx.master, '', history) + edit.keypress(1, 'a') + assert edit.get_edit_text() == 'a' + + # Don't let users type a space before starting a command + # as a usability feature + history = commander.CommandHistory(tctx.master, size=3) + edit = commander.CommandEdit(tctx.master, '', history) + edit.keypress(1, ' ') + assert edit.get_edit_text() == '' + + def test_backspace(self): + with taddons.context() as tctx: + history = commander.CommandHistory(tctx.master, size=3) + edit = commander.CommandEdit(tctx.master, '', history) + edit.keypress(1, 'a') + edit.keypress(1, 'b') + assert edit.get_edit_text() == 'ab' + edit.keypress(1, 'backspace') + assert edit.get_edit_text() == 'a' + + def test_left(self): + with taddons.context() as tctx: + history = commander.CommandHistory(tctx.master, size=3) + edit = commander.CommandEdit(tctx.master, '', history) + edit.keypress(1, 'a') + assert edit.cbuf.cursor == 1 + edit.keypress(1, 'left') + assert edit.cbuf.cursor == 0 + + # Do it again to make sure it won't go negative + edit.keypress(1, 'left') + assert edit.cbuf.cursor == 0 + + def test_right(self): + with taddons.context() as tctx: + history = commander.CommandHistory(tctx.master, size=3) + edit = commander.CommandEdit(tctx.master, '', history) + edit.keypress(1, 'a') + assert edit.cbuf.cursor == 1 + + # Make sure cursor won't go past the text + edit.keypress(1, 'right') + assert edit.cbuf.cursor == 1 + + # Make sure cursor goes left and then back right + edit.keypress(1, 'left') + assert edit.cbuf.cursor == 0 + edit.keypress(1, 'right') + assert edit.cbuf.cursor == 1 + + def test_up_and_down(self): + with taddons.context() as tctx: + history = commander.CommandHistory(tctx.master, size=3) + edit = commander.CommandEdit(tctx.master, '', history) + + buf = commander.CommandBuffer(tctx.master, 'cmd1') + history.add_command(buf) + buf = commander.CommandBuffer(tctx.master, 'cmd2') + history.add_command(buf) + + edit.keypress(1, 'up') + assert edit.get_edit_text() == 'cmd2' + edit.keypress(1, 'up') + assert edit.get_edit_text() == 'cmd1' + edit.keypress(1, 'up') + assert edit.get_edit_text() == 'cmd1' + + history = commander.CommandHistory(tctx.master, size=5) + edit = commander.CommandEdit(tctx.master, '', history) + edit.keypress(1, 'a') + edit.keypress(1, 'b') + edit.keypress(1, 'c') + assert edit.get_edit_text() == 'abc' + edit.keypress(1, 'up') + assert edit.get_edit_text() == '' + edit.keypress(1, 'down') + assert edit.get_edit_text() == 'abc' + edit.keypress(1, 'down') + assert edit.get_edit_text() == 'abc' + + history = commander.CommandHistory(tctx.master, size=5) + edit = commander.CommandEdit(tctx.master, '', history) + buf = commander.CommandBuffer(tctx.master, 'cmd3') + history.add_command(buf) + edit.keypress(1, 'z') + edit.keypress(1, 'up') + assert edit.get_edit_text() == 'cmd3' + edit.keypress(1, 'down') + assert edit.get_edit_text() == 'z' + class TestCommandHistory: def fill_history(self, commands): @@ -160,6 +254,15 @@ class TestCommandBuffer: cb.cursor = len(cb.text) cb.cycle_completion() + ch = commander.CommandHistory(tctx.master, 30) + ce = commander.CommandEdit(tctx.master, "se", ch) + ce.keypress(1, 'tab') + ce.update() + ret = ce.cbuf.render() + assert ret[0] == ('commander_command', 'set') + assert ret[1] == ('text', ' ') + assert ret[2] == ('commander_hint', 'str ') + def test_render(self): with taddons.context() as tctx: cb = commander.CommandBuffer(tctx.master) @@ -179,7 +282,3 @@ class TestCommandBuffer: assert ret[0] == ('commander_command', 'set') assert ret[1] == ('text', ' ') assert ret[2] == ('commander_hint', 'str ') - - # import pdb - # pdb.set_trace() - # print('x') -- cgit v1.2.3 From 8b52ea248e690df0d9892e9c5d9f88eda2486275 Mon Sep 17 00:00:00 2001 From: Henrique Date: Sun, 17 Nov 2019 11:26:20 -0500 Subject: Added coverage for the changes made --- test/mitmproxy/test_command.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test') diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index f5a641a8..eb3857bf 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -367,6 +367,8 @@ def test_simple(): c.add("one.two", a.cmd1) assert(c.commands["one.two"].help == "cmd1 help") assert(c.execute("one.two foo") == "ret foo") + assert(c.execute("one.two \"foo\"") == "ret foo") + assert(c.execute("one.two \"foo bar\"") == "ret \"foo bar\"") assert(c.call("one.two", "foo") == "ret foo") with pytest.raises(exceptions.CommandError, match="Unknown"): c.execute("nonexistent") @@ -382,6 +384,8 @@ def test_simple(): c.execute(r"\'") with pytest.raises(exceptions.CommandError, match="Unknown"): c.execute(r"\"") + with pytest.raises(exceptions.CommandError, match="Unknown"): + c.execute(r"\"") c.add("empty", a.empty) c.execute("empty") -- cgit v1.2.3 From cb723c53fab93dae67f68b4414a35c8bec7fc144 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 18 Nov 2019 02:55:51 +0100 Subject: revamp command processing - Display the parameter name instead of the parameter type whenver users interact with commands. This makes it easy to enter commands just by their signature. We may want to expose type information in the command list, but some quick testing showed that this are rather intuitive anyways. - Add shift tab backward cycling for the command completion. - Use inspect.Signature instead of homebrew argument matching solution. This gets rid of quite a bit of cruft. - Remove some type checking hacks in mitmproxy.types --- test/mitmproxy/test_command.py | 250 +++++++++++++++++++++++------------------ test/mitmproxy/test_types.py | 16 +-- 2 files changed, 150 insertions(+), 116 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index eb3857bf..2a1dfd08 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -1,13 +1,15 @@ -import typing import inspect +import io +import typing + +import pytest + +import mitmproxy.types from mitmproxy import command -from mitmproxy import flow from mitmproxy import exceptions -from mitmproxy.test import tflow +from mitmproxy import flow from mitmproxy.test import taddons -import mitmproxy.types -import io -import pytest +from mitmproxy.test import tflow class TAddon: @@ -29,7 +31,7 @@ class TAddon: return "ok" @command.command("subcommand") - def subcommand(self, cmd: mitmproxy.types.Cmd, *args: mitmproxy.types.Arg) -> str: + def subcommand(self, cmd: mitmproxy.types.Cmd, *args: mitmproxy.types.CmdArgs) -> str: return "ok" @command.command("empty") @@ -83,14 +85,14 @@ class TestCommand: with pytest.raises(exceptions.CommandError): command.Command(cm, "invalidret", a.invalidret) with pytest.raises(exceptions.CommandError): - command.Command(cm, "invalidarg", a.invalidarg) + assert command.Command(cm, "invalidarg", a.invalidarg) def test_varargs(self): with taddons.context() as tctx: cm = command.CommandManager(tctx.master) a = TAddon() c = command.Command(cm, "varargs", a.varargs) - assert c.signature_help() == "varargs str *str -> [str]" + assert c.signature_help() == "varargs one *var -> str[]" assert c.call(["one", "two", "three"]) == ["two", "three"] def test_call(self): @@ -99,7 +101,7 @@ class TestCommand: a = TAddon() c = command.Command(cm, "cmd.path", a.cmd1) assert c.call(["foo"]) == "ret foo" - assert c.signature_help() == "cmd.path str -> str" + assert c.signature_help() == "cmd.path foo -> str" c = command.Command(cm, "cmd.two", a.cmd2) with pytest.raises(exceptions.CommandError): @@ -113,239 +115,272 @@ class TestCommand: [ "foo bar", [ - command.ParseResult(value = "foo", type = mitmproxy.types.Cmd, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "bar", type = mitmproxy.types.Unknown, valid = False) + command.ParseResult(value="foo", type=mitmproxy.types.Cmd, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="bar", type=mitmproxy.types.Unknown, valid=False) ], [], ], [ "cmd1 'bar", [ - command.ParseResult(value = "cmd1", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "'bar", type = str, valid = True) + command.ParseResult(value="cmd1", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="'bar", type=str, valid=True) ], [], ], [ "a", - [command.ParseResult(value = "a", type = mitmproxy.types.Cmd, valid = False)], + [command.ParseResult(value="a", type=mitmproxy.types.Cmd, valid=False)], [], ], [ "", [], - [] + [ + command.CommandParameter("", mitmproxy.types.Cmd), + command.CommandParameter("", mitmproxy.types.CmdArgs) + ] ], [ "cmd3 1", [ - command.ParseResult(value = "cmd3", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "1", type = int, valid = True), + command.ParseResult(value="cmd3", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="1", type=int, valid=True), ], [] ], [ "cmd3 ", [ - command.ParseResult(value = "cmd3", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="cmd3", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), ], - ['int'] + [command.CommandParameter('foo', int)] ], [ "subcommand ", [ - command.ParseResult(value = "subcommand", type = mitmproxy.types.Cmd, valid = True,), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="subcommand", type=mitmproxy.types.Cmd, valid=True, ), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + ], + [ + command.CommandParameter('cmd', mitmproxy.types.Cmd), + command.CommandParameter('*args', mitmproxy.types.CmdArgs), ], - ["cmd", "arg"], ], [ "subcommand cmd3 ", [ - command.ParseResult(value = "subcommand", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "cmd3", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="subcommand", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="cmd3", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), ], - ["int"] + [command.CommandParameter('foo', int)] ], [ "cmd4", [ - command.ParseResult(value = "cmd4", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value="cmd4", type=mitmproxy.types.Cmd, valid=True), ], - ["int", "str", "path"] + [ + command.CommandParameter('a', int), + command.CommandParameter('b', str), + command.CommandParameter('c', mitmproxy.types.Path), + ] ], [ "cmd4 ", [ - command.ParseResult(value = "cmd4", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="cmd4", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), ], - ["int", "str", "path"] + [ + command.CommandParameter('a', int), + command.CommandParameter('b', str), + command.CommandParameter('c', mitmproxy.types.Path), + ] ], [ "cmd4 1", [ - command.ParseResult(value = "cmd4", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "1", type = int, valid = True), + command.ParseResult(value="cmd4", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="1", type=int, valid=True), ], - ["str", "path"] + [ + command.CommandParameter('b', str), + command.CommandParameter('c', mitmproxy.types.Path), + ] ], [ "flow", [ - command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value="flow", type=mitmproxy.types.Cmd, valid=True), ], - ["flow", "str"] + [ + command.CommandParameter('f', flow.Flow), + command.CommandParameter('s', str), + ] ], [ "flow ", [ - command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="flow", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), ], - ["flow", "str"] + [ + command.CommandParameter('f', flow.Flow), + command.CommandParameter('s', str), + ] ], [ "flow x", [ - command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "x", type = flow.Flow, valid = False), + command.ParseResult(value="flow", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="x", type=flow.Flow, valid=False), ], - ["str"] + [ + command.CommandParameter('s', str), + ] ], [ "flow x ", [ - command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "x", type = flow.Flow, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="flow", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="x", type=flow.Flow, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), ], - ["str"] + [ + command.CommandParameter('s', str), + ] ], [ "flow \"one two", [ - command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "\"one two", type = flow.Flow, valid = False), + command.ParseResult(value="flow", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="\"one two", type=flow.Flow, valid=False), ], - ["str"] + [ + command.CommandParameter('s', str), + ] ], [ "flow \"three four\"", [ - command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = '"three four"', type = flow.Flow, valid = False), + command.ParseResult(value="flow", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value='"three four"', type=flow.Flow, valid=False), ], - ["str"] + [ + command.CommandParameter('s', str), + ] ], [ "spaces ' '", [ - command.ParseResult(value = "spaces", type = mitmproxy.types.Cmd, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "' '", type = mitmproxy.types.Unknown, valid = False) + command.ParseResult(value="spaces", type=mitmproxy.types.Cmd, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="' '", type=mitmproxy.types.Unknown, valid=False) ], [], ], [ 'spaces2 " "', [ - command.ParseResult(value = "spaces2", type = mitmproxy.types.Cmd, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = '" "', type = mitmproxy.types.Unknown, valid = False) + command.ParseResult(value="spaces2", type=mitmproxy.types.Cmd, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value='" "', type=mitmproxy.types.Unknown, valid=False) ], [], ], [ '"abc"', [ - command.ParseResult(value = '"abc"', type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value='"abc"', type=mitmproxy.types.Cmd, valid=False), ], [], ], [ "'def'", [ - command.ParseResult(value = "'def'", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value="'def'", type=mitmproxy.types.Cmd, valid=False), ], [], ], [ "cmd10 'a' \"b\" c", [ - command.ParseResult(value = "cmd10", type = mitmproxy.types.Cmd, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "'a'", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = '"b"', type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "c", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="cmd10", type=mitmproxy.types.Cmd, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="'a'", type=mitmproxy.types.Unknown, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value='"b"', type=mitmproxy.types.Unknown, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="c", type=mitmproxy.types.Unknown, valid=False), ], [], ], [ "cmd11 'a \"b\" c'", [ - command.ParseResult(value = "cmd11", type = mitmproxy.types.Cmd, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "'a \"b\" c'", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="cmd11", type=mitmproxy.types.Cmd, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="'a \"b\" c'", type=mitmproxy.types.Unknown, valid=False), ], [], ], [ 'cmd12 "a \'b\' c"', [ - command.ParseResult(value = "cmd12", type = mitmproxy.types.Cmd, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = '"a \'b\' c"', type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="cmd12", type=mitmproxy.types.Cmd, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value='"a \'b\' c"', type=mitmproxy.types.Unknown, valid=False), ], [], ], [ r'cmd13 "a \"b\" c"', [ - command.ParseResult(value = "cmd13", type = mitmproxy.types.Cmd, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = r'"a \"b\" c"', type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="cmd13", type=mitmproxy.types.Cmd, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value=r'"a \"b\" c"', type=mitmproxy.types.Unknown, valid=False), ], [], ], [ r"cmd14 'a \'b\' c'", [ - command.ParseResult(value = "cmd14", type = mitmproxy.types.Cmd, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = r"'a \'b\' c'", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value="cmd14", type=mitmproxy.types.Cmd, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value=r"'a \'b\' c'", type=mitmproxy.types.Unknown, valid=False), ], [], ], [ " spaces_at_the_begining_are_not_stripped", [ - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "spaces_at_the_begining_are_not_stripped", type = mitmproxy.types.Cmd, valid = False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="spaces_at_the_begining_are_not_stripped", type=mitmproxy.types.Cmd, + valid=False), ], [], ], [ " spaces_at_the_begining_are_not_stripped neither_at_the_end ", [ - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "spaces_at_the_begining_are_not_stripped", type = mitmproxy.types.Cmd, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = "neither_at_the_end", type = mitmproxy.types.Unknown, valid = False), - command.ParseResult(value = " ", type = mitmproxy.types.Unknown, valid = False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="spaces_at_the_begining_are_not_stripped", type=mitmproxy.types.Cmd, + valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="neither_at_the_end", type=mitmproxy.types.Unknown, valid=False), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), ], [], ], @@ -356,8 +391,7 @@ class TestCommand: tctx.master.addons.add(TAddon()) for s, expected, expectedremain in tests: current, remain = tctx.master.commands.parse_partial(s) - assert current == expected - assert expectedremain == remain + assert (s, current, expectedremain) == (s, expected, remain) def test_simple(): @@ -365,11 +399,11 @@ def test_simple(): c = command.CommandManager(tctx.master) a = TAddon() c.add("one.two", a.cmd1) - assert(c.commands["one.two"].help == "cmd1 help") - assert(c.execute("one.two foo") == "ret foo") - assert(c.execute("one.two \"foo\"") == "ret foo") - assert(c.execute("one.two \"foo bar\"") == "ret \"foo bar\"") - assert(c.call("one.two", "foo") == "ret foo") + assert (c.commands["one.two"].help == "cmd1 help") + assert (c.execute("one.two foo") == "ret foo") + assert (c.execute("one.two \"foo\"") == "ret foo") + assert (c.execute("one.two \"foo bar\"") == "ret foo bar") + assert (c.call("one.two", "foo") == "ret foo") with pytest.raises(exceptions.CommandError, match="Unknown"): c.execute("nonexistent") with pytest.raises(exceptions.CommandError, match="Invalid"): @@ -397,13 +431,13 @@ def test_simple(): def test_typename(): assert command.typename(str) == "str" - assert command.typename(typing.Sequence[flow.Flow]) == "[flow]" + assert command.typename(typing.Sequence[flow.Flow]) == "flow[]" - assert command.typename(mitmproxy.types.Data) == "[data]" - assert command.typename(mitmproxy.types.CutSpec) == "[cut]" + assert command.typename(mitmproxy.types.Data) == "data[][]" + assert command.typename(mitmproxy.types.CutSpec) == "cut[]" assert command.typename(flow.Flow) == "flow" - assert command.typename(typing.Sequence[str]) == "[str]" + assert command.typename(typing.Sequence[str]) == "str[]" assert command.typename(mitmproxy.types.Choice("foo")) == "choice" assert command.typename(mitmproxy.types.Path) == "path" diff --git a/test/mitmproxy/test_types.py b/test/mitmproxy/test_types.py index 571985fb..c8f7afde 100644 --- a/test/mitmproxy/test_types.py +++ b/test/mitmproxy/test_types.py @@ -2,7 +2,6 @@ import pytest import os import typing import contextlib -from unittest import mock import mitmproxy.exceptions import mitmproxy.types @@ -64,13 +63,14 @@ def test_int(): b.parse(tctx.master.commands, int, "foo") -def test_path(tdata): +def test_path(tdata, monkeypatch): with taddons.context() as tctx: b = mitmproxy.types._PathType() assert b.parse(tctx.master.commands, mitmproxy.types.Path, "/foo") == "/foo" assert b.parse(tctx.master.commands, mitmproxy.types.Path, "/bar") == "/bar" - with mock.patch.dict("os.environ", {"HOME": "/home/test"}): - assert b.parse(tctx.master.commands, mitmproxy.types.Path, "~/mitm") == "/home/test/mitm" + monkeypatch.setenv("HOME", "/home/test") + monkeypatch.setenv("USERPROFILE", "/home/test") + assert b.parse(tctx.master.commands, mitmproxy.types.Path, "~/mitm") == "/home/test/mitm" assert b.is_valid(tctx.master.commands, mitmproxy.types.Path, "foo") is True assert b.is_valid(tctx.master.commands, mitmproxy.types.Path, "~/mitm") is True assert b.is_valid(tctx.master.commands, mitmproxy.types.Path, 3) is False @@ -127,10 +127,10 @@ def test_cutspec(): def test_arg(): with taddons.context() as tctx: b = mitmproxy.types._ArgType() - assert b.completion(tctx.master.commands, mitmproxy.types.Arg, "") == [] - assert b.parse(tctx.master.commands, mitmproxy.types.Arg, "foo") == "foo" - assert b.is_valid(tctx.master.commands, mitmproxy.types.Arg, "foo") is True - assert b.is_valid(tctx.master.commands, mitmproxy.types.Arg, 1) is False + assert b.completion(tctx.master.commands, mitmproxy.types.CmdArgs, "") == [] + with pytest.raises(mitmproxy.exceptions.TypeError): + b.parse(tctx.master.commands, mitmproxy.types.CmdArgs, "foo") + assert b.is_valid(tctx.master.commands, mitmproxy.types.CmdArgs, 1) is False def test_strseq(): -- cgit v1.2.3 From f75a95acea6772457b25395b0fdd2c97bfebb936 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 18 Nov 2019 03:45:16 +0100 Subject: fix vararg handling --- test/mitmproxy/test_types.py | 3 +-- test/mitmproxy/tools/console/test_commander.py | 14 +++++++------- test/mitmproxy/tools/console/test_defaultkeys.py | 17 +++++++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/test_types.py b/test/mitmproxy/test_types.py index c8f7afde..2cd17d87 100644 --- a/test/mitmproxy/test_types.py +++ b/test/mitmproxy/test_types.py @@ -128,8 +128,7 @@ def test_arg(): with taddons.context() as tctx: b = mitmproxy.types._ArgType() assert b.completion(tctx.master.commands, mitmproxy.types.CmdArgs, "") == [] - with pytest.raises(mitmproxy.exceptions.TypeError): - b.parse(tctx.master.commands, mitmproxy.types.CmdArgs, "foo") + assert b.parse(tctx.master.commands, mitmproxy.types.CmdArgs, "foo") == "foo" assert b.is_valid(tctx.master.commands, mitmproxy.types.CmdArgs, 1) is False diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index 9a2ec102..ce789d30 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -25,7 +25,7 @@ class TestListCompleter: for start, options, cycle in tests: c = commander.ListCompleter(start, options) for expected in cycle: - assert c.cycle() == expected + assert c.cycle(True) == expected class TestCommandEdit: @@ -252,7 +252,7 @@ class TestCommandBuffer: cb = commander.CommandBuffer(tctx.master) cb.text = "foo bar" cb.cursor = len(cb.text) - cb.cycle_completion() + cb.cycle_completion(True) ch = commander.CommandHistory(tctx.master, 30) ce = commander.CommandEdit(tctx.master, "se", ch) @@ -261,7 +261,7 @@ class TestCommandBuffer: ret = ce.cbuf.render() assert ret[0] == ('commander_command', 'set') assert ret[1] == ('text', ' ') - assert ret[2] == ('commander_hint', 'str ') + assert ret[2] == ('commander_hint', '*options ') def test_render(self): with taddons.context() as tctx: @@ -272,13 +272,13 @@ class TestCommandBuffer: cb.text = 'set view_filter=~bq test' ret = cb.render() assert ret[0] == ('commander_command', 'set') - assert ret[1] == ('commander_invalid', ' ') + assert ret[1] == ('text', ' ') assert ret[2] == ('text', 'view_filter=~bq') - assert ret[3] == ('commander_invalid', ' ') - assert ret[4] == ('commander_invalid', 'test') + assert ret[3] == ('text', ' ') + assert ret[4] == ('text', 'test') cb.text = "set" ret = cb.render() assert ret[0] == ('commander_command', 'set') assert ret[1] == ('text', ' ') - assert ret[2] == ('commander_hint', 'str ') + assert ret[2] == ('commander_hint', '*options ') diff --git a/test/mitmproxy/tools/console/test_defaultkeys.py b/test/mitmproxy/tools/console/test_defaultkeys.py index 9c79525b..58a0a585 100644 --- a/test/mitmproxy/tools/console/test_defaultkeys.py +++ b/test/mitmproxy/tools/console/test_defaultkeys.py @@ -1,10 +1,12 @@ +import pytest + +import mitmproxy.types +from mitmproxy import command +from mitmproxy import ctx from mitmproxy.test.tflow import tflow from mitmproxy.tools.console import defaultkeys from mitmproxy.tools.console import keymap from mitmproxy.tools.console import master -from mitmproxy import command -from mitmproxy import ctx -import pytest @pytest.mark.asyncio @@ -18,10 +20,13 @@ async def test_commands_exist(): await m.load_flow(tflow()) for binding in km.bindings: - results = command_manager.parse_partial(binding.command.strip()) + parsed, _ = command_manager.parse_partial(binding.command.strip()) - cmd = results[0][0].value - args = [a.value for a in results[0][1:]] + cmd = parsed[0].value + args = [ + a.value for a in parsed[1:] + if a.type != mitmproxy.types.Space + ] assert cmd in m.commands.commands -- cgit v1.2.3 From da0755106d76a9f45f281d2e65df38f83ae888c7 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 18 Nov 2019 03:54:18 +0100 Subject: adjust test --- test/mitmproxy/test_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index 2a1dfd08..a34a8cf6 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -168,7 +168,7 @@ class TestCommand: ], [ command.CommandParameter('cmd', mitmproxy.types.Cmd), - command.CommandParameter('*args', mitmproxy.types.CmdArgs), + command.CommandParameter('args', mitmproxy.types.CmdArgs, kind=inspect.Parameter.VAR_POSITIONAL), ], ], [ -- cgit v1.2.3 From dd556f052b0045b5e8f14b4810e302b4c2efc81f Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 18 Nov 2019 04:34:23 +0100 Subject: coverage++ --- test/mitmproxy/test_command.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index a34a8cf6..a432f9e3 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -171,6 +171,28 @@ class TestCommand: command.CommandParameter('args', mitmproxy.types.CmdArgs, kind=inspect.Parameter.VAR_POSITIONAL), ], ], + [ + "varargs one", + [ + command.ParseResult(value="varargs", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="one", type=str, valid=True), + ], + [command.CommandParameter('var', str, kind=inspect.Parameter.VAR_POSITIONAL)] + ], + [ + "varargs one two three", + [ + command.ParseResult(value="varargs", type=mitmproxy.types.Cmd, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="one", type=str, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="two", type=str, valid=True), + command.ParseResult(value=" ", type=mitmproxy.types.Space, valid=True), + command.ParseResult(value="three", type=str, valid=True), + ], + [], + ], [ "subcommand cmd3 ", [ @@ -402,7 +424,7 @@ def test_simple(): assert (c.commands["one.two"].help == "cmd1 help") assert (c.execute("one.two foo") == "ret foo") assert (c.execute("one.two \"foo\"") == "ret foo") - assert (c.execute("one.two \"foo bar\"") == "ret foo bar") + assert (c.execute("one.two 'foo bar'") == "ret foo bar") assert (c.call("one.two", "foo") == "ret foo") with pytest.raises(exceptions.CommandError, match="Unknown"): c.execute("nonexistent") -- cgit v1.2.3 From 74f5fa6a7736f116416c242b159e6b0525e6fe5b Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 18 Nov 2019 22:03:51 +0100 Subject: wip --- test/mitmproxy/tools/console/test_commander.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index ce789d30..6b42de76 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -25,7 +25,7 @@ class TestListCompleter: for start, options, cycle in tests: c = commander.ListCompleter(start, options) for expected in cycle: - assert c.cycle(True) == expected + assert c.cycle() == expected class TestCommandEdit: @@ -252,7 +252,7 @@ class TestCommandBuffer: cb = commander.CommandBuffer(tctx.master) cb.text = "foo bar" cb.cursor = len(cb.text) - cb.cycle_completion(True) + cb.cycle_completion() ch = commander.CommandHistory(tctx.master, 30) ce = commander.CommandEdit(tctx.master, "se", ch) -- cgit v1.2.3 From 76e648410745c61f7a659e864230b6154dc43ced Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 19 Nov 2019 18:14:00 +0100 Subject: fix lexing, sort of --- test/mitmproxy/test_command_lexer.py | 38 ++++++++++++++++++++++++++ test/mitmproxy/tools/console/test_commander.py | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/mitmproxy/test_command_lexer.py (limited to 'test') diff --git a/test/mitmproxy/test_command_lexer.py b/test/mitmproxy/test_command_lexer.py new file mode 100644 index 00000000..3f009f88 --- /dev/null +++ b/test/mitmproxy/test_command_lexer.py @@ -0,0 +1,38 @@ +import pyparsing +import pytest + +from mitmproxy import command_lexer + + +@pytest.mark.parametrize( + "test_input,valid", [ + ("'foo'", True), + ('"foo"', True), + ("'foo' bar'", False), + ("'foo\\' bar'", True), + ("'foo' 'bar'", False), + ("'foo'x", False), + ('''"foo ''', True), + ('''"foo 'bar' ''', True), + ] +) +def test_partial_quoted_string(test_input, valid): + if valid: + assert command_lexer.PartialQuotedString.parseString(test_input, parseAll=True)[0] == test_input + else: + with pytest.raises(pyparsing.ParseException): + command_lexer.PartialQuotedString.parseString(test_input, parseAll=True) + + +@pytest.mark.parametrize( + "test_input,expected", [ + ("'foo'", ["'foo'"]), + ('"foo"', ['"foo"']), + ("'foo' 'bar'", ["'foo'", ' ', "'bar'"]), + ("'foo'x", ["'foo'", 'x']), + ('''"foo''', ['"foo']), + ('''"foo 'bar' ''', ['''"foo 'bar' ''']), + ] +) +def test_expr(test_input, expected): + assert list(command_lexer.expr.parseString(test_input, parseAll=True)) == expected diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index 6b42de76..060e4b9b 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -269,7 +269,7 @@ class TestCommandBuffer: cb.text = "foo" assert cb.render() - cb.text = 'set view_filter=~bq test' + cb.text = 'set view_filter ~bq test' ret = cb.render() assert ret[0] == ('commander_command', 'set') assert ret[1] == ('text', ' ') -- cgit v1.2.3 From c7eedcbc1a90e9705172ffd6333cb740a5e9883f Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 19 Nov 2019 18:29:22 +0100 Subject: fix 'set' to only accept a single argument --- test/mitmproxy/addons/test_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py index 59875c2b..e6924ead 100644 --- a/test/mitmproxy/addons/test_core.py +++ b/test/mitmproxy/addons/test_core.py @@ -11,7 +11,7 @@ def test_set(): sa = core.Core() with taddons.context(loadcore=False) as tctx: assert tctx.master.options.server - tctx.command(sa.set, "server=false") + tctx.command(sa.set, "server", "false") assert not tctx.master.options.server with pytest.raises(exceptions.CommandError): -- cgit v1.2.3 From 228e1c74c20c8db13d2cf5489321cd2975c6c56f Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 19 Nov 2019 18:37:47 +0100 Subject: fix tests --- test/mitmproxy/tools/console/test_commander.py | 33 ++++++++++++++++---------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index 060e4b9b..8fc678fb 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -259,26 +259,33 @@ class TestCommandBuffer: ce.keypress(1, 'tab') ce.update() ret = ce.cbuf.render() - assert ret[0] == ('commander_command', 'set') - assert ret[1] == ('text', ' ') - assert ret[2] == ('commander_hint', '*options ') - + assert ret == [ + ('commander_command', 'set'), + ('text', ' '), + ('commander_hint', 'option '), + ('commander_hint', 'value '), + ] def test_render(self): with taddons.context() as tctx: cb = commander.CommandBuffer(tctx.master) cb.text = "foo" assert cb.render() - cb.text = 'set view_filter ~bq test' + cb.text = "set view_filter '~bq test'" ret = cb.render() - assert ret[0] == ('commander_command', 'set') - assert ret[1] == ('text', ' ') - assert ret[2] == ('text', 'view_filter=~bq') - assert ret[3] == ('text', ' ') - assert ret[4] == ('text', 'test') + assert ret == [ + ('commander_command', 'set'), + ('text', ' '), + ('text', 'view_filter'), + ('text', ' '), + ('text', "'~bq test'"), + ] cb.text = "set" ret = cb.render() - assert ret[0] == ('commander_command', 'set') - assert ret[1] == ('text', ' ') - assert ret[2] == ('commander_hint', '*options ') + assert ret == [ + ('commander_command', 'set'), + ('text', ' '), + ('commander_hint', 'option '), + ('commander_hint', 'value '), + ] \ No newline at end of file -- cgit v1.2.3 From fa100b9d16e3c521460801f2c3d6d3cc656abe75 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 19 Nov 2019 21:11:49 +0100 Subject: lint! --- test/mitmproxy/tools/console/test_commander.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index 8fc678fb..a77be043 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -1,7 +1,8 @@ -from mitmproxy.tools.console.commander import commander -from mitmproxy.test import taddons import pytest +from mitmproxy.test import taddons +from mitmproxy.tools.console.commander import commander + class TestListCompleter: def test_cycle(self): @@ -265,6 +266,7 @@ class TestCommandBuffer: ('commander_hint', 'option '), ('commander_hint', 'value '), ] + def test_render(self): with taddons.context() as tctx: cb = commander.CommandBuffer(tctx.master) @@ -288,4 +290,4 @@ class TestCommandBuffer: ('text', ' '), ('commander_hint', 'option '), ('commander_hint', 'value '), - ] \ No newline at end of file + ] -- cgit v1.2.3