Skip to content

Commit b06c702

Browse files
committed
Merge branch '1.0' into 1.0-tck-tests
2 parents 0da2579 + f1350ad commit b06c702

14 files changed

+249
-174
lines changed

examples/test_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_transaction_commit(self):
158158
tx.commit()
159159
# end::transaction-commit[]
160160
result = session.run("MATCH (p:Person {name: 'Guinevere'}) RETURN count(p)")
161-
record = next(result)
161+
record = next(iter(result))
162162
assert record["count(p)"] == 1
163163
session.close()
164164

@@ -171,7 +171,7 @@ def test_transaction_rollback(self):
171171
tx.rollback()
172172
# end::transaction-rollback[]
173173
result = session.run("MATCH (p:Person {name: 'Merlin'}) RETURN count(p)")
174-
record = next(result)
174+
record = next(iter(result))
175175
assert record["count(p)"] == 0
176176
session.close()
177177

neo4j/.DS_Store

6 KB
Binary file not shown.

neo4j/v1/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def __init__(self, sock, **config):
215215
# Determine auth details
216216
try:
217217
self.auth_dict = vars(config["auth"])
218-
except KeyError:
218+
except (KeyError, TypeError):
219219
self.auth_dict = {}
220220

221221
# Pick up the server certificate, if any

neo4j/v1/session.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,14 @@ def on_failure(metadata):
206206
pull_all_response.on_failure = on_failure
207207

208208
def __iter__(self):
209-
return self
210-
211-
def __next__(self):
212-
if self._buffer:
209+
while self._buffer:
213210
values = self._buffer.popleft()
214-
return Record(self.keys(), tuple(map(hydrated, values)))
215-
elif self._consumed:
216-
raise StopIteration()
217-
else:
218-
fetch = self.connection.fetch
219-
while not self._buffer and not self._consumed:
220-
fetch()
221-
return self.__next__()
211+
yield Record(self.keys(), tuple(map(hydrated, values)))
212+
while not self._consumed:
213+
self.connection.fetch()
214+
while self._buffer:
215+
values = self._buffer.popleft()
216+
yield Record(self.keys(), tuple(map(hydrated, values)))
222217

223218
def keys(self):
224219
""" Return the keys for the records.
@@ -228,14 +223,18 @@ def keys(self):
228223
self.connection.fetch()
229224
return self._keys
230225

226+
def buffer(self):
227+
if self.connection and not self.connection.closed:
228+
while not self._consumed:
229+
self.connection.fetch()
230+
self.connection = None
231+
231232
def consume(self):
232233
""" Consume the remainder of this result and return the
233234
summary.
234235
"""
235236
if self.connection and not self.connection.closed:
236-
fetch = self.connection.fetch
237-
while not self._consumed:
238-
fetch()
237+
list(self)
239238
self.connection = None
240239
return self._summary
241240

@@ -334,11 +333,11 @@ def __repr__(self):
334333

335334
@property
336335
def contains_updates(self):
337-
return self.nodes_created or self.nodes_deleted or \
336+
return bool(self.nodes_created or self.nodes_deleted or \
338337
self.relationships_created or self.relationships_deleted or \
339338
self.properties_set or self.labels_added or self.labels_removed or \
340339
self.indexes_added or self.indexes_removed or \
341-
self.constraints_added or self.constraints_removed
340+
self.constraints_added or self.constraints_removed)
342341

343342

344343
#: A plan describes how the database will execute your statement.
@@ -419,13 +418,6 @@ def __init__(self, driver):
419418
self.transaction = None
420419
self.last_result = None
421420

422-
def __del__(self):
423-
try:
424-
if not self.connection.closed:
425-
self.connection.close()
426-
except AttributeError:
427-
pass
428-
429421
def __enter__(self):
430422
return self
431423

@@ -480,7 +472,7 @@ def close(self):
480472
""" Recycle this session through the driver it came from.
481473
"""
482474
if self.last_result:
483-
self.last_result.consume()
475+
self.last_result.buffer()
484476
self.driver.recycle(self)
485477

486478
def begin_transaction(self):

neo4j/v1/types.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
of these classes.
2626
"""
2727

28-
2928
from .packstream import Structure
3029

3130

3231
class Entity(object):
3332
""" Base class for Node and Relationship.
3433
"""
35-
identity = None
34+
id = None
3635
properties = None
3736

3837
def __init__(self, properties=None, **kwproperties):
@@ -41,15 +40,15 @@ def __init__(self, properties=None, **kwproperties):
4140

