-
Notifications
You must be signed in to change notification settings - Fork 2
test(e2e): winml inspect E2E tests + fix --list-tasks crash #676
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bac0084
test(e2e): add winml inspect E2E tests + fix --list-tasks crash
DingmaomaoBJTU ac742bd
Merge branch 'main' into qiowu/inspect_e2e
xieofxie fb66a1d
refactor(test): move inspect CLI surface tests to tests/cli/
DingmaomaoBJTU 41d1947
refactor(test): address timenick review on inspect CLI tests
DingmaomaoBJTU 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
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,22 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| # -------------------------------------------------------------------------- | ||
| """Shared test helpers for winml CLI invocation. | ||
|
|
||
| Provides ``run_inspect``, a thin wrapper around ``CliRunner.invoke`` used | ||
| by both ``tests/cli/test_inspect_cli.py`` and ``tests/e2e/test_inspect_e2e.py`` | ||
| so that the invocation envelope (``obj={}``, ``mix_stderr`` defaults, etc.) | ||
| lives in a single place. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from click.testing import CliRunner, Result | ||
|
|
||
| from winml.modelkit.commands.inspect import inspect | ||
|
|
||
|
|
||
| def run_inspect(*args: str) -> Result: | ||
| """Invoke the ``inspect`` Click command with *args and return the Result.""" | ||
| return CliRunner().invoke(inspect, list(args), obj={}) |
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,116 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
| # -------------------------------------------------------------------------- | ||
| """CLI surface tests for `winml inspect`. | ||
|
|
||
| Covers help text, no-args UsageError, invalid option choices, and | ||
| --list-tasks — all without downloading any model weights or hitting | ||
| the network. | ||
|
|
||
| These tests run under the default CI filter (no special marker required). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
|
|
||
| import pytest | ||
|
|
||
| from tests._helpers import run_inspect as _run | ||
|
|
||
|
|
||
| # =========================================================================== | ||
| # CLI surface | ||
| # =========================================================================== | ||
|
|
||
|
|
||
| class TestInspectCliSurface: | ||
| """Help text, no-args errors, and format validation.""" | ||
|
|
||
| @pytest.fixture(scope="class") | ||
| def help_output(self) -> str: | ||
| """Invoke --help once and share the output across all parametrized cases.""" | ||
| return _run("--help").output | ||
|
|
||
| def test_no_args_exits_usage_error(self) -> None: | ||
| """Invoked with no arguments inspect must exit 2 with a UsageError.""" | ||
| result = _run() | ||
| assert result.exit_code == 2 | ||
| assert "At least one of" in result.output | ||
|
|
||
| def test_help_exits_zero(self) -> None: | ||
| """--help must exit 0.""" | ||
| assert _run("--help").exit_code == 0 | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "flags", | ||
| [ | ||
| ("-m", "--model"), | ||
| ("-f", "--format"), | ||
| ("--model-type",), | ||
| ("--model-class",), | ||
| ("--list-tasks",), | ||
| ("-v", "--verbose"), | ||
| ("-H", "--hierarchy"), | ||
| ], | ||
| ) | ||
| def test_help_documents_flag(self, help_output: str, flags: tuple[str, ...]) -> None: | ||
| """Every documented flag appears in --help output.""" | ||
| for flag in flags: | ||
| assert flag in help_output | ||
|
|
||
| def test_invalid_format(self) -> None: | ||
| """An unrecognised --format value must exit non-zero and name the bad value.""" | ||
| result = _run("--model-type", "bert", "--format", "xml") | ||
| assert result.exit_code != 0 | ||
| output_lower = result.output.lower() | ||
| assert "xml" in output_lower or "choice" in output_lower or "invalid" in output_lower | ||
|
|
||
|
|
||
| # =========================================================================== | ||
| # --list-tasks | ||
| # =========================================================================== | ||
|
|
||
|
|
||
| class TestInspectListTasks: | ||
| """--list-tasks must exit 0 and print one task-name per line.""" | ||
|
|
||
| def test_list_tasks_exits_zero(self) -> None: | ||
| """--list-tasks should not require a model argument and must exit 0.""" | ||
| result = _run("--list-tasks") | ||
| assert result.exit_code == 0, f"--list-tasks exited {result.exit_code}:\n{result.output}" | ||
|
|
||
| def test_list_tasks_output_is_nonempty(self) -> None: | ||
| """--list-tasks must print at least one task.""" | ||
| result = _run("--list-tasks") | ||
| assert result.exit_code == 0 | ||
| lines = [line.strip() for line in result.output.splitlines() if line.strip()] | ||
| assert len(lines) > 0, "Expected at least one task line" | ||
|
|
||
| def test_list_tasks_lines_match_task_name_pattern(self) -> None: | ||
| """Every line must be a valid HF task-name (lowercase, hyphens only).""" | ||
| result = _run("--list-tasks") | ||
|
DingmaomaoBJTU marked this conversation as resolved.
|
||
| assert result.exit_code == 0 | ||
| for line in result.output.splitlines(): | ||
| task = line.strip() | ||
| if task: | ||
| assert re.match(r"^[a-z][a-z0-9-]*$", task), ( | ||
| f"Line does not match task-name pattern: {task!r}" | ||
| ) | ||
|
|
||
| def test_list_tasks_includes_known_tasks(self) -> None: | ||
| """Output must include ModelKit-registered tasks.""" | ||
| result = _run("--list-tasks") | ||
| assert result.exit_code == 0 | ||
| tasks = {line.strip() for line in result.output.splitlines() if line.strip()} | ||
| assert "feature-extraction" in tasks | ||
| assert "mask-generation" in tasks | ||
|
|
||
| @pytest.mark.parametrize("extra_args", [[], ["--model-type", "bert"]]) | ||
| def test_list_tasks_is_sorted(self, extra_args: list[str]) -> None: | ||
| """Output lines must be in ascending lexicographic order.""" | ||
| result = _run("--list-tasks", *extra_args) | ||
| assert result.exit_code == 0 | ||
| lines = [line.strip() for line in result.output.splitlines() if line.strip()] | ||
| assert lines == sorted(lines), "Task list is not sorted" | ||
Oops, something went wrong.
Oops, something went wrong.
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.