summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAntoine Wacheux <awacheux@bloomberg.net>2017-11-09 10:15:45 +0000
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-11-21 03:37:51 +0900
commit22d804df6e5d08fb84be590da173164171365374 (patch)
tree663545053f587876cb2152da80d5b1a85eda8542 /tests
parent380dff80ff2a6d79cf8d656a204b35a56abfdae5 (diff)
downloadbuildstream-22d804df6e5d08fb84be590da173164171365374.tar.gz
Accept the first character as shortcut on interruption prompts130-interactive-prompt-prefix
On interruption, this makes buildstream to accept the first character of all the possible choices as if it was the full command. This behavior has been added to the failure screen and to the interruption screen. Fixes https://gitlab.com/BuildStream/buildstream/issues/130
Diffstat (limited to 'tests')
-rw-r--r--tests/frontend/main.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/frontend/main.py b/tests/frontend/main.py
new file mode 100644
index 000000000..9ba552c60
--- /dev/null
+++ b/tests/frontend/main.py
@@ -0,0 +1,34 @@
+from buildstream._frontend.main import prefix_choice_value_proc
+
+import pytest
+import click
+
+
+def test_prefix_choice_value_proc_full_match():
+ value_proc = prefix_choice_value_proc(['foo', 'bar', 'baz'])
+
+ assert("foo" == value_proc("foo"))
+ assert("bar" == value_proc("bar"))
+ assert("baz" == value_proc("baz"))
+
+
+def test_prefix_choice_value_proc_prefix_match():
+ value_proc = prefix_choice_value_proc(['foo'])
+
+ assert ("foo" == value_proc("f"))
+
+
+def test_prefix_choice_value_proc_ambigous_match():
+ value_proc = prefix_choice_value_proc(['bar', 'baz'])
+
+ assert ("bar" == value_proc("bar"))
+ assert ("baz" == value_proc("baz"))
+ with pytest.raises(click.UsageError):
+ value_proc("ba")
+
+
+def test_prefix_choice_value_proc_value_not_in_choices():
+ value_proc = prefix_choice_value_proc(['bar', 'baz'])
+
+ with pytest.raises(click.UsageError):
+ value_proc("foo")