Skip to content
Snippets Groups Projects
Commit 3529b4d7 authored by florian's avatar florian
Browse files

TST: Add more tests for string representation

parent 12d01e2f
No related branches found
No related tags found
2 merge requests!91Release 0.3,!73ENH: add representation to identifiables
Pipeline #31140 passed
...@@ -42,7 +42,8 @@ def test_create_hashable_string(): ...@@ -42,7 +42,8 @@ def test_create_hashable_string():
assert a == b assert a == b
assert ( assert (
Identifiable._create_hashable_string( Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B", properties={'a': db.Record(id=12)}) Identifiable(name="A", record_type="B",
properties={'a': db.Record(id=12)})
) == "P<B>N<A>a:12") ) == "P<B>N<A>a:12")
a = Identifiable._create_hashable_string( a = Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12)]})) Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12)]}))
...@@ -51,7 +52,8 @@ def test_create_hashable_string(): ...@@ -51,7 +52,8 @@ def test_create_hashable_string():
Identifiable(name="A", record_type="B", properties={'a': [12]})) == "P<B>N<A>a:[12]") Identifiable(name="A", record_type="B", properties={'a': [12]})) == "P<B>N<A>a:[12]")
assert ( assert (
Identifiable._create_hashable_string( Identifiable._create_hashable_string(
Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12), 11]}) Identifiable(name="A", record_type="B", properties={
'a': [db.Record(id=12), 11]})
) == "P<B>N<A>a:[12, 11]") ) == "P<B>N<A>a:[12, 11]")
assert ( assert (
Identifiable._create_hashable_string( Identifiable._create_hashable_string(
...@@ -68,6 +70,12 @@ def test_name(): ...@@ -68,6 +70,12 @@ def test_name():
def test_repr(): def test_repr():
# only test that something meaningful is returned # only test that something meaningful is returned
assert 'properties' in str(Identifiable(name="A", record_type="B")) assert 'properties' in str(Identifiable(name="A", record_type="B"))
assert str(Identifiable(name="A", record_type="B", properties={'a': 0})).split(
"properties:\n")[1].split('\n')[0] == '{"a": 0}'
assert str(Identifiable(name="A", record_type="B", properties={'a': 0, 'b': "test"})).split(
"properties:\n")[1].split('\n')[0] == '{"a": 0, "b": "test"}'
# TODO(henrik): Add a test using backrefs once that's implemented.
def test_equality(): def test_equality():
...@@ -83,5 +91,7 @@ def test_equality(): ...@@ -83,5 +91,7 @@ def test_equality():
path="a", properties={"a": 0}) == Identifiable(path="a", properties={"a": 1}) path="a", properties={"a": 0}) == Identifiable(path="a", properties={"a": 1})
assert Identifiable( assert Identifiable(
path="a", properties={"a": 0}) == Identifiable(properties={"a": 0}) path="a", properties={"a": 0}) == Identifiable(properties={"a": 0})
assert Identifiable(properties={"a": 0}) == Identifiable(properties={"a": 0}) assert Identifiable(properties={"a": 0}) == Identifiable(
assert Identifiable(properties={"a": 0}) != Identifiable(properties={"a": 1}) properties={"a": 0})
assert Identifiable(properties={"a": 0}) != Identifiable(
properties={"a": 1})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment