From 3529b4d7a2ce380a6411b1d0317735ef2da9c2ba Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Mon, 28 Nov 2022 11:47:09 +0100 Subject: [PATCH] TST: Add more tests for string representation --- unittests/test_identifiable.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/unittests/test_identifiable.py b/unittests/test_identifiable.py index 25de8fdf..847438ca 100644 --- a/unittests/test_identifiable.py +++ b/unittests/test_identifiable.py @@ -42,7 +42,8 @@ def test_create_hashable_string(): assert a == b assert ( 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") a = Identifiable._create_hashable_string( Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12)]})) @@ -51,7 +52,8 @@ def test_create_hashable_string(): Identifiable(name="A", record_type="B", properties={'a': [12]})) == "P<B>N<A>a:[12]") assert ( 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]") assert ( Identifiable._create_hashable_string( @@ -68,6 +70,12 @@ def test_name(): def test_repr(): # only test that something meaningful is returned 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(): @@ -83,5 +91,7 @@ def test_equality(): path="a", properties={"a": 0}) == Identifiable(path="a", properties={"a": 1}) assert Identifiable( path="a", properties={"a": 0}) == Identifiable(properties={"a": 0}) - assert Identifiable(properties={"a": 0}) == Identifiable(properties={"a": 0}) - assert Identifiable(properties={"a": 0}) != Identifiable(properties={"a": 1}) + assert Identifiable(properties={"a": 0}) == Identifiable( + properties={"a": 0}) + assert Identifiable(properties={"a": 0}) != Identifiable( + properties={"a": 1}) -- GitLab