26
26
Node ,
27
27
Path ,
28
28
Graph ,
29
+ Relationship ,
29
30
)
30
31
from neo4j .packstream import Structure
31
32
@@ -39,13 +40,13 @@ def test_can_create_node():
39
40
g = Graph ()
40
41
gh = Graph .Hydrator (g )
41
42
alice = gh .hydrate_node (1 , {"Person" }, {"name" : "Alice" , "age" : 33 })
43
+ assert isinstance (alice , Node )
42
44
assert alice .labels == {"Person" }
43
45
assert set (alice .keys ()) == {"name" , "age" }
44
46
assert set (alice .values ()) == {"Alice" , 33 }
45
47
assert set (alice .items ()) == {("name" , "Alice" ), ("age" , 33 )}
46
48
assert alice .get ("name" ) == "Alice"
47
49
assert alice .get ("age" ) == 33
48
- assert repr (alice ) == "<Node id=1 labels=frozenset({'Person'}) properties={'age': 33, 'name': 'Alice'}>"
49
50
assert len (alice ) == 2
50
51
assert alice ["name" ] == "Alice"
51
52
assert alice ["age" ] == 33
@@ -58,6 +59,7 @@ def test_null_properties():
58
59
g = Graph ()
59
60
gh = Graph .Hydrator (g )
60
61
stuff = gh .hydrate_node (1 , (), {"good" : ["puppies" , "kittens" ], "bad" : None })
62
+ assert isinstance (stuff , Node )
61
63
assert set (stuff .keys ()) == {"good" }
62
64
assert stuff .get ("good" ) == ["puppies" , "kittens" ]
63
65
assert stuff .get ("bad" ) is None
@@ -87,6 +89,13 @@ def test_node_hashing():
87
89
assert hash (node_1 ) != hash (node_3 )
88
90
89
91
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
+
90
99
# Relationship
91
100
92
101
@@ -96,14 +105,23 @@ def test_can_create_relationship():
96
105
alice = gh .hydrate_node (1 , {"Person" }, {"name" : "Alice" , "age" : 33 })
97
106
bob = gh .hydrate_node (2 , {"Person" }, {"name" : "Bob" , "age" : 44 })
98
107
alice_knows_bob = gh .hydrate_relationship (1 , alice .id , bob .id , "KNOWS" , {"since" : 1999 })
108
+ assert isinstance (alice_knows_bob , Relationship )
99
109
assert alice_knows_bob .start_node == alice
100
110
assert alice_knows_bob .type == "KNOWS"
101
111
assert alice_knows_bob .end_node == bob
102
112
assert set (alice_knows_bob .keys ()) == {"since" }
103
113
assert set (alice_knows_bob .values ()) == {1999 }
104
114
assert set (alice_knows_bob .items ()) == {("since" , 1999 )}
105
115
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}>"
107
125
108
126
109
127
# Path
@@ -118,12 +136,12 @@ def test_can_create_path():
118
136
alice_knows_bob = gh .hydrate_relationship (1 , alice .id , bob .id , "KNOWS" , {"since" : 1999 })
119
137
carol_dislikes_bob = gh .hydrate_relationship (2 , carol .id , bob .id , "DISLIKES" , {})
120
138
path = Path (alice , alice_knows_bob , carol_dislikes_bob )
139
+ assert isinstance (path , Path )
121
140
assert path .start_node == alice
122
141
assert path .end_node == carol
123
142
assert path .nodes == (alice , bob , carol )
124
143
assert path .relationships == (alice_knows_bob , carol_dislikes_bob )
125
144
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>"
127
145
128
146
129
147
def test_can_hydrate_path ():
@@ -142,7 +160,6 @@ def test_can_hydrate_path():
142
160
expected_carol_dislikes_bob = gh .hydrate_relationship (2 , carol .id , bob .id , "DISLIKES" , {})
143
161
assert path .relationships == (expected_alice_knows_bob , expected_carol_dislikes_bob )
144
162
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>"
146
163
147
164
148
165
def test_path_equality ():
@@ -170,3 +187,15 @@ def test_path_hashing():
170
187
path_1 = Path (alice , alice_knows_bob , carol_dislikes_bob )
171
188
path_2 = Path (alice , alice_knows_bob , carol_dislikes_bob )
172
189
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