Skip to content

Commit 590e712

Browse files
committed
refactor(info): describe as @click.command
1 parent 25ed496 commit 590e712

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

compiler_admin/commands/info.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from compiler_admin import __version__ as version, RESULT_SUCCESS, RESULT_FAILURE
2-
from compiler_admin.services.google import CallGAMCommand, CallGYBCommand
1+
import click
32

3+
from compiler_admin import __version__ as version
4+
from compiler_admin.services.google import CallGAMCommand, CallGYBCommand
45

5-
def info(*args, **kwargs) -> int:
6-
"""Print information about this package and the GAM environment.
76

8-
Returns:
9-
A value indicating if the operation succeeded or failed.
7+
@click.command()
8+
def info():
109
"""
11-
print(f"compiler-admin: {version}")
12-
13-
res = CallGAMCommand(("version",))
14-
res += CallGAMCommand(("info", "domain"))
15-
res += CallGYBCommand(("--version",))
10+
Print information about the configured environment.
11+
"""
12+
click.echo(f"compiler-admin, version {version}")
1613

17-
return RESULT_SUCCESS if res == RESULT_SUCCESS else RESULT_FAILURE
14+
CallGAMCommand(("version",))
15+
CallGAMCommand(("info", "domain"))
16+
CallGYBCommand(("--version",))

tests/commands/test_info.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import pytest
22

3-
from compiler_admin import RESULT_SUCCESS
3+
from compiler_admin import RESULT_SUCCESS, __version__
44
from compiler_admin.commands.info import info, __name__ as MODULE
5-
from compiler_admin.services.google import DOMAIN
65

76

87
@pytest.fixture
@@ -15,21 +14,10 @@ def mock_google_CallGYBCommand(mock_google_CallGYBCommand):
1514
return mock_google_CallGYBCommand(MODULE)
1615

1716

18-
def test_info(mock_google_CallGAMCommand, mock_google_CallGYBCommand):
19-
info()
17+
def test_info(cli_runner, mock_google_CallGAMCommand, mock_google_CallGYBCommand):
18+
result = cli_runner.invoke(info)
2019

20+
assert result.exit_code == RESULT_SUCCESS
21+
assert f"compiler-admin, version {__version__}" in result.output
2122
assert mock_google_CallGAMCommand.call_count > 0
2223
mock_google_CallGYBCommand.assert_called_once()
23-
24-
25-
@pytest.mark.e2e
26-
def test_info_e2e(capfd):
27-
res = info()
28-
captured = capfd.readouterr()
29-
30-
assert res == RESULT_SUCCESS
31-
assert "compiler-admin:" in captured.out
32-
assert "GAMADV-XTD3" in captured.out
33-
assert f"Primary Domain: {DOMAIN}" in captured.out
34-
assert "Got Your Back" in captured.out
35-
assert "WARNING: Config File:" not in captured.err

tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from click.testing import CliRunner
2+
13
import pytest
24
from pytest_socket import disable_socket
35

@@ -186,6 +188,11 @@ def _mock_NamedTemporaryFile(module, readlines=[""], **kwargs):
186188
return _mock_NamedTemporaryFile
187189

188190

191+
@pytest.fixture
192+
def cli_runner():
193+
return CliRunner()
194+
195+
189196
@pytest.fixture
190197
def harvest_file():
191198
return "notebooks/data/harvest-sample.csv"

0 commit comments

Comments
 (0)