@@ -53,8 +53,8 @@ def test_minimal_working_example(self):
5353 session .run ("CREATE (a:Person {name:'Arthur', title:'King'})" , )
5454
5555 result = session .run ("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" )
56- while result . next () :
57- print ("%s %s" % (result ["title" ], result ["name" ]))
56+ for record in result :
57+ print ("%s %s" % (record ["title" ], record ["name" ]))
5858
5959 session .close ()
6060 # end::minimal-example[]
@@ -116,8 +116,8 @@ def test_result_cursor(self):
116116 result = session .run ("MATCH (tool:Tool) WHERE tool.name CONTAINS {term} "
117117 "RETURN tool.name" , {"term" : search_term })
118118 print ("List of tools called %r:" % search_term )
119- while result . next () :
120- print (result ["tool.name" ])
119+ for record in result :
120+ print (record ["tool.name" ])
121121 # end::result-cursor[]
122122 session .close ()
123123
@@ -127,10 +127,10 @@ def test_cursor_nesting(self):
127127 # tag::retain-result-query[]
128128 result = session .run ("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} "
129129 "RETURN id(knight) AS knight_id" , {"castle" : "Camelot" })
130- while result . next () :
130+ for record in result :
131131 session .run ("MATCH (knight) WHERE id(knight) = {id} "
132132 "MATCH (king:Person) WHERE king.name = {king} "
133- "CREATE (knight)-[:DEFENDS]->(king)" , {"id" : result ["knight_id" ], "king" : "Arthur" })
133+ "CREATE (knight)-[:DEFENDS]->(king)" , {"id" : record ["knight_id" ], "king" : "Arthur" })
134134 # end::retain-result-query[]
135135 session .close ()
136136
@@ -140,9 +140,8 @@ def test_result_retention(self):
140140 # tag::retain-result-process[]
141141 result = session .run ("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} "
142142 "RETURN id(knight) AS knight_id" , {"castle" : "Camelot" })
143- id_records = list (result .stream ())
144-
145- for record in id_records :
143+ retained_result = list (result )
144+ for record in retained_result :
146145 session .run ("MATCH (knight) WHERE id(knight) = {id} "
147146 "MATCH (king:Person) WHERE king.name = {king} "
148147 "CREATE (knight)-[:DEFENDS]->(king)" , {"id" : record ["knight_id" ], "king" : "Arthur" })
@@ -158,7 +157,7 @@ def test_transaction_commit(self):
158157 tx .commit ()
159158 # end::transaction-commit[]
160159 result = session .run ("MATCH (p:Person {name: 'Guinevere'}) RETURN count(p)" )
161- assert result . next ()
160+ next (result )
162161 assert result ["count(p)" ] == 1
163162 assert result .at_end
164163 session .close ()
@@ -172,7 +171,7 @@ def test_transaction_rollback(self):
172171 tx .rollback ()
173172 # end::transaction-rollback[]
174173 result = session .run ("MATCH (p:Person {name: 'Merlin'}) RETURN count(p)" )
175- assert result . next ()
174+ next (result )
176175 assert result ["count(p)" ] == 0
177176 assert result .at_end
178177 session .close ()
@@ -183,8 +182,7 @@ def test_result_summary_query_profile(self):
183182 # tag::result-summary-query-profile[]
184183 result = session .run ("PROFILE MATCH (p:Person {name: {name}}) "
185184 "RETURN id(p)" , {"name" : "Arthur" })
186- while result .next ():
187- pass # skip the records to get to the summary
185+ list (result ) # skip the records to get to the summary
188186 print (result .summary .statement_type )
189187 print (result .summary .profile )
190188 # end::result-summary-query-profile[]
@@ -195,8 +193,7 @@ def test_result_summary_notifications(self):
195193 session = driver .session ()
196194 # tag::result-summary-notifications[]
197195 result = session .run ("EXPLAIN MATCH (king), (queen) RETURN king, queen" )
198- while result .next ():
199- pass # skip the records to get to the summary
196+ list (result ) # skip the records to get to the summary
200197 for notification in result .summary .notifications :
201198 print (notification )
202199 # end::result-summary-notifications[]
0 commit comments