diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2017-12-15 17:12:44 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2017-12-15 17:51:02 +1300 |
commit | 198c7b19a3c2777c064aeba54e16b3f0b78ba143 (patch) | |
tree | 5934e085ab0407c2000b638789e4b087b618accf /test | |
parent | 1d2cdcff07bc9db090c22699432a0006589abe37 (diff) | |
download | mitmproxy-198c7b19a3c2777c064aeba54e16b3f0b78ba143.tar.gz mitmproxy-198c7b19a3c2777c064aeba54e16b3f0b78ba143.tar.bz2 mitmproxy-198c7b19a3c2777c064aeba54e16b3f0b78ba143.zip |
commander: test++
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/tools/console/test_commander.py | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py index e8974869..823af06d 100644 --- a/test/mitmproxy/tools/console/test_commander.py +++ b/test/mitmproxy/tools/console/test_commander.py @@ -1,18 +1,36 @@ import os +import contextlib from mitmproxy.tools.console.commander import commander from mitmproxy.test import taddons from mitmproxy.test import tutils -def test_pathOptions(): - cd = os.path.normpath(tutils.test_data.path("mitmproxy/completion")) +@contextlib.contextmanager +def chdir(path: str): + old_dir = os.getcwd() + os.chdir(path) + yield + os.chdir(old_dir) + + +def normPathOpts(prefix, match): + ret = [] + for s in commander.pathOptions(match): + s = s[len(prefix):] + s = s.replace(os.sep, "/") + ret.append(s) + return ret - ret = [x[len(cd):] for x in commander.pathOptions(cd)] - assert ret == ['/aaa', '/aab', '/aac', '/bbb/'] - ret = [x[len(cd):] for x in commander.pathOptions(os.path.join(cd, "a"))] - assert ret == ['/aaa', '/aab', '/aac'] +def test_pathOptions(): + cd = os.path.normpath(tutils.test_data.path("mitmproxy/completion")) + assert normPathOpts(cd, cd) == ['/aaa', '/aab', '/aac', '/bbb/'] + assert normPathOpts(cd, os.path.join(cd, "a")) == ['/aaa', '/aab', '/aac'] + with chdir(cd): + assert normPathOpts("", "./") == ['./aaa', './aab', './aac', './bbb/'] + assert normPathOpts("", "") == ['./aaa', './aab', './aac', './bbb/'] + assert commander.pathOptions("nonexistent") == ["nonexistent"] class TestListCompleter: @@ -59,6 +77,24 @@ class TestCommandBuffer: assert cb.buf == 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 + for c in cursors: + cb.left() + assert cb.cursor == c + + def test_right(self): + cursors = [1, 2, 3, 4, 4] + with taddons.context() as tctx: + cb = commander.CommandBuffer(tctx.master) + cb.buf, cb.cursor = "abcd", 0 + for c in cursors: + cb.right() + assert cb.cursor == c + def test_insert(self): tests = [ [("", 0), ("x", 1)], @@ -79,3 +115,9 @@ class TestCommandBuffer: cb.buf = "foo bar" cb.cursor = len(cb.buf) cb.cycle_completion() + + def test_render(self): + with taddons.context() as tctx: + cb = commander.CommandBuffer(tctx.master) + cb.buf = "foo" + assert cb.render() == "foo" |