Skip to content

Commit

Permalink
add more cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klamann committed Sep 23, 2024
1 parent 3d4b165 commit fd750d1
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
from click.testing import Result
from typer.testing import CliRunner

from raspi_poe_mon import main
from raspi_poe_mon.main import app
from raspi_poe_mon.version import __version__

Expand All @@ -9,30 +11,41 @@

def test_main_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "raspi-poe-mon" in result.stdout
validate_help(result, "raspi-poe-mon")


def test_main_help_short():
result = runner.invoke(app, ["-h"])
assert result.exit_code == 0
assert "raspi-poe-mon" in result.stdout
validate_help(result, "raspi-poe-mon")


def test_main_no_params():
result = runner.invoke(app, [])
assert result.exit_code == 0
assert "raspi-poe-mon" in result.stdout
validate_help(result, "raspi-poe-mon")


def test_version():
result = runner.invoke(app, ["--version"])
assert result.exit_code == 0
assert __version__ in result.stdout
validate_help(result, __version__)


@pytest.mark.parametrize("command", ["display", "fan", "run"])
def test_command_help(command: str):
result = runner.invoke(app, [command, "--help"])
validate_help(result, f"raspi-poe-mon {command}")


def validate_help(result: Result, contains: str):
assert result.exit_code == 0
assert f"raspi-poe-mon {command}" in result.stdout
assert contains in result.stdout
print(result.stdout)


@pytest.mark.timeout(2)
def test_dry_run():
main.run(dry_run=True, verbose=True, frame_time=0.02, timeout=0.05)


@pytest.mark.timeout(2)
def test_profiling():
main.run(dry_run=True, profiling=True, frame_time=0.05, timeout=0.1)

0 comments on commit fd750d1

Please sign in to comment.