| 320 | |
| 321 | class TestFromFilePaths: |
| 322 | def test_toon_files(self, tmp_path): |
| 323 | if not from_file.toon_available: |
| 324 | pytest.skip("toon_format is not installed") |
| 325 | good = tmp_path / "data.toon" |
| 326 | Box(a=1, b="x").to_toon(filename=good) |
| 327 | assert box_from_file(good).to_dict() == {"a": 1, "b": "x"} |
| 328 | rows = tmp_path / "rows.toon" |
| 329 | BoxList([{"a": 1}, {"a": 2}]).to_toon(filename=rows) |
| 330 | assert box_from_file(rows).to_list() == [{"a": 1}, {"a": 2}] |
| 331 | bad = tmp_path / "bad.toon" |
| 332 | bad.write_text('a: "unterminated\n') |
| 333 | with pytest.raises(BoxError, match="not TOON"): |
| 334 | box_from_file(bad) |
| 335 | |
| 336 | def test_toon_unavailable(self, tmp_path, monkeypatch): |
| 337 | monkeypatch.setattr(from_file, "toon_available", False) |