- Notifications
You must be signed in to change notification settings - Fork673
test(cli): improve basic CLI coverage#1721
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
6 changes: 3 additions & 3 deletionsgitlab/cli.py
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 |
---|---|---|
@@ -178,7 +178,7 @@ def _parse_value(v: Any) -> Any: | ||
return v | ||
def docs() -> argparse.ArgumentParser: # pragma: no cover | ||
""" | ||
Provide a statically generated parser for sphinx only, so we don't need | ||
to provide dummy gitlab config for readthedocs. | ||
@@ -208,15 +208,15 @@ def main() -> None: | ||
sys.exit(0) | ||
sys.exit(e) | ||
# We only support v4 API at this time | ||
if config.api_version not in ("4",): # dead code # pragma: no cover | ||
nejch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
raise ModuleNotFoundError(name=f"gitlab.v{config.api_version}.cli") | ||
# Now we build the entire set of subcommands and do the complete parsing | ||
parser = _get_parser() | ||
try: | ||
import argcomplete # type: ignore | ||
argcomplete.autocomplete(parser) # pragma: no cover | ||
except Exception: | ||
pass | ||
args = parser.parse_args() | ||
1 change: 1 addition & 0 deletionspyproject.toml
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
1 change: 0 additions & 1 deletionrequirements-docker.txt
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
-r requirements.txt | ||
-r requirements-test.txt | ||
docker-compose==1.29.2 # prevent inconsistent .env behavior from system install | ||
pytest-docker |
2 changes: 1 addition & 1 deletionrequirements-test.txt
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
coverage | ||
httmock | ||
pytest | ||
pytest-console-scripts==1.2.1 | ||
pytest-cov | ||
responses |
6 changes: 6 additions & 0 deletionstests/conftest.py
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,6 @@ | ||
import pytest | ||
@pytest.fixture(scope="session") | ||
def test_dir(pytestconfig): | ||
return pytestconfig.rootdir / "tests" |
12 changes: 3 additions & 9 deletionstests/functional/api/test_users.py
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
49 changes: 49 additions & 0 deletionstests/functional/cli/test_cli.py
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,49 @@ | ||
import json | ||
from gitlab import __version__ | ||
def test_main_entrypoint(script_runner, gitlab_config): | ||
ret = script_runner.run("python", "-m", "gitlab", "--config-file", gitlab_config) | ||
assert ret.returncode == 2 | ||
def test_version(script_runner): | ||
ret = script_runner.run("gitlab", "--version") | ||
assert ret.stdout.strip() == __version__ | ||
def test_invalid_config(script_runner): | ||
ret = script_runner.run("gitlab", "--gitlab", "invalid") | ||
assert not ret.success | ||
assert not ret.stdout | ||
def test_invalid_config_prints_help(script_runner): | ||
ret = script_runner.run("gitlab", "--gitlab", "invalid", "--help") | ||
assert ret.success | ||
assert ret.stdout | ||
def test_invalid_api_version(script_runner, monkeypatch, fixture_dir): | ||
monkeypatch.setenv("PYTHON_GITLAB_CFG", str(fixture_dir / "invalid_version.cfg")) | ||
ret = script_runner.run("gitlab", "--gitlab", "test", "project", "list") | ||
assert not ret.success | ||
assert ret.stderr.startswith("Unsupported API version:") | ||
def test_invalid_auth_config(script_runner, monkeypatch, fixture_dir): | ||
monkeypatch.setenv("PYTHON_GITLAB_CFG", str(fixture_dir / "invalid_auth.cfg")) | ||
ret = script_runner.run("gitlab", "--gitlab", "test", "project", "list") | ||
assert not ret.success | ||
assert "401" in ret.stderr | ||
def test_fields(gitlab_cli, project_file): | ||
cmd = "-o", "json", "--fields", "default_branch", "project", "list" | ||
ret = gitlab_cli(cmd) | ||
assert ret.success | ||
content = json.loads(ret.stdout.strip()) | ||
assert ["default_branch" in item for item in content] |
22 changes: 11 additions & 11 deletionstests/functional/conftest.py
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
3 changes: 3 additions & 0 deletionstests/functional/fixtures/invalid_auth.cfg
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,3 @@ | ||
[test] | ||
url = https://gitlab.com | ||
private_token = abc123 |
3 changes: 3 additions & 0 deletionstests/functional/fixtures/invalid_version.cfg
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,3 @@ | ||
[test] | ||
api_version = 3 | ||
url = https://gitlab.example.com |
5 changes: 5 additions & 0 deletionstests/unit/conftest.py
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
File renamed without changes.
12 changes: 7 additions & 5 deletionstests/unit/objects/test_todos.py
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
14 changes: 11 additions & 3 deletionstests/unit/test_cli.py
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
2 changes: 1 addition & 1 deletiontests/unit/test_config.py
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
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.