diff --git a/src/caosdb/high_level_api.py b/src/caosdb/high_level_api.py index 534c01d127649d98f0362570cfc1620074dd5f82..c5289d97d8405cea31887cf403ecb28b7f8e0242 100644 --- a/src/caosdb/high_level_api.py +++ b/src/caosdb/high_level_api.py @@ -793,7 +793,7 @@ def convert_to_python_object(entity: Union[db.Container, db.Entity], return [convert_to_python_object(i, references) for i in entity] for entity_type in entity_map: - if isinstance(entity, entity_type): + if type(entity) == entity_type: # TODO: mypy fails here, the case "db.Container" is already treated above return _single_convert_to_python_object( entity_map[entity_type](), entity, references) diff --git a/unittests/test_high_level_api.py b/unittests/test_high_level_api.py index 4e036ed462d8e20b8d0cc159fa4371eae19bdd91..ae169b3c0653efcc6d1de823eef49ec25044bb32 100644 --- a/unittests/test_high_level_api.py +++ b/unittests/test_high_level_api.py @@ -28,7 +28,7 @@ import caosdb as db from caosdb.high_level_api import (convert_to_entity, convert_to_python_object) from caosdb.high_level_api import (CaosDBPythonUnresolvedParent, CaosDBPythonUnresolvedReference, - CaosDBPythonRecord) + CaosDBPythonRecord, CaosDBPythonFile) from caosdb.apiutils import compare_entities import pytest @@ -247,7 +247,7 @@ def test_conversion_to_entity(): assert equal_entities(r, rconv) - # With datatype: + # With a reference: r_ref = db.Record() r_ref.add_parent("bla") r_ref.add_property(name="a", value=42) @@ -258,5 +258,35 @@ def test_conversion_to_entity(): rconv = convert_to_entity(obj) assert (rconv.get_property("ref").value.get_property("a").value == r.get_property("ref").value.get_property("a").value) - # TODO: improve compare_entities function - raise NotImplementedError() + # TODO: add more tests here + + +def test_empty(): + r = db.Record() + obj = convert_to_python_object(r) + assert isinstance(obj, CaosDBPythonRecord) + assert len(obj.get_properties()) == 0 + assert len(obj.get_parents()) == 0 + + rconv = convert_to_entity(obj) + assert len(rconv.properties) == 0 + + +def test_files(): + # empty file: + r = db.File() + obj = convert_to_python_object(r) + print(type(obj)) + assert isinstance(obj, CaosDBPythonFile) + assert len(obj.get_properties()) == 0 + assert len(obj.get_parents()) == 0 + + rconv = convert_to_entity(obj) + assert len(rconv.properties) == 0 + + r.path = "test.dat" + r.file = "/local/path/test.dat" + obj = convert_to_python_object(r) + assert r.path == "test.dat" + assert r.file == "/local/path/test.dat" + assert isinstance(obj, CaosDBPythonFile)