Skip to content

Commit 0130dcd

Browse files
committed
Removed at_end; summary returns None if not available
1 parent 6abbbe0 commit 0130dcd

File tree

4 files changed

+14
-38
lines changed

4 files changed

+14
-38
lines changed

examples/test_examples.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ def test_transaction_commit(self):
159159
result = session.run("MATCH (p:Person {name: 'Guinevere'}) RETURN count(p)")
160160
record = next(result)
161161
assert record["count(p)"] == 1
162-
assert result.at_end
163162
session.close()
164163

165164
def test_transaction_rollback(self):
@@ -173,7 +172,6 @@ def test_transaction_rollback(self):
173172
result = session.run("MATCH (p:Person {name: 'Merlin'}) RETURN count(p)")
174173
record = next(result)
175174
assert record["count(p)"] == 0
176-
assert result.at_end
177175
session.close()
178176

179177
def test_result_summary_query_profile(self):

neo4j/v1/exceptions.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,3 @@ def __init__(self, data):
3838
for key, value in data.items():
3939
if not key.startswith("_"):
4040
setattr(self, key, value)
41-
42-
43-
class ResultError(Exception):
44-
""" Raised when the cursor encounters a problem.
45-
"""
46-
47-
pass

neo4j/v1/session.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class which can be used to obtain `Driver` instances that are used for
3434
from .compat import integer, string, urlparse
3535
from .connection import connect, Response, RUN, PULL_ALL
3636
from .constants import ENCRYPTED_DEFAULT, TRUST_DEFAULT, TRUST_SIGNED_CERTIFICATES
37-
from .exceptions import CypherError, ResultError
37+
from .exceptions import CypherError
3838
from .typesystem import hydrated
3939

4040

@@ -198,19 +198,6 @@ def close(self):
198198
self._consume()
199199
self._connection = None
200200

201-
@property
202-
def at_end(self):
203-
""" Return ``True`` if at the end of the record stream, ``False``
204-
otherwise.
205-
"""
206-
if self._record_buffer:
207-
return False
208-
elif self._consumed:
209-
return True
210-
else:
211-
self._connection.fetch()
212-
return self.at_end
213-
214201
def keys(self):
215202
""" Return the keys for the records.
216203
"""
@@ -223,15 +210,14 @@ def keys(self):
223210
def summary(self):
224211
""" Return the summary from the trailing metadata. Note that this is
225212
only available once the entire result stream has been consumed.
226-
Attempting to access the summary before then will raise an error.
213+
Accessing the summary before then will return :py:const:`None`.
227214
228-
:rtype: ResultSummary
229-
:raises ResultError: if the entire result has not yet been consumed
215+
:rtype: ResultSummary or :py:const:`None`
230216
"""
231217
if self._consumed:
232218
return self._summary
233219
else:
234-
raise ResultError("Summary not available until the entire result has been consumed")
220+
return None
235221

236222
def _consume(self):
237223
# Consume the remainder of this result, triggering all appropriate callback functions.

test/test_session.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from mock import patch
2626
from neo4j.v1.constants import TRUST_ON_FIRST_USE
27-
from neo4j.v1.exceptions import CypherError, ResultError
27+
from neo4j.v1.exceptions import CypherError
2828
from neo4j.v1.session import GraphDatabase, basic_auth, Record
2929
from neo4j.v1.typesystem import Node, Relationship, Path
3030

@@ -258,20 +258,19 @@ def test_can_obtain_summary_after_consuming_result(self):
258258
def test_cannot_obtain_summary_without_consuming_result(self):
259259
with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session:
260260
result = session.run("CREATE (n) RETURN n")
261-
with self.assertRaises(ResultError):
262-
_ = result.summary
261+
assert result.summary is None
263262

264263
def test_no_plan_info(self):
265264
with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session:
266-
cursor = session.run("CREATE (n) RETURN n")
267-
list(cursor)
268-
assert cursor.summary.plan is None
269-
assert cursor.summary.profile is None
265+
result = session.run("CREATE (n) RETURN n")
266+
list(result) # consume the result
267+
assert result.summary.plan is None
268+
assert result.summary.profile is None
270269

271270
def test_can_obtain_plan_info(self):
272271
with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session:
273272
result = session.run("EXPLAIN CREATE (n) RETURN n")
274-
list(result)
273+
list(result) # consume the result
275274
plan = result.summary.plan
276275
assert plan.operator_type == "ProduceResults"
277276
assert plan.identifiers == ["n"]
@@ -283,7 +282,7 @@ def test_can_obtain_plan_info(self):
283282
def test_can_obtain_profile_info(self):
284283
with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session:
285284
result = session.run("PROFILE CREATE (n) RETURN n")
286-
list(result)
285+
list(result) # consume the result
287286
profile = result.summary.profile
288287
assert profile.db_hits == 0
289288
assert profile.rows == 1
@@ -297,14 +296,14 @@ def test_can_obtain_profile_info(self):
297296
def test_no_notification_info(self):
298297
with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session:
299298
result = session.run("CREATE (n) RETURN n")
300-
list(result)
299+
list(result) # consume the result
301300
notifications = result.summary.notifications
302301
assert notifications == []
303302

304303
def test_can_obtain_notification_info(self):
305304
with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session:
306305
result = session.run("EXPLAIN MATCH (n), (m) RETURN n, m")
307-
list(result)
306+
list(result) # consume the result
308307
notifications = result.summary.notifications
309308

310309
assert len(notifications) == 1

0 commit comments

Comments
 (0)