Skip to content

Commit 7a5a4be

Browse files
committed
adding tests
1 parent 328055f commit 7a5a4be

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

cloudsmith_cli/cli/commands/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def main(ctx, opts, version, no_warn):
7373
opts.no_warn = True
7474

7575
if version:
76+
opts.no_warn = True
7677
print_version()
7778
elif ctx.invoked_subcommand is None:
7879
click.echo(ctx.get_help())

cloudsmith_cli/cli/tests/commands/test_main.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66

77

88
class TestMainCommand:
9-
@pytest.mark.usefixtures("set_no_warn_env_var")
109
@pytest.mark.parametrize("option", ["-V", "--version"])
1110
def test_main_version(self, runner, option):
1211
"""Test the output of `cloudsmith --version`."""
1312
result = runner.invoke(main, [option])
1413
assert result.exit_code == 0
15-
assert (
16-
result.output == "Versions:\n"
17-
"CLI Package Version: " + get_version() + "\n"
18-
"API Package Version: " + get_api_version() + "\n"
19-
)
14+
15+
assert "CLI Package Version: " + get_version() in result.output
16+
assert "API Package Version: " + get_api_version() in result.output
2017

2118
@pytest.mark.parametrize("option", ["-h", "--help"])
2219
def test_main_help(self, runner, option):
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from cloudsmith_cli.cli.warnings import (
2+
ApiAuthenticationWarning,
3+
CliWarnings,
4+
ConfigLoadWarning,
5+
ProfileNotFoundWarning,
6+
)
7+
8+
9+
class TestWarnings:
10+
def test_warning_append(self):
11+
"""Test appending warnings to the CliWarnings."""
12+
13+
config_load_warning_1 = ConfigLoadWarning({"test_path_1": False})
14+
config_load_warning_2 = ConfigLoadWarning({"test_path_2": True})
15+
profile_load_warning = ProfileNotFoundWarning(
16+
{"test_path_1": False}, "test_profile"
17+
)
18+
api_authentication_warning = ApiAuthenticationWarning("test.cloudsmith.io")
19+
cli_warnings = CliWarnings()
20+
cli_warnings.append(config_load_warning_1)
21+
cli_warnings.append(config_load_warning_2)
22+
cli_warnings.append(profile_load_warning)
23+
cli_warnings.append(profile_load_warning)
24+
cli_warnings.append(api_authentication_warning)
25+
assert len(cli_warnings) == 5
26+
assert len(cli_warnings.__dedupe__()) == 4

0 commit comments

Comments
 (0)