From 132a994b8f2fc9a5fcff4a772ed711a31c5d6bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org> Date: Mon, 4 Oct 2021 14:40:24 +0200 Subject: [PATCH] FIX: treatment of reference properties --- integrationtests/model.yml | 3 +-- src/caosadvancedtools/models/parser.py | 5 ++--- unittests/test_parser.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/integrationtests/model.yml b/integrationtests/model.yml index ab302f08..e1753a9f 100644 --- a/integrationtests/model.yml +++ b/integrationtests/model.yml @@ -9,6 +9,7 @@ Experiment: # TODO empty recommended_properties is a problem #recommended_properties: responsible: + datatype: LIST<Person> Project: SoftwareVersion: recommended_properties: @@ -30,8 +31,6 @@ Person: email: datatype: TEXT description: 'Email of a Person.' -responsible: - datatype: REFERENCE revisionOf: datatype: REFERENCE results: diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index 1eda0907..e56a492f 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -252,9 +252,8 @@ class Parser(object): # is it a property and "datatype" in definition # but not simply an RT of the model - and not (definition["datatype"] in self.model - or _get_listdatatype( - definition["datatype"]) in self.model)): + and not (_get_listdatatype(definition["datatype"]) == name and + _get_listdatatype(definition["datatype"]) in self.model)): # and create the new property self.model[name] = db.Property(name=name, diff --git a/unittests/test_parser.py b/unittests/test_parser.py index 44b01a3a..161e2873 100644 --- a/unittests/test_parser.py +++ b/unittests/test_parser.py @@ -274,6 +274,22 @@ A: parse_model_from_string(yaml) self.assertIn("line 3", yde.exception.args[0]) + def test_reference_property(self): + """Test correct creation of reference property using an RT.""" + modeldef = """A: + recommended_properties: + ref: + datatype: LIST<A> +""" + model = parse_model_from_string(modeldef) + self.assertEqual(len(model), 2) + for key in model.keys(): + if key == "A": + self.assertTrue(isinstance(model[key], db.RecordType)) + elif key == "ref": + self.assertTrue(isinstance(model[key], db.Property)) + self.assertEqual(model[key].datatype, "LIST<A>") + class ExternTest(unittest.TestCase): """TODO Testing the "extern" keyword in the YAML.""" -- GitLab