Merge pull request #1276 from dufferzafar/console-pathedit

mitmproxy.console tests - PathEdit
This commit is contained in:
Maximilian Hils 2016-06-20 20:36:31 -07:00 committed by GitHub
commit 44abb4caea
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,2 @@
This empty directory has been added so that we can hit [this line](https://codecov.io/gh/mitmproxy/mitmproxy/src/ba13fda10d3065a0c8dfd95d55680675b3bf08c2/mitmproxy/console/pathedit.py#L43) while testing pathedit completion.

View File

@ -2,6 +2,8 @@ import os
from os.path import normpath
from mitmproxy.console import pathedit
from mock import patch
from .. import tutils
@ -47,3 +49,25 @@ class TestPathCompleter:
s = "thisisatotallynonexistantpathforsure"
assert c.complete(s) == s
assert c.final == s
class TestPathEdit():
def test_keypress(self):
pe = pathedit.PathEdit()
with patch('urwid.widget.Edit.get_edit_text') as get_text, \
patch('urwid.widget.Edit.set_edit_text') as set_text:
cd = tutils.test_data.path("completion")
get_text.return_value = os.path.join(cd, "a")
# Pressing tab should set completed path
pe.keypress((1,), "tab")
set_text_called_with = set_text.call_args[0][0]
assert set_text_called_with.endswith(normpath("/completion/aaa"))
# Pressing any other key should reset
pe.keypress((1,), "a")
assert pe.lookup is None