roll/tests/cli/cli_test.py

36 lines
1.1 KiB
Python

import pytest
from click.testing import CliRunner
from roll.cli import cli
from roll.roll import Roll
@pytest.fixture
def runner() -> CliRunner:
return CliRunner()
def test_cli_smoke(runner: CliRunner):
result = runner.invoke(cli, [])
assert result.exit_code == 0
assert result.output.startswith("throwing 1d20:\n1:\t")
assert "total" in result.output
@pytest.mark.parametrize("value", ["2d20", "4d6-2", "9d100+3"])
def test_cli_roll(runner: CliRunner, value: str):
result = runner.invoke(cli, [value])
roll = Roll.from_str(value)
assert result.exit_code == 0
assert result.output.startswith(f"throwing {value}:\n1:\t")
assert len(result.output.splitlines()) >= roll.dice_count + 2
assert "total" in result.output
@pytest.mark.parametrize("advantage", ["advantage", "disadvantage"])
def test_cli_advantage(runner: CliRunner, advantage: str):
result = runner.invoke(cli, [advantage])
assert result.exit_code == 0
assert result.output.startswith(f"throwing 2d20 with {advantage}:\n1:\t")
assert "total" in result.output