diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index 84abc315574bff881442d8ce41827a46fa693adc..cd10d971aaf3f2e57508cd48f8a26ca012449a83 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -192,7 +192,7 @@ class Parser(object): self._add_entity_to_model(name, entity) # initialize recordtypes self._set_recordtypes() - self._check_datatypes() + self._check_and_convert_datatypes() for name, entity in ymlmodel.items(): self._treat_entity(name, entity, line=ymlmodel["__line__"]) @@ -384,7 +384,7 @@ class Parser(object): raise e self.treated.append(name) - def _check_datatypes(self): + def _check_and_convert_datatypes(self): """ checks if datatype is valid. datatype of properties is simply initialized with string. Here, we iterate over properties and check whether it is a base datatype of a @@ -395,13 +395,19 @@ class Parser(object): if isinstance(value, db.Property): dtype = value.datatype + is_list = False if _get_listdatatype(value.datatype) is not None: dtype = _get_listdatatype(value.datatype) + is_list = True if dtype in self.model: + if is_list: + value.datatype = db.LIST(self.model[dtype]) + else: + value.datatype = self.model[dtype] + continue - # get the datatype if dtype in [db.DOUBLE, db.REFERENCE, @@ -411,7 +417,13 @@ class Parser(object): db.FILE, db.BOOLEAN]: + if is_list: + value.datatype = db.LIST(db.__getattribute__(dtype)) + else: + value.datatype = db.__getattribute__(dtype) + continue + raise ValueError("Unknown Datatype.") def _set_recordtypes(self): diff --git a/unittests/test_parser.py b/unittests/test_parser.py index 03b828099686c54ee008bda964a0de9898340be7..620c9792ef9e68b06ea59d112603cdace7aabc7e 100644 --- a/unittests/test_parser.py +++ b/unittests/test_parser.py @@ -200,9 +200,14 @@ RT1: recommended_properties: a: datatype: LIST(RT2) + b: + datatype: LIST(TEXT) RT2: """ - parse_model_from_yaml(to_file(string)) + model = parse_model_from_yaml(to_file(string)) + + self.assertTrue(isinstance(model['b'], db.Property)) + self.assertEqual(model['b'].datatype, db.LIST(db.TEXT)) # This failed for an older version of caosdb-models string_list = """