Skip to content

1.0 tck tests - ResultSummary API and Equality #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 30, 2016
Merged
Binary file added neo4j/.DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions neo4j/v1/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class which can be used to obtain `Driver` instances that are used for
STATEMENT_TYPE_READ_ONLY = "r"
STATEMENT_TYPE_READ_WRITE = "rw"
STATEMENT_TYPE_WRITE_ONLY = "w"
STATEMENT_TYPE_SCHEMA_WRITE = "sw"
STATEMENT_TYPE_SCHEMA_WRITE = "s"


def basic_auth(user, password):
Expand Down Expand Up @@ -333,11 +333,11 @@ def __repr__(self):

@property
def contains_updates(self):
return self.nodes_created or self.nodes_deleted or \
return bool(self.nodes_created or self.nodes_deleted or \
self.relationships_created or self.relationships_deleted or \
self.properties_set or self.labels_added or self.labels_removed or \
self.indexes_added or self.indexes_removed or \
self.constraints_added or self.constraints_removed
self.constraints_added or self.constraints_removed)


#: A plan describes how the database will execute your statement.
Expand Down
36 changes: 30 additions & 6 deletions test/tck/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,46 @@

from test.tck import tck_util


def before_all(context):
context.config.setup_logging()
failing_features = {}


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


def before_scenario(context, scenario):
context.runners = []
if "reset_database" in scenario.tags:
tck_util.send_string("MATCH (n) DETACH DELETE n")
session = tck_util.driver.session()
session.run("MATCH (n) DETACH DELETE n")
session.close()
if "equality_test" in scenario.tags:
context.values = {}


def after_feature(context, feature):
failed_scenarios = []
for scenario in feature.scenarios:
if scenario.status == "untested" or scenario.status == "failed" :
failed_scenarios.append(scenario.name)
if len(failed_scenarios) > 0:
failing_features[feature.name] = failed_scenarios


def after_all(context):
if len(failing_features) != 0:
print("Following Features failed in TCK:")
for feature, list_of_scenarios in failing_features.items():
print("Feature: %s" %feature)
for scenario in list_of_scenarios:
print("Failing scenario: %s" % scenario)
raise Exception("\tTCK FAILED!")


def after_scenario(context, scenario):
if scenario.status != "passed":
raise Exception("%s did not pass" %scenario)
pass
for runner in tck_util.runners:
runner.close()

6 changes: 4 additions & 2 deletions test/tck/resultparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ def get_path(string_path):
string_path = string_path[1:-1]
n, string_path = get_node(string_path)
list_of_nodes_and_rel = [n]
n.id = ++id
id+=1
n.id = id
while string_path != '':
r, string_path, point_up = get_relationship(string_path)
n, string_path = get_node(string_path)
n.id = ++id
id+=1
n.id = id
if point_up:
r.start = list_of_nodes_and_rel[-1].id
r.end = n.id
Expand Down
20 changes: 14 additions & 6 deletions test/tck/steps/bolt_compability_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@

from behave import *

from test.tck import tck_util
from test.tck.resultparser import parse_values
from test.tck.tck_util import to_unicode, Type, send_string, send_parameters, string_to_type
from test.tck.tck_util import to_unicode, Type, string_to_type

from neo4j.v1 import compat
use_step_matcher("re")


@given("A running database")
def step_impl(context):
send_string("RETURN 1")
session = tck_util.driver.session()
session.run("RETURN 1")
session.close()


@given("a value (?P<input>.+)")
Expand Down Expand Up @@ -80,15 +83,20 @@ def step_impl(context, size, type):

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


@step("the value given in the result should be the same as what was sent")
def step_impl(context):
assert len(context.results) > 0
for result in context.results.values():
result_value = result[0].values()[0]
for result in context.results:
records = list(result)
assert len(records) == 1
assert len(records[0].values()) == 1
result_value = records[0].values()[0]
assert result_value == context.expected


Expand Down
36 changes: 22 additions & 14 deletions test/tck/steps/cypher_compability_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from behave import *

from test.tck import tck_util
from test.tck.tck_util import TestValue, send_string, send_parameters
from test.tck.resultparser import parse_values, parse_values_to_comparable

Expand All @@ -28,31 +29,38 @@

@given("init: (?P<statement>.+)")
def step_impl(context, statement):
send_string(statement)
session = tck_util.driver.session()
session.run(statement)
session.close()


@when("running: (?P<statement>.+)")
@step("running: (?P<statement>.+)")
def step_impl(context, statement):
context.results = {"as_string": send_string(statement)}
runner = tck_util.Runner(statement).run()
context.runners.append(runner)
context.results = [runner.result]


@then("result")
def step_impl(context):
result = context.results["as_string"]
given = driver_result_to_comparable_result(result)
expected = table_to_comparable_result(context.table)
if not unordered_equal(given, expected):
raise Exception("Does not match given: \n%s expected: \n%s" % (given, expected))


@when('running parametrized: (?P<statement>.+)')
@step('running parametrized: (?P<statement>.+)')
def step_impl(context, statement):
assert len(context.table.rows) == 1
keys = context.table.headings
values = context.table.rows[0]
parameters = {keys[i]: parse_values(values[i]) for i in range(len(keys))}
runner = tck_util.Runner(statement, parameters).run()
context.runners.append(runner)
context.results = [runner.result]

context.results = {"as_string": send_parameters(statement, parameters)}

@then("result")
def step_impl(context):
expected = table_to_comparable_result(context.table)
assert(len(context.results) > 0)
for result in context.results:
records = list(result)
given = driver_result_to_comparable_result(records)
if not unordered_equal(given, expected):
raise Exception("Does not match given: \n%s expected: \n%s" % (given, expected))


def _driver_value_to_comparable(val):
Expand Down
52 changes: 52 additions & 0 deletions test/tck/steps/driver_equality_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

# Copyright (c) 2002-2016 "Neo Technology,"
# Network Engine for Objects in Lund AB [http://neotechnology.com]
#
# This file is part of Neo4j.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from behave import *

from test.tck.tck_util import send_string

use_step_matcher("re")


@step("`(?P<key>.+)` is single value result of: (?P<statement>.+)")
def step_impl(context, key, statement):
runner = send_string(statement)
records = list(runner.result)
assert len(records) == 1
assert len(records[0]) == 1
context.values[key] = records[0][0]


@step("saved values should all equal")
def step_impl(context):
values = list(context.values.values())
assert len(values) > 1
first_val = values.pop()
for item in values:
assert item == first_val


@step("none of the saved values should be equal")
def step_impl(context):
values = list(context.values.values())
assert len(values) > 1
first_val = values.pop()
for item in values:
assert item != first_val
Loading