Skip to content

Commit

Permalink
add parametrize to test cli with and without output_path arg
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Dec 20, 2024
1 parent 2866e3b commit 7ab890b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import patch

import numpy as np
import pytest
from typer.testing import CliRunner

from bimorph_mirror_analysis import __version__
Expand All @@ -11,15 +12,37 @@
runner = CliRunner()


def test_app():
@pytest.mark.parametrize(
["outpath"],
[
["tests/data/out.csv"],
[False],
],
)
def test_app(outpath: str | bool):
with (
patch("bimorph_mirror_analysis.__main__.np.savetxt") as mock_np_save,
patch(
"bimorph_mirror_analysis.__main__.calculate_optimal_voltages"
) as mock_calculate_optimal_voltages,
):
mock_calculate_optimal_voltages.return_value = np.array([72.14, 50.98, 18.59])
result = runner.invoke(app, ["calculate-voltages", "tests/data/raw_data.csv"])
if outpath is not False:
print("\n\n\n\n\n\n")
result = runner.invoke(
app,
[
"calculate-voltages",
"tests/data/raw_data.csv",
"--output_path",
f"{outpath}",
],
)
print("aaa")
elif not outpath:
result = runner.invoke(
app, ["calculate-voltages", "tests/data/raw_data.csv"]
)
mock_np_save.assert_called_once()
mock_calculate_optimal_voltages.assert_called_with("tests/data/raw_data.csv")
assert "The optimal voltages are: [72.14, 50.98, 18.59]" in result.stdout
Expand Down

0 comments on commit 7ab890b

Please sign in to comment.