2525
2626
2727class RunTestCase (TestCase ):
28-
2928 def test_must_use_valid_url_scheme (self ):
3029 with self .assertRaises (ValueError ):
3130 GraphDatabase .driver ("x://xxx" )
@@ -141,9 +140,65 @@ def test_can_obtain_summary_info(self):
141140 assert summary .statement_type == "rw"
142141 assert summary .statistics .nodes_created == 1
143142
143+ def test_no_plan_info (self ):
144+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
145+ result = session .run ("CREATE (n) RETURN n" )
146+ assert result .summarize ().plan is None
147+ assert result .summarize ().profile is None
148+
149+ def test_can_obtain_plan_info (self ):
150+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
151+ result = session .run ("EXPLAIN CREATE (n) RETURN n" )
152+ plan = result .summarize ().plan
153+ assert plan .operator_type == "ProduceResults"
154+ assert plan .identifiers == ["n" ]
155+ assert plan .arguments == {"planner" : "COST" , "EstimatedRows" : 1.0 , "version" : "CYPHER 3.0" ,
156+ "KeyNames" : "n" , "runtime-impl" : "INTERPRETED" , "planner-impl" : "IDP" ,
157+ "runtime" : "INTERPRETED" }
158+ assert len (plan .children ) == 1
159+
160+ def test_can_obtain_profile_info (self ):
161+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
162+ result = session .run ("PROFILE CREATE (n) RETURN n" )
163+ profile = result .summarize ().profile
164+ assert profile .db_hits == 0
165+ assert profile .rows == 1
166+ assert profile .operator_type == "ProduceResults"
167+ assert profile .identifiers == ["n" ]
168+ assert profile .arguments == {"planner" : "COST" , "EstimatedRows" : 1.0 , "version" : "CYPHER 3.0" ,
169+ "KeyNames" : "n" , "runtime-impl" : "INTERPRETED" , "planner-impl" : "IDP" ,
170+ "runtime" : "INTERPRETED" , "Rows" : 1 , "DbHits" : 0 }
171+ assert len (profile .children ) == 1
172+
173+ def test_no_notification_info (self ):
174+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
175+ result = session .run ("CREATE (n) RETURN n" )
176+ notifications = result .summarize ().notifications
177+ assert notifications == []
178+
179+ def test_can_obtain_notification_info (self ):
180+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
181+ result = session .run ("EXPLAIN MATCH (n), (m) RETURN n, m" )
182+ notifications = result .summarize ().notifications
183+
184+ assert len (notifications ) == 1
185+ notification = notifications [0 ]
186+ assert notification .code == "Neo.ClientNotification.Statement.CartesianProduct"
187+ assert notification .title == "This query builds a cartesian product between disconnected patterns."
188+ assert notification .description == \
189+ "If a part of a query contains multiple disconnected patterns, " \
190+ "this will build a cartesian product between all those parts. " \
191+ "This may produce a large amount of data and slow down query processing. " \
192+ "While occasionally intended, it may often be possible to reformulate the query " \
193+ "that avoids the use of this cross product, perhaps by adding a relationship between " \
194+ "the different parts or by using OPTIONAL MATCH (identifier is: (m))"
195+ position = notification .position
196+ assert position .offset == 0
197+ assert position .line == 1
198+ assert position .column == 1
144199
145- class TransactionTestCase (TestCase ):
146200
201+ class TransactionTestCase (TestCase ):
147202 def test_can_commit_transaction (self ):
148203 with GraphDatabase .driver ("bolt://localhost" ).session () as session :
149204 tx = session .new_transaction ()
@@ -161,7 +216,7 @@ def test_can_commit_transaction(self):
161216
162217 # Check the property value
163218 result = session .run ("MATCH (a) WHERE id(a) = {n} "
164- "RETURN a.foo" , {"n" : node_id })
219+ "RETURN a.foo" , {"n" : node_id })
165220 foo = result [0 ][0 ]
166221 assert foo == "bar"
167222
@@ -182,13 +237,12 @@ def test_can_rollback_transaction(self):
182237
183238 # Check the property value
184239 result = session .run ("MATCH (a) WHERE id(a) = {n} "
185- "RETURN a.foo" , {"n" : node_id })
240+ "RETURN a.foo" , {"n" : node_id })
186241 assert len (result ) == 0
187242
188243 def test_can_commit_transaction_using_with_block (self ):
189244 with GraphDatabase .driver ("bolt://localhost" ).session () as session :
190245 with session .new_transaction () as tx :
191-
192246 # Create a node
193247 result = tx .run ("CREATE (a) RETURN id(a)" )
194248 node_id = result [0 ][0 ]
@@ -202,14 +256,13 @@ def test_can_commit_transaction_using_with_block(self):
202256
203257 # Check the property value
204258 result = session .run ("MATCH (a) WHERE id(a) = {n} "
205- "RETURN a.foo" , {"n" : node_id })
259+ "RETURN a.foo" , {"n" : node_id })
206260 foo = result [0 ][0 ]
207261 assert foo == "bar"
208262
209263 def test_can_rollback_transaction_using_with_block (self ):
210264 with GraphDatabase .driver ("bolt://localhost" ).session () as session :
211265 with session .new_transaction () as tx :
212-
213266 # Create a node
214267 result = tx .run ("CREATE (a) RETURN id(a)" )
215268 node_id = result [0 ][0 ]
@@ -221,5 +274,5 @@ def test_can_rollback_transaction_using_with_block(self):
221274
222275 # Check the property value
223276 result = session .run ("MATCH (a) WHERE id(a) = {n} "
224- "RETURN a.foo" , {"n" : node_id })
277+ "RETURN a.foo" , {"n" : node_id })
225278 assert len (result ) == 0
0 commit comments