summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.com>2019-01-09 16:44:14 +0000
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2019-01-14 18:46:57 +0000
commitff666e76c30bf48d01bd675e564163a77068e60c (patch)
tree327fa3d1e6fd16a4e0be03fa1096bc6fc5c4bf20
parent542cdaf047945e93de64b397629607b7cf6d4b53 (diff)
downloadbuildstream-jennis/add_artifacts_completion.tar.gz
completions.py: Add a test for our artifact ref autocompletionsjennis/add_artifacts_completion
Since the artifact subcommand group has been created, we have been able to tab complete both element names and artifact refs as arguments to the artifact subcommands (e.g. bst artifact log), this commit adds a test for this.
-rw-r--r--tests/completions/completions.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/completions/completions.py b/tests/completions/completions.py
index 372ed7840..6c75b31e2 100644
--- a/tests/completions/completions.py
+++ b/tests/completions/completions.py
@@ -281,3 +281,44 @@ def test_argument_element_invalid(datafiles, cli, project, cmd, word_idx, expect
])
def test_help_commands(cli, cmd, word_idx, expected):
assert_completion(cli, cmd, word_idx, expected)
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project'))
+def test_argument_artifact(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ # Build an import element with no dependencies (as there will only be ONE cache key)
+ result = cli.run(project=project, args=['build', 'import-bin.bst']) # Has no dependencies
+ result.assert_success()
+
+ # Get the key and the artifact ref ($project/$element_name/$key)
+ key = cli.get_element_key(project, 'import-bin.bst')
+ artifact = os.path.join('test', 'import-bin', key)
+
+ # Test autocompletion of the artifact
+ cmds = [
+ 'bst artifact log ',
+ 'bst artifact log t',
+ 'bst artifact log test/'
+ ]
+
+ for i, cmd in enumerate(cmds):
+ word_idx = 3
+ result = cli.run(project=project, cwd=project, env={
+ '_BST_COMPLETION': 'complete',
+ 'COMP_WORDS': cmd,
+ 'COMP_CWORD': str(word_idx)
+ })
+ words = []
+ if result.output:
+ words = result.output.splitlines() # This leaves an extra space on each e.g. ['foo.bst ']
+ words = [word.strip() for word in words]
+
+ if i == 0:
+ expected = PROJECT_ELEMENTS + [artifact] # We should now be able to see the artifact
+ elif i == 1:
+ expected = ['target.bst', artifact]
+ elif i == 2:
+ expected = [artifact]
+
+ assert expected == words