-
Notifications
You must be signed in to change notification settings - Fork 19
cli: debug optional args #420
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0c02da7
cli: debug optional args
Borda 4d2ae8c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8c9d988
S
Borda 7206b67
as_positional=False
Borda 6db0b43
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9e04dfb
Apply suggestions from code review
Borda e6493fa
chlog
Borda 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
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,66 @@ | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def test_version(): | ||
| """Prints the help message for the requirements commands.""" | ||
| return_code = subprocess.call(["python", "-mlightning_utilities.cli", "version"]) # noqa: S607 | ||
| assert return_code == 0 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("args", ["positional", "optional"]) | ||
| class TestRequirements: | ||
| """Test requirements commands.""" | ||
|
|
||
| BASE_CMD = ("python", "-m", "lightning_utilities.cli", "requirements") | ||
| REQUIREMENTS_SAMPLE = """ | ||
| # This is sample requirements file | ||
| # with multi line comments | ||
|
|
||
| torchvision >=0.13.0, <0.16.0 # sample # comment | ||
| gym[classic,control] >=0.17.0, <0.27.0 | ||
| ipython[all] <8.15.0 # strict | ||
| torchmetrics >=0.10.0, <1.3.0 | ||
| deepspeed >=0.8.2, <=0.9.3; platform_system != "Windows" # strict | ||
| """ | ||
|
|
||
| def _create_requirements_file(self, local_path: Path, filename: str = "testing-cli-requirements.txt"): | ||
| """Create a sample requirements file.""" | ||
| req_file = local_path / filename | ||
| with open(req_file, "w", encoding="utf8") as fopen: | ||
| fopen.write(self.REQUIREMENTS_SAMPLE) | ||
| return str(req_file) | ||
|
|
||
| def _build_command(self, subcommand: str, cli_params: tuple, arg_style: str): | ||
| """Build the command for the CLI.""" | ||
| if arg_style == "positional": | ||
| return list(self.BASE_CMD) + [subcommand] + [value for _, value in cli_params] | ||
| if arg_style == "optional": | ||
| return list(self.BASE_CMD) + [subcommand] + [f"--{key}={value}" for key, value in cli_params] | ||
| raise ValueError(f"Unknown test configuration: {arg_style}") | ||
|
|
||
| def test_requirements_prune_pkgs(self, args, tmp_path): | ||
| """Prune packages from requirements files.""" | ||
| req_file = self._create_requirements_file(tmp_path) | ||
| cli_params = (("packages", "ipython"), ("req_files", req_file)) | ||
| cmd = self._build_command("prune-pkgs", cli_params, args) | ||
| return_code = subprocess.call(cmd) # noqa: S603 | ||
| assert return_code == 0 | ||
|
|
||
| def test_requirements_set_oldest(self, args, tmp_path): | ||
| """Set the oldest version of packages in requirement files.""" | ||
| req_file = self._create_requirements_file(tmp_path, "requirements.txt") | ||
| cli_params = (("req_files", req_file),) | ||
| cmd = self._build_command("set-oldest", cli_params, args) | ||
| return_code = subprocess.call(cmd) # noqa: S603 | ||
| assert return_code == 0 | ||
|
|
||
| def test_requirements_replace_pkg(self, args, tmp_path): | ||
| """Replace a package in requirements files.""" | ||
| req_file = self._create_requirements_file(tmp_path, "requirements.txt") | ||
| cli_params = (("old_package", "torchvision"), ("new_package", "torchtext"), ("req_files", req_file)) | ||
| cmd = self._build_command("replace-pkg", cli_params, args) | ||
| return_code = subprocess.call(cmd) # noqa: S603 | ||
| assert return_code == 0 |
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.