Skip to content

Commit 6debbc9

Browse files
committed
Merge pull request #41 from neo4j/1.0-tck-tests
1.0 tck tests - ResultSummary API and Equality
2 parents f1350ad + 3083a85 commit 6debbc9

File tree

9 files changed

+309
-43
lines changed

9 files changed

+309
-43
lines changed

neo4j/.DS_Store

6 KB
Binary file not shown.

neo4j/v1/session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class which can be used to obtain `Driver` instances that are used for
4343
STATEMENT_TYPE_READ_ONLY = "r"
4444
STATEMENT_TYPE_READ_WRITE = "rw"
4545
STATEMENT_TYPE_WRITE_ONLY = "w"
46-
STATEMENT_TYPE_SCHEMA_WRITE = "sw"
46+
STATEMENT_TYPE_SCHEMA_WRITE = "s"
4747

4848

4949
def basic_auth(user, password):
@@ -333,11 +333,11 @@ def __repr__(self):
333333

334334
@property
335335
def contains_updates(self):
336-
return self.nodes_created or self.nodes_deleted or \
336+
return bool(self.nodes_created or self.nodes_deleted or \
337337
self.relationships_created or self.relationships_deleted or \
338338
self.properties_set or self.labels_added or self.labels_removed or \
339339
self.indexes_added or self.indexes_removed or \
340-
self.constraints_added or self.constraints_removed
340+
self.constraints_added or self.constraints_removed)
341341

342342

343343
#: A plan describes how the database will execute your statement.

test/tck/environment.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,46 @@
2020

2121
from test.tck import tck_util
2222

23-
24-
def before_all(context):
25-
context.config.setup_logging()
23+
failing_features = {}
2624

2725

2826
def before_feature(context, feature):
2927
# Workaround. Behave has a different way of tagging than cucumber
3028
for scenario in feature.scenarios:
3129
scenario.tags += feature.tags
3230

31+
3332
def before_scenario(context, scenario):
33+
context.runners = []
3434
if "reset_database" in scenario.tags:
35-
tck_util.send_string("MATCH (n) DETACH DELETE n")
35+
session = tck_util.driver.session()
36+
session.run("MATCH (n) DETACH DELETE n")
37+
session.close()
38+
if "equality_test" in scenario.tags:
39+
context.values = {}
40+
41+
42+
def after_feature(context, feature):
43+
failed_scenarios = []
44+
for scenario in feature.scenarios:
45+
if scenario.status == "untested" or scenario.status == "failed" :
46+
failed_scenarios.append(scenario.name)
47+
if len(failed_scenarios) > 0:
48+
failing_features[feature.name] = failed_scenarios
49+
50+
51+
def after_all(context):
52+
if len(failing_features) != 0:
53+
print("Following Features failed in TCK:")
54+
for feature, list_of_scenarios in failing_features.items():
55+
print("Feature: %s" %feature)
56+
for scenario in list_of_scenarios:
57+
print("Failing scenario: %s" % scenario)
58+
raise Exception("\tTCK FAILED!")
3659

3760

3861
def after_scenario(context, scenario):
39-
if scenario.status != "passed":
40-
raise Exception("%s did not pass" %scenario)
62+
pass
63+
for runner in tck_util.runners:
64+
runner.close()
4165

test/tck/resultparser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ 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.id = ++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.id = ++id
189+
id+=1
190+
n.id = id
189191
if point_up:
190192
r.start = list_of_nodes_and_rel[-1].id
191193
r.end = n.id

test/tck/steps/bolt_compability_steps.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@
2424

2525
from behave import *
2626

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

3031
from neo4j.v1 import compat
3132
use_step_matcher("re")
3233

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,15 +83,20 @@ 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 = {"as_string": send_string("RETURN " + as_cypher_text(context.expected)),
84-
"as_parameters": 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]
8590

8691

8792
@step("the value given in the result should be the same as what was sent")
8893
def step_impl(context):
8994
assert len(context.results) > 0
90-
for result in context.results.values():
91-
result_value = result[0].values()[0]
95+
for result in context.results:
96+
records = list(result)
97+
assert len(records) == 1
98+
assert len(records[0].values()) == 1
99+
result_value = records[0].values()[0]
92100
assert result_value == context.expected
93101

94102

test/tck/steps/cypher_compability_steps.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from behave import *
2222

23+
from test.tck import tck_util
2324
from test.tck.tck_util import TestValue, send_string, send_parameters
2425
from test.tck.resultparser import parse_values, parse_values_to_comparable
2526

@@ -28,31 +29,38 @@
2829

2930
@given("init: (?P<statement>.+)")
3031
def step_impl(context, statement):
31-
send_string(statement)
32+
session = tck_util.driver.session()
33+
session.run(statement)
34+
session.close()
3235

3336

34-
@when("running: (?P<statement>.+)")
37+
@step("running: (?P<statement>.+)")
3538
def step_impl(context, statement):
36-
context.results = {"as_string": send_string(statement)}
39+
runner = tck_util.Runner(statement).run()
40+
context.runners.append(runner)
41+
context.results = [runner.result]
3742

3843

39-
@then("result")
40-
def step_impl(context):
41-
result = context.results["as_string"]
42-
given = driver_result_to_comparable_result(result)
43-
expected = table_to_comparable_result(context.table)
44-
if not unordered_equal(given, expected):
45-
raise Exception("Does not match given: \n%s expected: \n%s" % (given, expected))
46-
47-
48-
@when('running parametrized: (?P<statement>.+)')
44+
@step('running parametrized: (?P<statement>.+)')
4945
def step_impl(context, statement):
5046
assert len(context.table.rows) == 1
5147
keys = context.table.headings
5248
values = context.table.rows[0]
5349
parameters = {keys[i]: parse_values(values[i]) for i in range(len(keys))}
50+
runner = tck_util.Runner(statement, parameters).run()
51+
context.runners.append(runner)
52+
context.results = [runner.result]
5453

55-
context.results = {"as_string": send_parameters(statement, parameters)}
54+
55+
@then("result")
56+
def step_impl(context):
57+
expected = table_to_comparable_result(context.table)
58+
assert(len(context.results) > 0)
59+
for result in context.results:
60+
records = list(result)
61+
given = driver_result_to_comparable_result(records)
62+
if not unordered_equal(given, expected):
63+
raise Exception("Does not match given: \n%s expected: \n%s" % (given, expected))
5664

5765

5866
def _driver_value_to_comparable(val):
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
# Copyright (c) 2002-2016 "Neo Technology,"
5+
# Network Engine for Objects in Lund AB [http://neotechnology.com]
6+
#
7+
# This file is part of Neo4j.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
21+
from behave import *
22+
23+
from test.tck.tck_util import send_string
24+
25+
use_step_matcher("re")
26+
27+
28+
@step("`(?P<key>.+)` is single value result of: (?P<statement>.+)")
29+
def step_impl(context, key, statement):
30+
runner = send_string(statement)
31+
records = list(runner.result)
32+
assert len(records) == 1
33+
assert len(records[0]) == 1
34+
context.values[key] = records[0][0]
35+
36+
37+
@step("saved values should all equal")
38+
def step_impl(context):
39+
values = list(context.values.values())
40+
assert len(values) > 1
41+
first_val = values.pop()
42+
for item in values:
43+
assert item == first_val
44+
45+
46+
@step("none of the saved values should be equal")
47+
def step_impl(context):
48+
values = list(context.values.values())
49+
assert len(values) > 1
50+
first_val = values.pop()
51+
for item in values:
52+
assert item != first_val

0 commit comments

Comments
 (0)