"""IMP-09 PR 1 — _parse_fr_string tests. Catalog presets only use `1fr` / `1fr 1fr` specs (verified templates/phase_z2/layouts/layouts.yaml). The helper must reject non-fr tokens and round to integer pixel sizes summing to `total`. """ from __future__ import annotations import pytest from src.phase_z2_pipeline import _parse_fr_string def test_single_fr_returns_full_total(): assert _parse_fr_string("1fr", 585) == [585] def test_two_equal_fr_splits_evenly(): result = _parse_fr_string("1fr 1fr", 1180) assert result == [590, 590] assert sum(result) == 1180 def test_unequal_fr_distributes_by_ratio(): result = _parse_fr_string("2fr 1fr", 300) assert sum(result) == 300 assert result[0] > result[1] def test_rounding_absorbed_by_last_track(): # 1fr 1fr 1fr / total=100 -> 33,33,33 + diff 1 absorbed by last. result = _parse_fr_string("1fr 1fr 1fr", 100) assert sum(result) == 100 assert result == [33, 33, 34] def test_non_fr_token_raises(): with pytest.raises(ValueError, match="non-fr token"): _parse_fr_string("200px 1fr", 1000) def test_empty_spec_raises(): with pytest.raises(ValueError, match="empty spec"): _parse_fr_string("", 1000) def test_zero_fr_raises(): with pytest.raises(ValueError, match="total fr"): _parse_fr_string("0fr 0fr", 1000)