diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index 6d028a28f5c17897adb861c171d53cfc65368b2e..84abc315574bff881442d8ce41827a46fa693adc 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -248,8 +248,10 @@ class Parser(object): and isinstance(definition, dict) # is it a property and "datatype" in definition - # but not a list - and not is_reference(db.Property(datatype=definition["datatype"]))): + # but not simply an RT of the model + and not (definition["datatype"] in self.model + or _get_listdatatype( + definition["datatype"]) in self.model)): # and create the new property self.model[name] = db.Property(name=name, @@ -384,23 +386,33 @@ class Parser(object): def _check_datatypes(self): """ checks if datatype is valid. - datatype of properties is simply initialized with string. Here over - properties is iterated and datatype is corrected. """ + datatype of properties is simply initialized with string. Here, we + iterate over properties and check whether it is a base datatype of a + name that was defined in the model (or extern part) + """ for key, value in self.model.items(): + if isinstance(value, db.Property): - if value.datatype in self.model: - value.datatype = self.model[value.datatype] - else: - # get the datatype - try: - if _get_listdatatype(value.datatype) is None: - value.datatype = db.__getattribute__(value.datatype) - else: - value.datatype = db.__getattribute__( - _get_listdatatype(value.datatype)) - except AttributeError: - raise ValueError("Unknown Datatype.") + dtype = value.datatype + + if _get_listdatatype(value.datatype) is not None: + dtype = _get_listdatatype(value.datatype) + + if dtype in self.model: + continue + # get the datatype + + if dtype in [db.DOUBLE, + db.REFERENCE, + db.TEXT, + db.DATETIME, + db.INTEGER, + db.FILE, + db.BOOLEAN]: + + continue + raise ValueError("Unknown Datatype.") def _set_recordtypes(self): """ properties are defined in first iteration; set remaining as RTs """ diff --git a/unittests/test_parser.py b/unittests/test_parser.py index 852577a471ba15e3afc163bd8e1e6fd97abd0c0a..03b828099686c54ee008bda964a0de9898340be7 100644 --- a/unittests/test_parser.py +++ b/unittests/test_parser.py @@ -190,7 +190,7 @@ p1: p2: datatype: TXT """ - self.assertRaises(ValueError, lambda: parse_model_from_yaml(to_file(string))) + self.assertRaises(ValueError, parse_model_from_yaml, to_file(string)) class ListTest(unittest.TestCase): @@ -202,7 +202,7 @@ RT1: datatype: LIST(RT2) RT2: """ - model = parse_model_from_yaml(to_file(string)) + parse_model_from_yaml(to_file(string)) # This failed for an older version of caosdb-models string_list = """ @@ -215,17 +215,7 @@ B: c: datatype: INTEGER """ - model = parse_model_from_yaml(to_file(string_list)) - - def test_dmgd_list(self): - string = """ -RT1: - recommended_properties: - a: - datatype: LIST(T2 -RT2: -""" - self.assertRaises(ValueError, lambda: parse_model_from_yaml(to_file(string))) + parse_model_from_yaml(to_file(string_list)) class ParserTest(unittest.TestCase):