def test_non_numeric(): with pytest.raises(ValueError, match="must be integer numbers"): parse_vladmodels_spec("vladmodels katya y117 forty seven 154") Run with:
vladmodels katya y117 47 154 – into a useful data object and does a small bit of domain‑specific work (calculating the “size” of the product). vladmodels katya y117 47 154
Parameters ---------- spec: str Raw specification text. def test_non_numeric(): with pytest
# Optional sanity‑check (you can adjust the limits to your domain) if not (0 < width < 10_000 and 0 < height < 10_000): raise ValueError(f"Unreasonable dimensions: width mm × height mm") "vladmodels" name: str # e
@dataclass(frozen=True, slots=True) class VladModel: """A tiny data‑class representing a single VladModels product.""" brand: str # e.g. "vladmodels" name: str # e.g. "katya" code: str # e.g. "y117" width_mm: int # first numeric value (mm) height_mm: int # second numeric value (mm)
def test_basic_parsing(): raw = "vladmodels katya y117 47 154" model = parse_vladmodels_spec(raw) assert model == VladModel( brand="vladmodels", name="katya", code="y117", width_mm=47, height_mm=154, ) assert model.area_mm2 == 47 * 154