2626 Node ,
2727 Path ,
2828 Graph ,
29+ Relationship ,
2930)
3031from neo4j .packstream import Structure
3132
@@ -39,13 +40,13 @@ def test_can_create_node():
3940 g = Graph ()
4041 gh = Graph .Hydrator (g )
4142 alice = gh .hydrate_node (1 , {"Person" }, {"name" : "Alice" , "age" : 33 })
43+ assert isinstance (alice , Node )
4244 assert alice .labels == {"Person" }
4345 assert set (alice .keys ()) == {"name" , "age" }
4446 assert set (alice .values ()) == {"Alice" , 33 }
4547 assert set (alice .items ()) == {("name" , "Alice" ), ("age" , 33 )}
4648 assert alice .get ("name" ) == "Alice"
4749 assert alice .get ("age" ) == 33
48- assert repr (alice ) == "<Node id=1 labels=frozenset({'Person'}) properties={'age': 33, 'name': 'Alice'}>"
4950 assert len (alice ) == 2
5051 assert alice ["name" ] == "Alice"
5152 assert alice ["age" ] == 33
@@ -58,6 +59,7 @@ def test_null_properties():
5859 g = Graph ()
5960 gh = Graph .Hydrator (g )
6061 stuff = gh .hydrate_node (1 , (), {"good" : ["puppies" , "kittens" ], "bad" : None })
62+ assert isinstance (stuff , Node )
6163 assert set (stuff .keys ()) == {"good" }
6264 assert stuff .get ("good" ) == ["puppies" , "kittens" ]
6365 assert stuff .get ("bad" ) is None
@@ -87,6 +89,13 @@ def test_node_hashing():
8789 assert hash (node_1 ) != hash (node_3 )
8890
8991
92+ def test_node_repr ():
93+ g = Graph ()
94+ gh = Graph .Hydrator (g )
95+ alice = gh .hydrate_node (1 , {"Person" }, {"name" : "Alice" })
96+ assert repr (alice ) == "<Node id=1 labels=frozenset({'Person'}) properties={'name': 'Alice'}>"
97+
98+
9099# Relationship
91100
92101
@@ -96,14 +105,23 @@ def test_can_create_relationship():
96105 alice = gh .hydrate_node (1 , {"Person" }, {"name" : "Alice" , "age" : 33 })
97106 bob = gh .hydrate_node (2 , {"Person" }, {"name" : "Bob" , "age" : 44 })
98107 alice_knows_bob = gh .hydrate_relationship (1 , alice .id , bob .id , "KNOWS" , {"since" : 1999 })
108+ assert isinstance (alice_knows_bob , Relationship )
99109 assert alice_knows_bob .start_node == alice
100110 assert alice_knows_bob .type == "KNOWS"
101111 assert alice_knows_bob .end_node == bob
102112 assert set (alice_knows_bob .keys ()) == {"since" }
103113 assert set (alice_knows_bob .values ()) == {1999 }
104114 assert set (alice_knows_bob .items ()) == {("since" , 1999 )}
105115 assert alice_knows_bob .get ("since" ) == 1999
106- assert repr (alice_knows_bob ) == "<Relationship id=1 nodes=(<Node id=1 labels=frozenset({'Person'}) properties={'age': 33, 'name': 'Alice'}>, <Node id=2 labels=frozenset({'Person'}) properties={'age': 44, 'name': 'Bob'}>) type='KNOWS' properties={'since': 1999}>"
116+
117+
118+ def test_relationship_repr ():
119+ g = Graph ()
120+ gh = Graph .Hydrator (g )
121+ alice = gh .hydrate_node (1 , {"Person" }, {"name" : "Alice" })
122+ bob = gh .hydrate_node (2 , {"Person" }, {"name" : "Bob" })
123+ alice_knows_bob = gh .hydrate_relationship (1 , alice .id , bob .id , "KNOWS" , {"since" : 1999 })
124+ assert repr (alice_knows_bob ) == "<Relationship id=1 nodes=(<Node id=1 labels=frozenset({'Person'}) properties={'name': 'Alice'}>, <Node id=2 labels=frozenset({'Person'}) properties={'name': 'Bob'}>) type='KNOWS' properties={'since': 1999}>"
107125
108126
109127# Path
@@ -118,12 +136,12 @@ def test_can_create_path():
118136 alice_knows_bob = gh .hydrate_relationship (1 , alice .id , bob .id , "KNOWS" , {"since" : 1999 })
119137 carol_dislikes_bob = gh .hydrate_relationship (2 , carol .id , bob .id , "DISLIKES" , {})
120138 path = Path (alice , alice_knows_bob , carol_dislikes_bob )
139+ assert isinstance (path , Path )
121140 assert path .start_node == alice
122141 assert path .end_node == carol
123142 assert path .nodes == (alice , bob , carol )
124143 assert path .relationships == (alice_knows_bob , carol_dislikes_bob )
125144 assert list (path ) == [alice_knows_bob , carol_dislikes_bob ]
126- assert repr (path ) == "<Path start=<Node id=1 labels=frozenset({'Person'}) properties={'age': 33, 'name': 'Alice'}> end=<Node id=3 labels=frozenset({'Person'}) properties={'age': 55, 'name': 'Carol'}> size=2>"
127145
128146
129147def test_can_hydrate_path ():
@@ -142,7 +160,6 @@ def test_can_hydrate_path():
142160 expected_carol_dislikes_bob = gh .hydrate_relationship (2 , carol .id , bob .id , "DISLIKES" , {})
143161 assert path .relationships == (expected_alice_knows_bob , expected_carol_dislikes_bob )
144162 assert list (path ) == [expected_alice_knows_bob , expected_carol_dislikes_bob ]
145- assert repr (path ) == "<Path start=<Node id=1 labels=frozenset({'Person'}) properties={'age': 33, 'name': 'Alice'}> end=<Node id=3 labels=frozenset({'Person'}) properties={'age': 55, 'name': 'Carol'}> size=2>"
146163
147164
148165def test_path_equality ():
@@ -170,3 +187,15 @@ def test_path_hashing():
170187 path_1 = Path (alice , alice_knows_bob , carol_dislikes_bob )
171188 path_2 = Path (alice , alice_knows_bob , carol_dislikes_bob )
172189 assert hash (path_1 ) == hash (path_2 )
190+
191+
192+ def test_path_repr ():
193+ g = Graph ()
194+ gh = Graph .Hydrator (g )
195+ alice = gh .hydrate_node (1 , {"Person" }, {"name" : "Alice" })
196+ bob = gh .hydrate_node (2 , {"Person" }, {"name" : "Bob" })
197+ carol = gh .hydrate_node (3 , {"Person" }, {"name" : "Carol" })
198+ alice_knows_bob = gh .hydrate_relationship (1 , alice .id , bob .id , "KNOWS" , {"since" : 1999 })
199+ carol_dislikes_bob = gh .hydrate_relationship (2 , carol .id , bob .id , "DISLIKES" , {})
200+ path = Path (alice , alice_knows_bob , carol_dislikes_bob )
201+ assert repr (path ) == "<Path start=<Node id=1 labels=frozenset({'Person'}) properties={'name': 'Alice'}> end=<Node id=3 labels=frozenset({'Person'}) properties={'name': 'Carol'}> size=2>"
0 commit comments