4241
def __eq__(self, other):
4342
try:
44-
return self.identity == other.identity
43+
return self.id == other.id
4544
except AttributeError:
4645
return False
4746

4847
def __ne__(self, other):
4948
return not self.__eq__(other)
5049

5150
def __hash__(self):
52-
return hash(self.identity)
51+
return hash(self.id)
5352

5453
def __len__(self):
5554
return len(self.properties)
@@ -82,18 +81,18 @@ class Node(Entity):
8281
labels = None
8382

8483
@classmethod
85-
def hydrate(cls, identity, labels, properties=None):
84+
def hydrate(cls, id_, labels, properties=None):
8685
inst = cls(labels, properties)
87-
inst.identity = identity
86+
inst.id = id_
8887
return inst
8988

9089
def __init__(self, labels=None, properties=None, **kwproperties):
9190
super(Node, self).__init__(properties, **kwproperties)
9291
self.labels = set(labels or set())
9392

9493
def __repr__(self):
95-
return "<Node identity=%r labels=%r properties=%r>" % \
96-
(self.identity, self.labels, self.properties)
94+
return "<Node id=%r labels=%r properties=%r>" % \
95+
(self.id, self.labels, self.properties)
9796

9897

9998
class BaseRelationship(Entity):
@@ -113,9 +112,9 @@ class Relationship(BaseRelationship):
113112
end = None
114113

115114
@classmethod
116-
def hydrate(cls, identity, start, end, type, properties=None):
115+
def hydrate(cls, id_, start, end, type, properties=None):
117116
inst = cls(start, end, type, properties)
118-
inst.identity = identity
117+
inst.id = id_
119118
return inst
120119

121120
def __init__(self, start, end, type, properties=None, **kwproperties):
@@ -126,12 +125,12 @@ def __init__(self, start, end, type, properties=None, **kwproperties):
126125
self.end = end
127126

128127
def __repr__(self):
129-
return "<Relationship identity=%r start=%r end=%r type=%r properties=%r>" % \
130-
(self.identity, self.start, self.end, self.type, self.properties)
128+
return "<Relationship id=%r start=%r end=%r type=%r properties=%r>" % \
129+
(self.id, self.start, self.end, self.type, self.properties)
131130

132131
def unbind(self):
133132
inst = UnboundRelationship(self.type, self.properties)
134-
inst.identity = self.identity
133+
inst.id = self.id
135134
return inst
136135

137136

