Skip to content

Commit 9f906f9

Browse files
committed
refactor: Use existing fixture loader in test_api.py
Refactored to import and reuse get_all_decode_fixtures() from test_spec_fixtures.py instead of duplicating fixture loading logic. This reduces code duplication and ensures both test modules use the same official TOON spec fixtures.
1 parent 44ffada commit 9f906f9

1 file changed

Lines changed: 14 additions & 25 deletions

File tree

tests/test_api.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
"""
1212

1313
import json
14-
from pathlib import Path
1514
from typing import Any, Dict, List
1615

1716
import pytest
1817

1918
from toon_format import ToonDecodeError, decode, encode
2019
from toon_format.types import DecodeOptions, EncodeOptions
20+
from tests.test_spec_fixtures import get_all_decode_fixtures
2121

2222

2323
class TestEncodeAPI:
@@ -302,32 +302,21 @@ class TestDecodeJSONIndentation:
302302
pass
303303

304304

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-
311305
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"}
314314
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+
331320
return test_cases
332321

333322

0 commit comments

Comments
 (0)