From d187ec6387baea05993b22c8de99b6bdbcb1c141 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org>
Date: Fri, 15 Oct 2021 10:34:03 +0200
Subject: [PATCH] MAINT: do not directly load the model but use the
 insert_model module"

---
 integrationtests/insert_model.py              | 44 +++++++++++--------
 .../test_crawl_with_datamodel_problems.py     |  5 ++-
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/integrationtests/insert_model.py b/integrationtests/insert_model.py
index d793b041..3cff966d 100755
--- a/integrationtests/insert_model.py
+++ b/integrationtests/insert_model.py
@@ -5,22 +5,28 @@ from caosadvancedtools.cfoods.h5 import H5CFood
 from caosadvancedtools.models.data_model import DataModel
 from caosadvancedtools.models.parser import parse_model_from_yaml
 
-# for teseting existing data model parts for the YANL Interface
-db.RecordType(name="TestRT1", datatype=db.TEXT).insert()
-db.Property(name="TestP1", datatype=db.TEXT).insert()
-
-model = parse_model_from_yaml("model.yml")
-model.sync_data_model(noquestion=True)
-
-if len(db.execute_query("FIND Property alias")) == 0:
-    al = db.Property(name="alias")
-    al.add_parent(name="name")
-    al.insert()
-
-h5model = db.Container()
-h5file = h5py.File('extroot/ExperimentalData/2010_TestProject/2019-02-03/hdf5_dummy_file.hdf5', 'r')
-H5CFood.create_structure(h5file, create_recordTypes=True, collection=h5model,
-                         root_name="ExampleH5")
-print(h5model)
-h5model = DataModel(h5model)
-h5model.sync_data_model(noquestion=True)
+
+def main():
+
+    # for teseting existing data model parts for the YANL Interface
+    db.RecordType(name="TestRT1", datatype=db.TEXT).insert()
+    db.Property(name="TestP1", datatype=db.TEXT).insert()
+
+    model = parse_model_from_yaml("model.yml")
+    model.sync_data_model(noquestion=True)
+
+    if len(db.execute_query("FIND Property alias")) == 0:
+        al = db.Property(name="alias")
+        al.add_parent(name="name")
+        al.insert()
+
+    h5model = db.Container()
+    h5file = h5py.File('extroot/ExperimentalData/2010_TestProject/2019-02-03/hdf5_dummy_file.hdf5', 'r')
+    H5CFood.create_structure(h5file, create_recordTypes=True, collection=h5model,
+                             root_name="ExampleH5")
+    h5model = DataModel(h5model)
+    h5model.sync_data_model(noquestion=True)
+
+
+if __name__ == "__main__":
+    main()
diff --git a/integrationtests/test_crawl_with_datamodel_problems.py b/integrationtests/test_crawl_with_datamodel_problems.py
index 2831bb67..61fec390 100644
--- a/integrationtests/test_crawl_with_datamodel_problems.py
+++ b/integrationtests/test_crawl_with_datamodel_problems.py
@@ -34,6 +34,8 @@ from caosadvancedtools.models.parser import parse_model_from_yaml
 from caosadvancedtools.scifolder import (AnalysisCFood, ExperimentCFood,
                                          PublicationCFood, SimulationCFood)
 
+from insert_model import main as insert_model
+
 
 def setup_module():
     """Clear problems and remove all entities except for built-in ones."""
@@ -67,8 +69,7 @@ def test_crawler_with_data_model_problems():
                            prefix="", dryrun=False, forceAllowSymlinks=False)
 
     # load and damage the model
-    model = parse_model_from_yaml("model.yml")
-    model.sync_data_model(noquestion=True)
+    insert_model()
     deleted_entities = {"Experiment", "Poster", "results"}
 
     for ent in deleted_entities:
-- 
GitLab