Skip to content
Snippets Groups Projects
Commit 28d118f4 authored by florian's avatar florian
Browse files

MAINT: Deprecate `parent` keyword in yaml datamodel

Resolves #36
parent e6c0faac
No related branches found
No related tags found
2 merge requests!54REL: Release 0.5.0,!53MAINT: Deprecate `parent` keyword in yaml datamodel
Pipeline #27548 passed
......@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ##
### Added ###
- You can now use `python -m caosadvancedtools.models.parser model_file` to
parse and potentially synchronize data models.
......@@ -14,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated ###
- [#36](https://gitlab.com/caosdb/caosdb-advanced-user-tools/-/issues/36)
`parent` keyword in yaml datamodel definition (replaced by
`inherit_from_{obligatory|recommended|suggested}` keywords).
### Removed ###
### Fixed ###
......
......@@ -42,6 +42,7 @@ import sys
import yaml
from typing import List
from warnings import warn
import jsonschema
import caosdb as db
......@@ -519,6 +520,16 @@ class Parser(object):
self._inherit(name, prop, db.RECOMMENDED)
elif prop_name == "inherit_from_suggested":
self._inherit(name, prop, db.SUGGESTED)
elif prop_name == "parent":
warn(
DeprecationWarning(
"The `parent` keyword is deprecated and will be "
"removed in a future version. Use "
"`inherit_from_{obligatory|recommended|suggested}` "
"instead."
)
)
self._inherit(name, prop, db.OBLIGATORY)
else:
raise ValueError("invalid keyword: {}".format(prop_name))
......
......@@ -109,7 +109,7 @@ Keywords
added as parents, and all Properties with at least the importance ``XXX`` are inherited. For
example, ``inherited_from_recommended`` will inherit all Properties of importance ``recommended``
and ``obligatory``, but not ``suggested``.
- **parent**: Parent of this entity. (*Deprecated*)
- **parent**: Parent of this entity. Same as ``inherit_from_obligatory``. (*Deprecated*)
Usage
=====
......
import unittest
from datetime import date
from tempfile import NamedTemporaryFile
from pytest import raises
from pytest import deprecated_call, raises
import caosdb as db
from caosadvancedtools.models.parser import (TwiceDefinedException,
......@@ -474,3 +474,40 @@ F:
"""
with raises(NotImplementedError):
entities = parse_model_from_string(model)
def test_issue_36():
"""Test whether the `parent` keyword is deprecated.
See https://gitlab.com/caosdb/caosdb-advanced-user-tools/-/issues/36.
"""
model_string = """
R1:
obligatory_properties:
prop1:
datatype: TEXT
R2:
obligatory_properties:
prop2:
datatype: TEXT
recommended_properties:
prop3:
datatype: TEXT
R3:
parent:
- R2
inherit_from_obligatory:
- R1
"""
with deprecated_call():
# Check whether this is actually deprecated
model = parse_model_from_string(model_string)
assert "R3" in model
r3 = model["R3"]
assert isinstance(r3, db.RecordType)
for par in ["R1", "R2"]:
# Until removal, both do the same
assert has_parent(r3, par)
assert r3.get_parent(par)._flags["inheritance"] == db.OBLIGATORY
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment