summaryrefslogtreecommitdiff
path: root/cliff/tests
diff options
context:
space:
mode:
authorCedric Brandily <zzelle@gmail.com>2015-02-20 22:09:04 +0100
committerCedric Brandily <zzelle@gmail.com>2015-02-20 23:52:15 +0100
commit103b9b88e4efb8ad668683181bbacc1879337778 (patch)
treeff501efda4e379c782da6dd4a4eca2a21ee685bf /cliff/tests
parent01c8d8f05cb404d9f06745f24c431f83edec54bf (diff)
downloadcliff-103b9b88e4efb8ad668683181bbacc1879337778.tar.gz
Correct completion in interactive mode
Currently, in interactive mode, cliff shows cmd/cmd2 style commands[1] matching written prefix in completion list but not cliff style commands[2]: * for command prefix without completer delimiter, InteractiveAPP uses cmd completion method (completenames) and returns only cmd/cmd2 style command candidates, * for command prefix with completer delimiter, InteractiveAPP uses its completion method (completedefault) but with an incorrect filter and returns no or incorrect candidates. This change defines completenames method to add cliff style commands in completion and corrects completedefault method implementation. [1]: commands defined through a do_$method in $method InteractiveApp class or subclasses. By consequence, $method contains no completer delimiter. [2]: commands defined using cliff command-manager Change-Id: I84a64212acb305e5bfcf25282ad21a694a6826a9 Closes-Bug: #1424053
Diffstat (limited to 'cliff/tests')
-rw-r--r--cliff/tests/test_interactive.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/cliff/tests/test_interactive.py b/cliff/tests/test_interactive.py
new file mode 100644
index 0000000..20306d1
--- /dev/null
+++ b/cliff/tests/test_interactive.py
@@ -0,0 +1,62 @@
+# -*- encoding: utf-8 -*-
+
+from cliff.interactive import InteractiveApp
+
+
+class FakeApp(object):
+ NAME = 'Fake'
+
+
+def make_interactive_app(*command_names):
+ fake_command_manager = [(x, None) for x in command_names]
+ return InteractiveApp(FakeApp, fake_command_manager,
+ stdin=None, stdout=None)
+
+
+def _test_completenames(expecteds, prefix):
+ app = make_interactive_app('hips', 'hippo', 'nonmatching')
+ assert set(app.completenames(prefix)) == set(expecteds)
+
+
+def test_cmd2_completenames():
+ # cmd2.Cmd define do_help method
+ _test_completenames(['help'], 'he')
+
+
+def test_cliff_completenames():
+ _test_completenames(['hips', 'hippo'], 'hip')
+
+
+def test_no_completenames():
+ _test_completenames([], 'taz')
+
+
+def test_both_completenames():
+ # cmd2.Cmd define do_hi and do_history methods
+ _test_completenames(['hi', 'history', 'hips', 'hippo'], 'hi')
+
+
+def _test_completedefault(expecteds, line, begidx):
+ command_names = set(['show file', 'show folder', 'show long', 'list all'])
+ app = make_interactive_app(*command_names)
+ observeds = app.completedefault(None, line, begidx, None)
+ assert set(observeds) == set(expecteds)
+ assert set([line[:begidx] + x for x in observeds]) <= command_names
+
+
+def test_empty_text_completedefault():
+ # line = 'show ' + begidx = 5 implies text = ''
+ _test_completedefault(['file', 'folder', ' long'], 'show ', 5)
+
+
+def test_nonempty_text_completedefault2():
+ # line = 'show f' + begidx = 6 implies text = 'f'
+ _test_completedefault(['file', 'folder'], 'show f', 5)
+
+
+def test_long_completedefault():
+ _test_completedefault(['long'], 'show ', 6)
+
+
+def test_no_completedefault():
+ _test_completedefault([], 'taz ', 4)