Skip to content

Commit d94be36

Browse files
committed
Test verbosity
1 parent b129452 commit d94be36

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/wristpy/core/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,16 @@ def main(
111111
"-e",
112112
"--epoch-length",
113113
help="Specify the sampling rate in seconds for all metrics. "
114-
"Must be greater than 1.",
114+
"Must be greater than or equal to 1.",
115115
min=1,
116116
),
117117
verbosity: int = typer.Option(
118118
0,
119119
"-v",
120120
"--verbosity",
121121
count=True,
122-
help="Determines the level of verbosity. Use -v for info, -vv for debug. "
122+
help="Determines the level of verbosity. Use -v for info, -vv for debug."
123+
"If -vvv or more, it will be set to debug."
123124
"Default for warning.",
124125
),
125126
version: bool = typer.Option(

tests/unit/test_cli.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_main_with_bad_thresholds(
164164
) -> None:
165165
"""Test cli with bad thresholds."""
166166
result = create_typer_cli_runner.invoke(
167-
cli.app, [str(sample_data_gt3x), "-t", "-3.0"]
167+
cli.app, [str(sample_data_gt3x), "-t", "3.0"]
168168
)
169169

170170
assert result.exit_code != 0
@@ -178,10 +178,33 @@ def test_main_with_bad_epoch(
178178
) -> None:
179179
"""Test cli with invalid epoch length."""
180180
result = create_typer_cli_runner.invoke(
181-
cli.app, ([str(sample_data_gt3x), "-e", "-5"])
181+
cli.app, [str(sample_data_gt3x), "-e", "-5"]
182182
)
183183

184184
assert result.exit_code != 0
185185
# partial matching due to ANSI escape sequences in Github Actions
186186
assert "Invalid value for" in result.output
187187
assert "is not in the range x>=1." in result.output
188+
189+
190+
@pytest.mark.parametrize(
191+
"verbosity, expected_log_level",
192+
[
193+
("-v", logging.INFO),
194+
("-vv", logging.DEBUG),
195+
("-vvv", logging.DEBUG),
196+
],
197+
)
198+
def test_main_verbosity(
199+
mocker: pytest_mock.MockerFixture,
200+
sample_data_gt3x: pathlib.Path,
201+
create_typer_cli_runner: CliRunner,
202+
verbosity: int,
203+
expected_log_level: int,
204+
) -> None:
205+
"""Test cli with different verbosity levels."""
206+
mock_run = mocker.patch.object(orchestrator, "run")
207+
208+
create_typer_cli_runner.invoke(cli.app, [str(sample_data_gt3x), verbosity])
209+
210+
assert mock_run.call_args.kwargs["verbosity"] == expected_log_level

0 commit comments

Comments
 (0)