Add validation tests for combat move timing fields

This commit is contained in:
Jared Miller 2026-02-16 14:49:06 -05:00
parent 03d04f0a33
commit 0a9a7f74bc
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -223,8 +223,8 @@ hit_time_ms = 800
load_move(toml_file) load_move(toml_file)
def test_load_move_missing_hit_time(tmp_path): def test_load_attack_missing_hit_time_raises(tmp_path):
"""Test loading move without hit_time_ms defaults to 0.""" """Test loading attack without hit_time_ms raises error."""
toml_content = """ toml_content = """
name = "test" name = "test"
move_type = "attack" move_type = "attack"
@ -233,9 +233,87 @@ stamina_cost = 5.0
toml_file = tmp_path / "bad.toml" toml_file = tmp_path / "bad.toml"
toml_file.write_text(toml_content) toml_file.write_text(toml_content)
with pytest.raises(ValueError, match="hit_time_ms"):
load_move(toml_file)
def test_load_attack_zero_hit_time_raises(tmp_path):
"""Test loading attack with hit_time_ms = 0 raises error."""
toml_content = """
name = "test"
move_type = "attack"
stamina_cost = 5.0
hit_time_ms = 0
"""
toml_file = tmp_path / "bad.toml"
toml_file.write_text(toml_content)
with pytest.raises(ValueError, match="hit_time_ms"):
load_move(toml_file)
def test_load_defense_missing_active_ms_raises(tmp_path):
"""Test loading defense without active_ms raises error."""
toml_content = """
name = "test"
move_type = "defense"
stamina_cost = 3.0
recovery_ms = 2000
"""
toml_file = tmp_path / "bad.toml"
toml_file.write_text(toml_content)
with pytest.raises(ValueError, match="active_ms"):
load_move(toml_file)
def test_load_defense_zero_active_ms_raises(tmp_path):
"""Test loading defense with active_ms = 0 raises error."""
toml_content = """
name = "test"
move_type = "defense"
stamina_cost = 3.0
active_ms = 0
recovery_ms = 2000
"""
toml_file = tmp_path / "bad.toml"
toml_file.write_text(toml_content)
with pytest.raises(ValueError, match="active_ms"):
load_move(toml_file)
def test_load_attack_valid_passes(tmp_path):
"""Test loading attack with valid hit_time_ms passes."""
toml_content = """
name = "test"
move_type = "attack"
stamina_cost = 5.0
hit_time_ms = 500
"""
toml_file = tmp_path / "valid.toml"
toml_file.write_text(toml_content)
moves = load_move(toml_file) moves = load_move(toml_file)
assert len(moves) == 1 assert len(moves) == 1
assert moves[0].hit_time_ms == 0 assert moves[0].hit_time_ms == 500
def test_load_defense_valid_passes(tmp_path):
"""Test loading defense with valid active_ms passes."""
toml_content = """
name = "test"
move_type = "defense"
stamina_cost = 3.0
active_ms = 500
recovery_ms = 2000
"""
toml_file = tmp_path / "valid.toml"
toml_file.write_text(toml_content)
moves = load_move(toml_file)
assert len(moves) == 1
assert moves[0].active_ms == 500
def test_load_moves_from_directory(tmp_path): def test_load_moves_from_directory(tmp_path):