|
11 | 11 | """ |
12 | 12 |
|
13 | 13 | import json |
14 | | -from pathlib import Path |
15 | 14 | from typing import Any, Dict, List |
16 | 15 |
|
17 | 16 | import pytest |
18 | 17 |
|
19 | 18 | from toon_format import ToonDecodeError, decode, encode |
20 | 19 | from toon_format.types import DecodeOptions, EncodeOptions |
| 20 | +from tests.test_spec_fixtures import get_all_decode_fixtures |
21 | 21 |
|
22 | 22 |
|
23 | 23 | class TestEncodeAPI: |
@@ -302,32 +302,21 @@ class TestDecodeJSONIndentation: |
302 | 302 | pass |
303 | 303 |
|
304 | 304 |
|
305 | | -def _load_fixture_file(filepath: Path) -> Dict[str, Any]: |
306 | | - """Load a fixture JSON file.""" |
307 | | - with open(filepath, encoding="utf-8") as f: |
308 | | - return json.load(f) |
309 | | - |
310 | | - |
311 | 305 | def _get_sample_decode_fixtures() -> List[tuple]: |
312 | | - """Get a sample of decode test cases from fixture files for json_indent testing.""" |
313 | | - fixtures_dir = Path(__file__).parent / "fixtures" / "decode" |
| 306 | + """Get a sample of decode test cases from fixture files for json_indent testing. |
| 307 | + |
| 308 | + Selects a few representative test cases from the official TOON spec fixtures. |
| 309 | + """ |
| 310 | + all_fixtures = get_all_decode_fixtures() |
| 311 | + |
| 312 | + # Select a few representative test cases from different fixture categories |
| 313 | + selected_files = {"primitives.json", "arrays-primitive.json", "objects.json"} |
314 | 314 | test_cases = [] |
315 | | - |
316 | | - # Select a few representative fixture files |
317 | | - fixture_files = [ |
318 | | - "primitives.json", |
319 | | - "arrays-primitive.json", |
320 | | - "objects.json", |
321 | | - ] |
322 | | - |
323 | | - for filename in fixture_files: |
324 | | - fixture_path = fixtures_dir / filename |
325 | | - if fixture_path.exists(): |
326 | | - fixture_data = _load_fixture_file(fixture_path) |
327 | | - for idx, test in enumerate(fixture_data.get("tests", [])[:3]): # Sample 3 from each |
328 | | - test_id = f"{filename}::{test['name']}" |
329 | | - test_cases.append((test_id, test)) |
330 | | - |
| 315 | + |
| 316 | + for test_id, test_data, fixture_name in all_fixtures: |
| 317 | + if f"{fixture_name}.json" in selected_files and len(test_cases) < 9: |
| 318 | + test_cases.append((test_id, test_data)) |
| 319 | + |
331 | 320 | return test_cases |
332 | 321 |
|
333 | 322 |
|
|
0 commit comments