feat: add extensible operators and golden flows
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from govoplan_dataflow.backend.executor import execute_preview
|
||||
from govoplan_dataflow.backend.graph import validate_graph
|
||||
from govoplan_dataflow.backend.schemas import PipelineGraph
|
||||
|
||||
|
||||
FIXTURES = Path(__file__).parents[1] / "fixtures" / "golden"
|
||||
|
||||
|
||||
class GoldenFlowTests(unittest.TestCase):
|
||||
def test_every_golden_flow_matches_its_expected_output(self) -> None:
|
||||
directories = sorted(
|
||||
path for path in FIXTURES.iterdir() if path.is_dir()
|
||||
)
|
||||
self.assertGreaterEqual(len(directories), 2)
|
||||
for directory in directories:
|
||||
with self.subTest(flow=directory.name):
|
||||
manifest = _json(directory / "manifest.json")
|
||||
graph_payload = _json(directory / str(manifest["graph"]))
|
||||
for item in graph_payload["nodes"]:
|
||||
fixture = item.get("config", {}).get("fixture")
|
||||
if fixture:
|
||||
item["config"]["rows"] = _json(
|
||||
directory / "inputs" / fixture
|
||||
)
|
||||
graph = PipelineGraph.model_validate(graph_payload)
|
||||
diagnostics = validate_graph(graph)
|
||||
self.assertEqual(
|
||||
[],
|
||||
[
|
||||
item.model_dump()
|
||||
for item in diagnostics
|
||||
if item.severity == "error"
|
||||
],
|
||||
)
|
||||
|
||||
result = execute_preview(graph, row_limit=500)
|
||||
|
||||
self.assertEqual(
|
||||
_json(directory / str(manifest["expected_output"])),
|
||||
result.rows,
|
||||
)
|
||||
|
||||
|
||||
def _json(path: Path):
|
||||
return json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user