From 9c87f9ab030135ffaa21c2cc306bc5bf02f0d4d2 Mon Sep 17 00:00:00 2001
From: Alexander Schlemmer <alexander@mail-schlemmer.de>
Date: Mon, 26 Sep 2022 10:41:52 +0200
Subject: [PATCH] TST: added failing test for issue 35

---
 .../substitutions_parents.yml                 | 25 +++++++++++++++++++
 unittests/test_variable_substitutions.py      | 13 ++++++++++
 2 files changed, 38 insertions(+)
 create mode 100644 unittests/test_directories/example_substitutions/substitutions_parents.yml

diff --git a/unittests/test_directories/example_substitutions/substitutions_parents.yml b/unittests/test_directories/example_substitutions/substitutions_parents.yml
new file mode 100644
index 00000000..107e766c
--- /dev/null
+++ b/unittests/test_directories/example_substitutions/substitutions_parents.yml
@@ -0,0 +1,25 @@
+
+ExperimentalData:  # name of the converter
+  type: Directory
+  match: ExperimentalData
+  records:
+    Project:
+      name: project
+  subtree:
+    File:  # name of the converter
+      type: SimpleFile
+      match: (?P<year>[0-9]{2,2})(?P<month>[0-9]{2,2})(?P<day>[0-9]{2,2})_data.dat
+      records:
+        Experiment:
+          parents:
+          - Experiment
+          - Month_$month  # This adds a special parent as record type
+          date: 20$year-$month-$day
+
+        ExperimentSeries:
+          Experiment: $Experiment
+
+        Project:
+          Experiments: +$Experiment
+          dates: +20$year-$month-$day
+      
diff --git a/unittests/test_variable_substitutions.py b/unittests/test_variable_substitutions.py
index 071bf464..565b71ad 100644
--- a/unittests/test_variable_substitutions.py
+++ b/unittests/test_variable_substitutions.py
@@ -39,6 +39,14 @@ def crawler():
                             rfp("test_directories", "example_substitutions", "substitutions.yml"))
     return crawler
 
+@pytest.fixture
+def crawler_2():
+    crawler = Crawler(debug=True)
+    crawler.crawl_directory(rfp("test_directories", "example_substitutions", "ExperimentalData"),
+                            rfp("test_directories", "example_substitutions",
+                                "substitutions_parents.yml"))
+    return crawler
+
 
 def test_substitutions(crawler):
     # @review Florian Spreckelsen 2022-05-13
@@ -59,3 +67,8 @@ def test_substitutions(crawler):
         assert isinstance(subd[i]["Project"].get_property("dates").value, list)
         assert subd[i]["Project"].get_property(
             "dates").value[0] == "2022-05-12"
+
+def test_substitutions_parents(crawler_2):
+    # This is a test for:
+    # https://gitlab.indiscale.com/caosdb/src/caosdb-crawler/-/issues/35
+    # ... testing whether variable substitutions can be used in parent declarations.
-- 
GitLab