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

FIX: type checking was broken

parent 031cdd39
Branches
Tags
2 merge requests!57RELEASE 0.7.3,!52F refactor high level api
......@@ -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)
......
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment