-
Notifications
You must be signed in to change notification settings - Fork 1.3k
tests: add smoke coverage for shell completion script #3112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Vaishnav88sk
wants to merge
7
commits into
Netflix:master
Choose a base branch
from
Vaishnav88sk:tests/smoke-tests-for-shell-completion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a0b50d7
tests: add smoke coverage for shell completion script
Vaishnav88sk 0cb636d
tests: add shell completion smoke test and docs note
Vaishnav88sk 4df2aca
Merge branch 'master' into tests/smoke-tests-for-shell-completion
Vaishnav88sk 0c87f39
tests: tests: add smoke coverage for shell completion script
Vaishnav88sk c81c9fa
Merge branch 'master' into tests/smoke-tests-for-shell-completion
Vaishnav88sk c87eedb
tests: guard wrapper cleanup when mkstemp fails
Vaishnav88sk 672f34d
tests: use stable metaflow wrapper name in completion smoke test
Vaishnav88sk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import os | ||
| import shlex | ||
| import subprocess | ||
| import sys | ||
|
|
||
|
|
||
| def test_metaflow_completion_script_smoke(): | ||
| """Smoke-test that bash completion loads and returns command candidates.""" | ||
| repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) | ||
| completion_script = os.path.join(repo_root, "metaflow-complete.sh") | ||
|
|
||
| # Use a temporary executable named `metaflow` so click reads _METAFLOW_COMPLETE. | ||
| wrapper_path = os.path.join(repo_root, ".tmp-test-metaflow-cli") | ||
| wrapper_code = ( | ||
| "#!/usr/bin/env python3\n" | ||
| "import os\n" | ||
| "import sys\n" | ||
| f"sys.path.insert(0, {repr(repo_root)})\n" | ||
| "from metaflow.cmd.main_cli import start\n" | ||
| "start()\n" | ||
| ) | ||
|
|
||
| with open(wrapper_path, "w") as f: | ||
| f.write(wrapper_code) | ||
| os.chmod(wrapper_path, 0o755) | ||
|
|
||
| try: | ||
| bash_script = f""" | ||
| set -euo pipefail | ||
| source {shlex.quote(completion_script)} | ||
| complete -p metaflow >/dev/null | ||
| COMP_WORDS=("metaflow" "") | ||
| COMP_CWORD=1 | ||
| _metaflow_completion {shlex.quote(wrapper_path)} | ||
| printf "%s\\n" "${{COMPREPLY[@]}}" | ||
| """ | ||
| result = subprocess.run( | ||
| ["bash", "-lc", bash_script], | ||
| capture_output=True, | ||
| text=True, | ||
| check=True, | ||
| env={**os.environ, "PYTHONPATH": repo_root}, | ||
| ) | ||
| finally: | ||
| try: | ||
| os.remove(wrapper_path) | ||
| except OSError: | ||
| pass | ||
|
|
||
| completions = {line.strip() for line in result.stdout.splitlines() if line.strip()} | ||
| expected_commands = {"configure", "develop", "help", "status", "tutorials", "code"} | ||
| missing = expected_commands - completions | ||
| assert not missing, ( | ||
| "metaflow completion output is missing expected commands: " | ||
| f"{sorted(missing)}. Full output: {sorted(completions)}" | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.