Переглянути джерело

Add garden test fixture loading

Lukas Goldschmidt 1 місяць тому
батько
коміт
c76d18f500
4 змінених файлів з 52 додано та 0 видалено
  1. 33 0
      examples/ganja_test_fixture.ttl
  2. 8 0
      src/garden_layer/helpers.py
  3. 1 0
      test.sh
  4. 10 0
      test_garden_layer.py

+ 33 - 0
examples/ganja_test_fixture.ttl

@@ -0,0 +1,33 @@
+@prefix ex: <http://world.eu.org/example1#> .
+@prefix cb: <http://world.eu.org/cannabis-breeding#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix dc: <http://purl.org/dc/elements/1.1/> .
+
+ex:ProductionCycle_21d96b6c-179 a cb:ProductionCycle ;
+    rdfs:label "Cycle 2026-3" ;
+    dc:description "Fixture production cycle for garden-layer tests." .
+
+ex:Strain_kerosene_reference a cb:Strain ;
+    rdfs:label "Kerosene Reference" ;
+    dc:description "Fixture strain for garden-layer tests." .
+
+ex:Plant_90d53925-bb5 a cb:IndividualPlant ;
+    rdfs:label "Kerosene Root" ;
+    dc:description "Fixture root plant for clone traversal." ;
+    cb:inCycle ex:ProductionCycle_21d96b6c-179 ;
+    cb:belongsToStrain ex:Strain_kerosene_reference .
+
+ex:Plant_kerosene_clone_a a cb:IndividualPlant ;
+    rdfs:label "Kerosene Clone A" ;
+    dc:description "First fixture clone." ;
+    cb:cloneOf ex:Plant_90d53925-bb5 ;
+    cb:inCycle ex:ProductionCycle_21d96b6c-179 ;
+    cb:belongsToStrain ex:Strain_kerosene_reference .
+
+ex:Plant_kerosene_clone_b a cb:IndividualPlant ;
+    rdfs:label "Kerosene Clone B" ;
+    dc:description "Second fixture clone." ;
+    cb:cloneOf ex:Plant_90d53925-bb5 ;
+    cb:inCycle ex:ProductionCycle_21d96b6c-179 ;
+    cb:belongsToStrain ex:Strain_kerosene_reference .

+ 8 - 0
src/garden_layer/helpers.py

@@ -59,6 +59,14 @@ class GardenLayer:
             payload["graph"] = graph
         return self._call("batch_insert", payload)
 
+    def load_examples(self, files: Optional[List[str]] = None, graph: Optional[str] = None) -> Any:
+        payload: Dict[str, Any] = {}
+        if files is not None:
+            payload["files"] = files
+        if graph:
+            payload["graph"] = graph
+        return self._call("garden_load_examples", payload)
+
     def reassign_cycle(self, plant_uri: str, new_cycle_uri: str, old_cycle_uri: Optional[str] = None) -> Any:
         payload = {
             "subject": plant_uri,

+ 1 - 0
test.sh

@@ -11,4 +11,5 @@ if [[ -n "${GARDEN_LAYER_VENV:-}" ]]; then
 fi
 
 export PYTHONPATH="$PWD/src${PYTHONPATH:+:$PYTHONPATH}"
+export MCP_ALLOW_EXAMPLE_LOAD="${MCP_ALLOW_EXAMPLE_LOAD:-true}"
 python3 -m pytest -v -s test_garden_layer.py

+ 10 - 0
test_garden_layer.py

@@ -7,6 +7,7 @@ from garden_layer import GardenLayer
 from garden_layer.config import CLONE_OF, GRAPH, KEROSENE_ROOT, MCP_URL
 
 CYCLE_2026_3 = "http://world.eu.org/example1#ProductionCycle_21d96b6c-179"
+FIXTURE_FILES = ["ganja_test_fixture.ttl"]
 
 
 def pytest_report_header(config):
@@ -20,6 +21,15 @@ def garden_layer():
         layer.traverse(KEROSENE_ROOT, CLONE_OF, direction="incoming", limit=1)
     except requests.RequestException as exc:
         pytest.skip(f"Cannot reach MCP server: {exc}")
+    if os.getenv("MCP_ALLOW_EXAMPLE_LOAD", "false").lower() == "true":
+        try:
+            layer.load_examples(files=FIXTURE_FILES, graph=GRAPH)
+        except Exception as exc:
+            pytest.skip(f"Cannot load garden fixtures: {exc}")
+    result = layer.traverse(KEROSENE_ROOT, CLONE_OF, direction="incoming", limit=1)
+    bindings = result.get("results", {}).get("bindings", [])
+    if not bindings:
+        pytest.skip("No garden fixture data available; set MCP_ALLOW_EXAMPLE_LOAD=true")
     return layer