diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/test_types.py | 10 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/test_commander.py | 25 |
2 files changed, 23 insertions, 12 deletions
diff --git a/test/mitmproxy/test_types.py b/test/mitmproxy/test_types.py index 46e23ff3..29e86203 100644 --- a/test/mitmproxy/test_types.py +++ b/test/mitmproxy/test_types.py @@ -136,6 +136,8 @@ def test_strseq(): class DummyConsole: @command.command("view.resolve") def resolve(self, spec: str) -> typing.Sequence[flow.Flow]: + if spec == "err": + raise mitmproxy.exceptions.CommandError() n = int(spec) return [tflow.tflow(resp=True)] * n @@ -157,9 +159,11 @@ def test_flow(): assert b.is_valid(tctx.master.commands, flow.Flow, tflow.tflow()) is True assert b.is_valid(tctx.master.commands, flow.Flow, "xx") is False with pytest.raises(mitmproxy.exceptions.TypeError): - assert b.parse(tctx.master.commands, flow.Flow, "0") + b.parse(tctx.master.commands, flow.Flow, "0") with pytest.raises(mitmproxy.exceptions.TypeError): - assert b.parse(tctx.master.commands, flow.Flow, "2") + b.parse(tctx.master.commands, flow.Flow, "2") + with pytest.raises(mitmproxy.exceptions.TypeError): + b.parse(tctx.master.commands, flow.Flow, "err") def test_flows(): @@ -175,6 +179,8 @@ def test_flows(): assert len(b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "0")) == 0 assert len(b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "1")) == 1 assert len(b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "2")) == 2 + with pytest.raises(mitmproxy.exceptions.TypeError): + b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "err") def test_data(): diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index 34062dcb..2a96995d 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -42,16 +42,16 @@ class TestCommandBuffer: with taddons.context() as tctx: for start, output in tests: cb = commander.CommandBuffer(tctx.master) - cb.buf, cb.cursor = start[0], start[1] + cb.text, cb.cursor = start[0], start[1] cb.backspace() - assert cb.buf == output[0] + assert cb.text == output[0] assert cb.cursor == output[1] def test_left(self): cursors = [3, 2, 1, 0, 0] with taddons.context() as tctx: cb = commander.CommandBuffer(tctx.master) - cb.buf, cb.cursor = "abcd", 4 + cb.text, cb.cursor = "abcd", 4 for c in cursors: cb.left() assert cb.cursor == c @@ -60,7 +60,7 @@ class TestCommandBuffer: cursors = [1, 2, 3, 4, 4] with taddons.context() as tctx: cb = commander.CommandBuffer(tctx.master) - cb.buf, cb.cursor = "abcd", 0 + cb.text, cb.cursor = "abcd", 0 for c in cursors: cb.right() assert cb.cursor == c @@ -74,20 +74,25 @@ class TestCommandBuffer: with taddons.context() as tctx: for start, output in tests: cb = commander.CommandBuffer(tctx.master) - cb.buf, cb.cursor = start[0], start[1] + cb.text, cb.cursor = start[0], start[1] cb.insert("x") - assert cb.buf == output[0] + assert cb.text == output[0] assert cb.cursor == output[1] def test_cycle_completion(self): with taddons.context() as tctx: cb = commander.CommandBuffer(tctx.master) - cb.buf = "foo bar" - cb.cursor = len(cb.buf) + cb.text = "foo bar" + cb.cursor = len(cb.text) cb.cycle_completion() def test_render(self): with taddons.context() as tctx: cb = commander.CommandBuffer(tctx.master) - cb.buf = "foo" - assert cb.render() == "foo" + 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" |