Skip to content
Snippets Groups Projects
Commit 5469ff58 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

TST: added tests for runtime errors

parent 24a9f86e
No related branches found
No related tags found
2 merge requests!57RELEASE 0.7.3,!52F refactor high level api
Pipeline #20047 canceled
......@@ -78,6 +78,20 @@ def standard_type_for_high_level_type(high_level_record: "CaosDBPythonEntity",
raise RuntimeError("Incompatible type.")
def high_level_type_for_role(role: str):
if role == "Record":
return CaosDBPythonRecord
if role == "File":
return CaosDBPythonFile
if role == "Property":
return CaosDBPythonProperty
if role == "RecordType":
return CaosDBPythonRecordType
if role == "Entity":
return CaosDBPythonEntity
raise RuntimeError("Unknown role.")
def high_level_type_for_standard_type(standard_record: db.Entity):
if type(standard_record) == db.Record:
return CaosDBPythonRecord
......@@ -586,8 +600,13 @@ class CaosDBPythonEntity(object):
return [p for p in self.__dict__
if p not in self._forbidden]
def deserialize(self, serialization: dict):
raise NotImplementedError()
@staticmethod
def deserialize(serialization: dict):
"""
Deserialize a yaml representation of an entity in high level API form.
"""
pass
def serialize(self, without_metadata: bool = False):
"""
......@@ -605,7 +624,7 @@ class CaosDBPythonEntity(object):
fulldict = dict()
# Add CaosDB role:
fulldict["role"] = standard_type_for_high_level_type(self, True)
for parent in self._parents:
if isinstance(parent, CaosDBPythonEntity):
......
......@@ -32,6 +32,7 @@ from caosdb.high_level_api import (CaosDBPythonUnresolvedParent,
CaosDBPythonRecord, CaosDBPythonFile,
high_level_type_for_standard_type,
standard_type_for_high_level_type,
high_level_type_for_role,
CaosDBPythonEntity)
from caosdb.apiutils import compare_entities
......@@ -522,3 +523,14 @@ def test_type_conversion():
assert standard_type_for_high_level_type(CaosDBPythonEntity()) == db.Entity
assert standard_type_for_high_level_type(CaosDBPythonFile(), True) == "File"
assert standard_type_for_high_level_type(CaosDBPythonRecord(), True) == "Record"
assert high_level_type_for_role("Record") == CaosDBPythonRecord
assert high_level_type_for_role("Entity") == CaosDBPythonEntity
assert high_level_type_for_role("File") == CaosDBPythonFile
with pytest.raises(RuntimeError, match="Unknown role."):
high_level_type_for_role("jkaldjfkaldsjf")
with pytest.raises(RuntimeError, match="Incompatible type."):
standard_type_for_high_level_type(42, True)
with pytest.raises(RuntimeError, match="Incompatible type."):
high_level_type_for_standard_type("ajsdkfjasfkj")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment