Skip to content

Commit 2793320

Browse files
committed
records->stream; fixed tx.success on __exit__
1 parent 8243a42 commit 2793320

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

examples/test_examples.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_result_retention(self):
131131
# tag::retain-result-process[]
132132
cursor = session.run("MATCH (person:Person) WHERE person.dept = {dept} "
133133
"RETURN id(person) AS minion", {"dept": "IT"})
134-
minion_records = list(cursor.records())
134+
minion_records = list(cursor.stream())
135135

136136
for record in minion_records:
137137
session.run("MATCH (person) WHERE id(person) = {id} "

neo4j/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def main():
6868
else:
6969
if not args.quiet:
7070
has_results = False
71-
for i, record in enumerate(cursor.records()):
71+
for i, record in enumerate(cursor.stream()):
7272
has_results = True
7373
if i == 0:
7474
stdout.write("%s\r\n" % "\t".join(record.keys()))

neo4j/v1/session.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def at_end(self):
187187
self._connection.fetch_next()
188188
return self.at_end()
189189

190-
def records(self):
190+
def stream(self):
191191
""" Yield all subsequent records.
192192
"""
193193
while self.next():
@@ -518,7 +518,8 @@ def __enter__(self):
518518
return self
519519

520520
def __exit__(self, exc_type, exc_value, traceback):
521-
self.success = False if exc_type else True
521+
if exc_value:
522+
self.success = False
522523
self.close()
523524

524525
def run(self, statement, parameters=None):

test/tck/tck_util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ def send_string(text):
1111
session = driver.session()
1212
cursor = session.run(text)
1313
session.close()
14-
return list(cursor.records())
14+
return list(cursor.stream())
1515

1616

1717
def send_parameters(statement, parameters):
1818
session = driver.session()
1919
cursor = session.run(statement, parameters)
2020
session.close()
21-
return list(cursor.records())
21+
return list(cursor.stream())
2222

2323

2424
def get_bolt_value(type, value):

test/test_session.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_sessions_are_not_reused_if_still_in_use(self):
8585
def test_can_run_simple_statement(self):
8686
session = GraphDatabase.driver("bolt://localhost").session()
8787
count = 0
88-
for record in session.run("RETURN 1 AS n").records():
88+
for record in session.run("RETURN 1 AS n").stream():
8989
assert record[0] == 1
9090
assert record["n"] == 1
9191
with self.assertRaises(KeyError):
@@ -104,7 +104,7 @@ def test_can_run_simple_statement(self):
104104
def test_can_run_simple_statement_with_params(self):
105105
session = GraphDatabase.driver("bolt://localhost").session()
106106
count = 0
107-
for record in session.run("RETURN {x} AS n", {"x": {"abc": ["d", "e", "f"]}}).records():
107+
for record in session.run("RETURN {x} AS n", {"x": {"abc": ["d", "e", "f"]}}).stream():
108108
assert record[0] == {"abc": ["d", "e", "f"]}
109109
assert record["n"] == {"abc": ["d", "e", "f"]}
110110
assert repr(record)
@@ -126,7 +126,7 @@ def test_fails_on_missing_parameter(self):
126126
def test_can_run_simple_statement_from_bytes_string(self):
127127
session = GraphDatabase.driver("bolt://localhost").session()
128128
count = 0
129-
for record in session.run(b"RETURN 1 AS n").records():
129+
for record in session.run(b"RETURN 1 AS n").stream():
130130
assert record[0] == 1
131131
assert record["n"] == 1
132132
assert repr(record)
@@ -138,22 +138,22 @@ def test_can_run_simple_statement_from_bytes_string(self):
138138
def test_can_run_statement_that_returns_multiple_records(self):
139139
session = GraphDatabase.driver("bolt://localhost").session()
140140
count = 0
141-
for record in session.run("unwind(range(1, 10)) AS z RETURN z").records():
141+
for record in session.run("unwind(range(1, 10)) AS z RETURN z").stream():
142142
assert 1 <= record[0] <= 10
143143
count += 1
144144
session.close()
145145
assert count == 10
146146

147147
def test_can_use_with_to_auto_close_session(self):
148148
with GraphDatabase.driver("bolt://localhost").session() as session:
149-
record_list = list(session.run("RETURN 1").records())
149+
record_list = list(session.run("RETURN 1").stream())
150150
assert len(record_list) == 1
151151
for record in record_list:
152152
assert record[0] == 1
153153

154154
def test_can_return_node(self):
155155
with GraphDatabase.driver("bolt://localhost").session() as session:
156-
record_list = list(session.run("MERGE (a:Person {name:'Alice'}) RETURN a").records())
156+
record_list = list(session.run("MERGE (a:Person {name:'Alice'}) RETURN a").stream())
157157
assert len(record_list) == 1
158158
for record in record_list:
159159
alice = record[0]
@@ -164,7 +164,7 @@ def test_can_return_node(self):
164164
def test_can_return_relationship(self):
165165
with GraphDatabase.driver("bolt://localhost").session() as session:
166166
reocrd_list = list(session.run("MERGE ()-[r:KNOWS {since:1999}]->() "
167-
"RETURN r").records())
167+
"RETURN r").stream())
168168
assert len(reocrd_list) == 1
169169
for record in reocrd_list:
170170
rel = record[0]
@@ -175,7 +175,7 @@ def test_can_return_relationship(self):
175175
def test_can_return_path(self):
176176
with GraphDatabase.driver("bolt://localhost").session() as session:
177177
record_list = list(session.run("MERGE p=({name:'Alice'})-[:KNOWS]->({name:'Bob'}) "
178-
"RETURN p").records())
178+
"RETURN p").stream())
179179
assert len(record_list) == 1
180180
for record in record_list:
181181
path = record[0]
@@ -403,7 +403,7 @@ def test_can_rollback_transaction(self):
403403
# Check the property value
404404
cursor = session.run("MATCH (a) WHERE id(a) = {n} "
405405
"RETURN a.foo", {"n": node_id})
406-
assert len(list(cursor.records())) == 0
406+
assert len(list(cursor.stream())) == 0
407407

408408
def test_can_commit_transaction_using_with_block(self):
409409
with GraphDatabase.driver("bolt://localhost").session() as session:
@@ -443,4 +443,4 @@ def test_can_rollback_transaction_using_with_block(self):
443443
# Check the property value
444444
cursor = session.run("MATCH (a) WHERE id(a) = {n} "
445445
"RETURN a.foo", {"n": node_id})
446-
assert len(list(cursor.records())) == 0
446+
assert len(list(cursor.stream())) == 0

0 commit comments

Comments
 (0)