2525
2626
2727class RunTestCase (TestCase ):
28-
2928 def test_must_use_valid_url_scheme (self ):
3029 try :
3130 GraphDatabase .driver ("x://xxx" )
@@ -169,9 +168,38 @@ def test_can_obtain_summary_info(self):
169168 assert summary .statement_type == "rw"
170169 assert summary .statistics .nodes_created == 1
171170
171+ def test_no_plan_info (self ):
172+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
173+ result = session .run ("CREATE (n) RETURN n" )
174+ assert result .summarize ().plan is None
175+ assert result .summarize ().profile is None
176+
177+ def test_can_obtain_plan_info (self ):
178+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
179+ result = session .run ("EXPLAIN CREATE (n) RETURN n" )
180+ plan = result .summarize ().plan
181+ assert plan .operator_type == "ProduceResults"
182+ assert plan .identifiers == ["n" ]
183+ assert plan .arguments == {"planner" : "COST" , "EstimatedRows" : 1.0 , "version" : "CYPHER 3.0" ,
184+ "KeyNames" : "n" , "runtime-impl" : "INTERPRETED" , "planner-impl" : "IDP" ,
185+ "runtime" : "INTERPRETED" }
186+ assert len (plan .children ) == 1
187+
188+ def test_can_obtain_profile_info (self ):
189+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
190+ result = session .run ("PROFILE CREATE (n) RETURN n" )
191+ profile = result .summarize ().profile
192+ assert profile .db_hits == 0
193+ assert profile .rows == 1
194+ assert profile .operator_type == "ProduceResults"
195+ assert profile .identifiers == ["n" ]
196+ assert profile .arguments == {"planner" : "COST" , "EstimatedRows" : 1.0 , "version" : "CYPHER 3.0" ,
197+ "KeyNames" : "n" , "runtime-impl" : "INTERPRETED" , "planner-impl" : "IDP" ,
198+ "runtime" : "INTERPRETED" , "Rows" : 1 , "DbHits" : 0 }
199+ assert len (profile .children ) == 1
172200
173- class TransactionTestCase (TestCase ):
174201
202+ class TransactionTestCase (TestCase ):
175203 def test_can_commit_transaction (self ):
176204 with GraphDatabase .driver ("bolt://localhost" ).session () as session :
177205 tx = session .new_transaction ()
@@ -189,7 +217,7 @@ def test_can_commit_transaction(self):
189217
190218 # Check the property value
191219 result = session .run ("MATCH (a) WHERE id(a) = {n} "
192- "RETURN a.foo" , {"n" : node_id })
220+ "RETURN a.foo" , {"n" : node_id })
193221 foo = result [0 ][0 ]
194222 assert foo == "bar"
195223
@@ -210,13 +238,12 @@ def test_can_rollback_transaction(self):
210238
211239 # Check the property value
212240 result = session .run ("MATCH (a) WHERE id(a) = {n} "
213- "RETURN a.foo" , {"n" : node_id })
241+ "RETURN a.foo" , {"n" : node_id })
214242 assert len (result ) == 0
215243
216244 def test_can_commit_transaction_using_with_block (self ):
217245 with GraphDatabase .driver ("bolt://localhost" ).session () as session :
218246 with session .new_transaction () as tx :
219-
220247 # Create a node
221248 result = tx .run ("CREATE (a) RETURN id(a)" )
222249 node_id = result [0 ][0 ]
@@ -230,14 +257,13 @@ def test_can_commit_transaction_using_with_block(self):
230257
231258 # Check the property value
232259 result = session .run ("MATCH (a) WHERE id(a) = {n} "
233- "RETURN a.foo" , {"n" : node_id })
260+ "RETURN a.foo" , {"n" : node_id })
234261 foo = result [0 ][0 ]
235262 assert foo == "bar"
236263
237264 def test_can_rollback_transaction_using_with_block (self ):
238265 with GraphDatabase .driver ("bolt://localhost" ).session () as session :
239266 with session .new_transaction () as tx :
240-
241267 # Create a node
242268 result = tx .run ("CREATE (a) RETURN id(a)" )
243269 node_id = result [0 ][0 ]
@@ -249,7 +275,7 @@ def test_can_rollback_transaction_using_with_block(self):
249275
250276 # Check the property value
251277 result = session .run ("MATCH (a) WHERE id(a) = {n} "
252- "RETURN a.foo" , {"n" : node_id })
278+ "RETURN a.foo" , {"n" : node_id })
253279 assert len (result ) == 0
254280
255281
0 commit comments