54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from graphrag_platform.sources import JsonLinesSourceReader
|
|
|
|
|
|
def test_jsonl_source_contract_preserves_nested_metadata(tmp_path: Path) -> None:
|
|
source = tmp_path / "source.jsonl"
|
|
source.write_text(
|
|
json.dumps(
|
|
{
|
|
"schema_version": "1.0",
|
|
"external_id": "record-1",
|
|
"corpus": "test",
|
|
"url": "https://example.test/article",
|
|
"body": "<main>Text, with commas and \"quotes\".</main>",
|
|
"retrieved_at": "2026-10-13T18:00:00Z",
|
|
"metadata": {"tags": ["one", "two"], "nested": {"value": 1}},
|
|
}
|
|
)
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
records = list(JsonLinesSourceReader(source).records())
|
|
|
|
assert records[0].external_id == "record-1"
|
|
assert records[0].metadata["tags"] == ["one", "two"]
|
|
assert '"quotes"' in records[0].body
|
|
|
|
|
|
def test_jsonl_source_contract_rejects_unknown_schema(tmp_path: Path) -> None:
|
|
source = tmp_path / "source.jsonl"
|
|
source.write_text(
|
|
json.dumps(
|
|
{
|
|
"schema_version": "2.0",
|
|
"external_id": "record-1",
|
|
"url": "https://example.test/article",
|
|
"body": "text",
|
|
"retrieved_at": "2026-10-13T18:00:00Z",
|
|
}
|
|
)
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
with pytest.raises(ValueError, match="unsupported source schema"):
|
|
list(JsonLinesSourceReader(source).records())
|