roll/tests/cli/roll_param_test.py

39 lines
1.2 KiB
Python
Raw Normal View History

2023-08-13 18:54:11 +00:00
import click
import pytest
from roll.cli.roll_param import RollParam
from roll.roll import Roll
def test_roll_param_passthrough():
roll = Roll()
result = RollParam().convert(roll, None, None)
assert result == roll
@pytest.mark.parametrize("value", ["1d20", "2d20+3", "4d6-3"])
def test_roll_param_valid(value):
result = RollParam().convert(value, None, None)
assert isinstance(result, Roll)
assert result.to_str() == value
@pytest.mark.parametrize("value", ["advantage", "disadvantage"])
def test_roll_param_advantage(value):
result = RollParam().convert(value, None, None)
assert result == value
@pytest.mark.parametrize("value", ["d90", "0d", "d-1", "aba", "000", "1d1d1d"])
def test_roll_param_invalid(value):
with pytest.raises(click.exceptions.BadParameter) as e:
RollParam().convert(value, None, None)
assert value in e.value.message
@pytest.mark.parametrize("value", ["0d0", "0d20", "1d0", "1d1"])
def test_roll_param_invalid_properties(value):
with pytest.raises(click.exceptions.BadParameter) as e:
RollParam().convert(value, None, None)
assert "sides" in e.value.message or "dice" in e.value.message