@@ -140,21 +139,21 @@ class UnboundRelationship(BaseRelationship):
140139
"""
141140

142141
@classmethod
143-
def hydrate(cls, identity, type, properties=None):
142+
def hydrate(cls, id_, type, properties=None):
144143
inst = cls(type, properties)
145-
inst.identity = identity
144+
inst.id = id_
146145
return inst
147146

148147
def __init__(self, type, properties=None, **kwproperties):
149148
super(UnboundRelationship, self).__init__(type, properties, **kwproperties)
150149

151150
def __repr__(self):
152-
return "<UnboundRelationship identity=%r type=%r properties=%r>" % \
153-
(self.identity, self.type, self.properties)
151+
return "<UnboundRelationship id=%r type=%r properties=%r>" % \
152+
(self.id, self.type, self.properties)
154153

155154
def bind(self, start, end):
156155
inst = Relationship(start, end, self.type, self.properties)
157-
inst.identity = self.identity
156+
inst.id = self.id
158157
return inst
159158

160159

@@ -174,9 +173,9 @@ def hydrate(cls, nodes, rels, sequence):
174173
assert rel_index != 0
175174
next_node = nodes[sequence[2 * i + 1]]
176175
if rel_index > 0:
177-
entities.append(rels[rel_index - 1].bind(last_node.identity, next_node.identity))
176+
entities.append(rels[rel_index - 1].bind(last_node.id, next_node.id))
178177
else:
179-
entities.append(rels[-rel_index - 1].bind(next_node.identity, last_node.identity))
178+
entities.append(rels[-rel_index - 1].bind(next_node.id, last_node.id))
180179
entities.append(next_node)
181180
last_node = next_node
182181
return cls(*entities)
@@ -187,7 +186,7 @@ def __init__(self, start_node, *rels_and_nodes):
187186

188187
def __repr__(self):
189188
return "<Path start=%r end=%r size=%s>" % \
190-
(self.start.identity, self.end.identity, len(self))
189+
(self.start.id, self.end.id, len(self))
191190

192191
def __eq__(self, other):
193192
try:

test/tck/environment.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
failing_features = {}
2424

2525

26-
def before_all(context):
27-
context.config.setup_logging()
26+
# def before_all(context):
27+
# context.config.setup_logging()
2828

2929

3030
def before_feature(context, feature):
@@ -34,8 +34,11 @@ def before_feature(context, feature):
3434

3535

3636
def before_scenario(context, scenario):
37+
context.runners = []
3738
if "reset_database" in scenario.tags:
38-
tck_util.send_string("MATCH (n) DETACH DELETE n")
39+
session = tck_util.driver.session()
40+
session.run("MATCH (n) DETACH DELETE n")
41+
session.close()
3942
if "equality_test" in scenario.tags:
4043
context.values = {}
4144

@@ -59,8 +62,10 @@ def after_all(context):
5962
raise Exception("\tTCK FAILED!")
6063

6164

62-
6365
def after_scenario(context, scenario):
64-
if scenario.status != "passed":
65-
raise Exception("%s did not pass" %scenario)
66+
pass
67+
for runner in tck_util.runners:
68+
runner.close()
69+
# if scenario.status != "passed":
70+
# raise Exception("%s did not pass" %scenario)
6671

test/tck/resultparser.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,21 @@ def get_path(string_path):
181181
string_path = string_path[1:-1]
182182
n, string_path = get_node(string_path)
183183
list_of_nodes_and_rel = [n]
184-
n.identity = ++id
184+
id+=1
185+
n.id = id
185186
while string_path != '':
186187
r, string_path, point_up = get_relationship(string_path)
187188
n, string_path = get_node(string_path)
188-
n.identity = ++id
189+
id+=1
190+
n.id = id
189191
if point_up:
190-
r.start = list_of_nodes_and_rel[-1].identity
191-
r.end = n.identity
192-
r.identity = 0
192+
r.start = list_of_nodes_and_rel[-1].id
193+
r.end = n.id
194+
r.id = 0
193195
else:
194-
r.start = n.identity
195-
r.end = list_of_nodes_and_rel[-1].identity
196-
r.identity = 0
196+
r.start = n.id
197+
r.end = list_of_nodes_and_rel[-1].id
198+
r.id = 0
197199
list_of_nodes_and_rel.append(r)
198200
list_of_nodes_and_rel.append(n)
199201
path = Path(list_of_nodes_and_rel[0], *list_of_nodes_and_rel[1:])

test/tck/steps/bolt_compability_steps.py

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

2525
from behave import *
2626

27+
from test.tck import tck_util
2728
from test.tck.resultparser import parse_values
2829
from test.tck.tck_util import to_unicode, Type, send_string, send_parameters, string_to_type
2930

@@ -33,7 +34,9 @@
3334

3435
@given("A running database")
3536
def step_impl(context):
36-
send_string("RETURN 1")
37+
session = tck_util.driver.session()
38+
session.run("RETURN 1")
39+
session.close()
3740

3841

3942
@given("a value (?P<input>.+)")
@@ -80,22 +83,21 @@ def step_impl(context, size, type):
8083

8184
@when("the driver asks the server to echo this (?P<unused>.+) back")
8285
def step_impl(context, unused):
83-
context.results = [ send_string("RETURN " + as_cypher_text(context.expected)), send_parameters("RETURN {input}", {'input': context.expected})]
86+
str_runner = tck_util.Runner("RETURN " + as_cypher_text(context.expected)).run()
87+
param_runner = tck_util.Runner("RETURN {input}", {'input': context.expected}).run()
88+
context.runners += [str_runner, param_runner]
89+
context.results = [str_runner.result, param_runner.result]
8490

8591

8692
@step("the value given in the result should be the same as what was sent")
8793
def step_impl(context):
8894
assert len(context.results) > 0
89-
print(context.results[0])
90-
print(list(context.results[0]))
9195
for result in context.results:
92-
print(result)
93-
for record in result:
94-
print(record)
95-
assert len(list(result)) == 1
96-
result_value = result.record().values()[0]
96+
records = list(result)
97+
assert len(records) == 1
98+
assert len(records[0].values()) == 1
99+
result_value = records[0].values()[0]
97100
assert result_value == context.expected
98-
assert result.at_end()
99101

100102

101103
def as_cypher_text(expected):

0 commit comments

Comments
 (0)