diff --git a/src/playtest2/steps/core.py b/src/playtest2/steps/core.py index ed8938c..9306bf8 100644 --- a/src/playtest2/steps/core.py +++ b/src/playtest2/steps/core.py @@ -10,11 +10,50 @@ def assert_string_value(expected: str): @step("整数値のである") def assert_int_value(expected: str): actual = data_store.spec.pop("actual") - expected = int(expected) - assert actual == expected, f"Expected {expected!r} but got {actual!r}" # noqa: S101 + expected_int = int(expected) + assert actual == expected_int, f"Expected {expected_int!r} but got {actual!r}" # noqa: S101 @step("真である") def assert_true_value(): actual = data_store.spec.pop("actual") assert actual is True, f"Expected True but got {actual!r}" # noqa: S101 + + +@step("文字列のを含んでいる") +def assert_string_contains(expected: str): + actual = data_store.spec.pop("actual") + assert expected in actual, f"Expected {actual!r} to contain {expected!r}" # noqa: S101 + + +@step("小数値のである") +def assert_float_value(expected: str): + actual = data_store.spec.pop("actual") + expected_float = float(expected) + assert actual == expected_float, f"Expected {expected_float!r} but got {actual!r}" # noqa: S101 + + +@step("整数値の以上である") +def assert_int_greater_equal(expected: str): + actual = data_store.spec.pop("actual") + expected_int = int(expected) + assert actual >= expected_int, f"Expected {actual!r} to be >= {expected_int!r}" # noqa: S101 + + +@step("偽である") +def assert_false_value(): + actual = data_store.spec.pop("actual") + assert actual is False, f"Expected False but got {actual!r}" # noqa: S101 + + +@step("真偽値のである") +def assert_bool_value(expected: str): + actual = data_store.spec.pop("actual") + expected_bool = expected == "True" + assert actual == expected_bool, f"Expected {expected_bool!r} but got {actual!r}" # noqa: S101 + + +@step("nullである") +def assert_null_value(): + actual = data_store.spec.pop("actual") + assert actual is None, f"Expected None but got {actual!r}" # noqa: S101 diff --git a/tests/steps/test_core.py b/tests/steps/test_core.py index fbce643..9575d06 100644 --- a/tests/steps/test_core.py +++ b/tests/steps/test_core.py @@ -64,3 +64,149 @@ def test_assert_true_value_fail(): core_steps.assert_true_value() assert "actual" not in data_store.spec + + +def test_assert_string_contains_pass(): + from getgauge.python import data_store + + data_store.spec["actual"] = "hello world" + + core_steps.assert_string_contains("world") + + assert "actual" not in data_store.spec + + +def test_assert_string_contains_fail(): + from getgauge.python import data_store + + data_store.spec["actual"] = "hello world" + + with pytest.raises(AssertionError): + core_steps.assert_string_contains("python") + + assert "actual" not in data_store.spec + + +def test_assert_float_value_pass(): + from getgauge.python import data_store + + data_store.spec["actual"] = 3.14 + + core_steps.assert_float_value("3.14") + + assert "actual" not in data_store.spec + + +def test_assert_float_value_fail(): + from getgauge.python import data_store + + data_store.spec["actual"] = 3.14 + + with pytest.raises(AssertionError): + core_steps.assert_float_value("2.71") + + assert "actual" not in data_store.spec + + +def test_assert_int_greater_equal_pass(): + from getgauge.python import data_store + + data_store.spec["actual"] = 42 + + core_steps.assert_int_greater_equal("40") + + assert "actual" not in data_store.spec + + +def test_assert_int_greater_equal_equal_pass(): + from getgauge.python import data_store + + data_store.spec["actual"] = 42 + + core_steps.assert_int_greater_equal("42") + + assert "actual" not in data_store.spec + + +def test_assert_int_greater_equal_fail(): + from getgauge.python import data_store + + data_store.spec["actual"] = 42 + + with pytest.raises(AssertionError): + core_steps.assert_int_greater_equal("50") + + assert "actual" not in data_store.spec + + +def test_assert_false_value_pass(): + from getgauge.python import data_store + + data_store.spec["actual"] = False + + core_steps.assert_false_value() + + assert "actual" not in data_store.spec + + +def test_assert_false_value_fail(): + from getgauge.python import data_store + + data_store.spec["actual"] = True + + with pytest.raises(AssertionError): + core_steps.assert_false_value() + + assert "actual" not in data_store.spec + + +def test_assert_bool_value_pass_true(): + from getgauge.python import data_store + + data_store.spec["actual"] = True + + core_steps.assert_bool_value("True") + + assert "actual" not in data_store.spec + + +def test_assert_bool_value_pass_false(): + from getgauge.python import data_store + + data_store.spec["actual"] = False + + core_steps.assert_bool_value("False") + + assert "actual" not in data_store.spec + + +def test_assert_bool_value_fail(): + from getgauge.python import data_store + + data_store.spec["actual"] = True + + with pytest.raises(AssertionError): + core_steps.assert_bool_value("False") + + assert "actual" not in data_store.spec + + +def test_assert_null_value_pass(): + from getgauge.python import data_store + + data_store.spec["actual"] = None + + core_steps.assert_null_value() + + assert "actual" not in data_store.spec + + +def test_assert_null_value_fail(): + from getgauge.python import data_store + + data_store.spec["actual"] = "not null" + + with pytest.raises(AssertionError): + core_steps.assert_null_value() + + assert "actual" not in data_store.spec