Skip to content
Snippets Groups Projects
Commit d75b3948 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

ENH: add nice string representation for identifiables

parent 6cf10a47
Branches
Tags
2 merge requests!91Release 0.3,!73ENH: add representation to identifiables
Pipeline #31000 failed
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
from __future__ import annotations from __future__ import annotations
import caosdb as db import caosdb as db
from datetime import datetime from datetime import datetime
import json
from hashlib import sha256 from hashlib import sha256
from typing import Union from typing import Union
...@@ -127,3 +128,10 @@ class Identifiable(): ...@@ -127,3 +128,10 @@ class Identifiable():
return True return True
else: else:
return False return False
def __repr__(self):
pstring = json.dumps(self.properties)
return (f"{self.__class__.__name__} for RT {self.record_type}: id={self.record_id}; "
f"name={self.name}\n\tpath={self.path}\n"
f"\tproperties:\n{pstring}\n"
f"\tbackrefs:\n{self.backrefs}")
...@@ -65,6 +65,11 @@ def test_name(): ...@@ -65,6 +65,11 @@ def test_name():
Identifiable(properties={"Name": 'li'}) Identifiable(properties={"Name": 'li'})
def test_repr():
# only test that something meaningful is returned
assert 'properties' str(Identifiable(name="A", record_type="B"))
def test_equality(): def test_equality():
assert Identifiable( assert Identifiable(
record_id=12, properties={"a": 0}) == Identifiable(record_id=12, properties={"a": 1}) record_id=12, properties={"a": 0}) == Identifiable(record_id=12, properties={"a": 1})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment