From adbf4a49ff4846dbccafc79da60356b541dccfe4 Mon Sep 17 00:00:00 2001 From: Zhen Date: Tue, 13 Oct 2015 17:34:18 +0200 Subject: [PATCH 01/10] Fix the failure in CI -o Fixed wrong input type for hex method -o Fixed wrong assertion on array --- neo4j/connection.py | 3 ++- neoget.sh | 5 ++--- runtests.sh | 2 +- test/session_test.py | 2 ++ test/typesystem_test.py | 6 +++--- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/neo4j/connection.py b/neo4j/connection.py index e8e4150bb..1e8fb8545 100644 --- a/neo4j/connection.py +++ b/neo4j/connection.py @@ -70,7 +70,8 @@ log_error = log.error -def hex2(x): +def hex2(str): + x = ord(str) if x < 0x10: return "0" + hex(x)[2:].upper() else: diff --git a/neoget.sh b/neoget.sh index 46052bcf5..8e98d8a4f 100755 --- a/neoget.sh +++ b/neoget.sh @@ -21,7 +21,7 @@ EDITION="community" MODE="" CHECK_EXISTS=0 ALL_VERSIONS="2.3.0-M02 2.2.2 2.1.8 2.0.4" -ALPHA_VERSION="3.0.0-alpha" +ALPHA_VERSION="3.0.0-M01" function usage { SCRIPT=$(basename $0) @@ -83,7 +83,7 @@ function download { fi if [ $DOWNLOAD -eq 1 ] then - if [[ "${VERSION}" == *"alpha"* ]] + if [[ "$ALL_VERSIONS" == "$ALPHA_VERSION" ]] then URL="${ALPHA}/${ARCHIVE}" else @@ -161,4 +161,3 @@ then else download fi - diff --git a/runtests.sh b/runtests.sh index 9399d8448..edddd94b8 100755 --- a/runtests.sh +++ b/runtests.sh @@ -97,5 +97,5 @@ if [ ${RUNNING} -eq 1 ] then runtests else - runserverandtests "3.0.0-alpha" + runserverandtests "3.0.0-M01" fi diff --git a/test/session_test.py b/test/session_test.py index 7397f535e..9c9f78fa5 100644 --- a/test/session_test.py +++ b/test/session_test.py @@ -190,6 +190,8 @@ def test_can_rollback_transaction(self): tx.rollback() + # I do not know how this framework works to close the tx after each method call + # But it should be closed due to the rollback # Check the property value result = session.run("MATCH (a) WHERE id(a) = {n} " "RETURN a.foo", {"n": node_id}) diff --git a/test/typesystem_test.py b/test/typesystem_test.py index fcf4f7222..7347f55f3 100644 --- a/test/typesystem_test.py +++ b/test/typesystem_test.py @@ -168,7 +168,7 @@ def test_can_hydrate_node_structure(self): alice = hydrated(struct) assert alice.identity == "node/123" assert alice.labels == {"Person"} - assert alice.keys() == {"name"} + assert alice.keys()[0] == "name" assert alice.get("name") == "Alice" def test_hydrating_unknown_structure_returns_same(self): @@ -187,7 +187,7 @@ def test_can_hydrate_in_list(self): alice, = alice_in_list assert alice.identity == "node/123" assert alice.labels == {"Person"} - assert alice.keys() == {"name"} + assert alice.keys()[0] == "name" assert alice.get("name") == "Alice" def test_can_hydrate_in_dict(self): @@ -200,7 +200,7 @@ def test_can_hydrate_in_dict(self): alice = alice_in_dict["foo"] assert alice.identity == "node/123" assert alice.labels == {"Person"} - assert alice.keys() == {"name"} + assert alice.keys()[0] == "name" assert alice.get("name") == "Alice" From c54c6703c2a06c6bfd34e4f9549b8e63a1ac6ed1 Mon Sep 17 00:00:00 2001 From: Nigel Small Date: Thu, 15 Oct 2015 10:53:16 +0100 Subject: [PATCH 02/10] Fixed for Python 3.4 --- neo4j/connection.py | 3 +-- runtests.sh | 3 ++- test/typesystem_test.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/neo4j/connection.py b/neo4j/connection.py index 1e8fb8545..e8e4150bb 100644 --- a/neo4j/connection.py +++ b/neo4j/connection.py @@ -70,8 +70,7 @@ log_error = log.error -def hex2(str): - x = ord(str) +def hex2(x): if x < 0x10: return "0" + hex(x)[2:].upper() else: diff --git a/runtests.sh b/runtests.sh index edddd94b8..fc008321f 100755 --- a/runtests.sh +++ b/runtests.sh @@ -32,7 +32,7 @@ function runserverandtests { mkdir -p ${DOT_TEST} 2> /dev/null pushd ${DOT_TEST} > /dev/null - tar xf $(${NEOGET} -ex ${NEO_VERSION}) + tar xf $(${NEOGET} ${NEOGET_ARGS}) NEO_HOME=$(ls -1Ft | grep "/$" | head -1) # finds the newest directory relative to .test echo "xx.bolt.enabled=true" >> ${NEO_HOME}/conf/neo4j-server.properties ${NEO_HOME}/bin/neo4j start @@ -97,5 +97,6 @@ if [ ${RUNNING} -eq 1 ] then runtests else + NEOGET_ARGS="-eax" runserverandtests "3.0.0-M01" fi diff --git a/test/typesystem_test.py b/test/typesystem_test.py index 7347f55f3..fcf4f7222 100644 --- a/test/typesystem_test.py +++ b/test/typesystem_test.py @@ -168,7 +168,7 @@ def test_can_hydrate_node_structure(self): alice = hydrated(struct) assert alice.identity == "node/123" assert alice.labels == {"Person"} - assert alice.keys()[0] == "name" + assert alice.keys() == {"name"} assert alice.get("name") == "Alice" def test_hydrating_unknown_structure_returns_same(self): @@ -187,7 +187,7 @@ def test_can_hydrate_in_list(self): alice, = alice_in_list assert alice.identity == "node/123" assert alice.labels == {"Person"} - assert alice.keys()[0] == "name" + assert alice.keys() == {"name"} assert alice.get("name") == "Alice" def test_can_hydrate_in_dict(self): @@ -200,7 +200,7 @@ def test_can_hydrate_in_dict(self): alice = alice_in_dict["foo"] assert alice.identity == "node/123" assert alice.labels == {"Person"} - assert alice.keys()[0] == "name" + assert alice.keys() == {"name"} assert alice.get("name") == "Alice" From f08ec3ef0eb429639afc366843ef59dae4cc9e8a Mon Sep 17 00:00:00 2001 From: Nigel Small Date: Thu, 15 Oct 2015 11:07:15 +0100 Subject: [PATCH 03/10] Fixed tests for py2 --- test/typesystem_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/typesystem_test.py b/test/typesystem_test.py index fcf4f7222..a785ec2c8 100644 --- a/test/typesystem_test.py +++ b/test/typesystem_test.py @@ -168,7 +168,7 @@ def test_can_hydrate_node_structure(self): alice = hydrated(struct) assert alice.identity == "node/123" assert alice.labels == {"Person"} - assert alice.keys() == {"name"} + assert set(alice.keys()) == {"name"} assert alice.get("name") == "Alice" def test_hydrating_unknown_structure_returns_same(self): @@ -187,7 +187,7 @@ def test_can_hydrate_in_list(self): alice, = alice_in_list assert alice.identity == "node/123" assert alice.labels == {"Person"} - assert alice.keys() == {"name"} + assert set(alice.keys()) == {"name"} assert alice.get("name") == "Alice" def test_can_hydrate_in_dict(self): @@ -200,7 +200,7 @@ def test_can_hydrate_in_dict(self): alice = alice_in_dict["foo"] assert alice.identity == "node/123" assert alice.labels == {"Person"} - assert alice.keys() == {"name"} + assert set(alice.keys()) == {"name"} assert alice.get("name") == "Alice" From a968ff8a680562425c3c01b386ce6f59527fb050 Mon Sep 17 00:00:00 2001 From: Nigel Small Date: Thu, 15 Oct 2015 11:12:19 +0100 Subject: [PATCH 04/10] Moved hex2 to compat --- neo4j/compat.py | 14 ++++++++++++++ neo4j/connection.py | 13 +++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/neo4j/compat.py b/neo4j/compat.py index 719f8070e..978d5448e 100644 --- a/neo4j/compat.py +++ b/neo4j/compat.py @@ -34,10 +34,24 @@ except NameError: integer = int string = str + + def hex2(x): + if x < 0x10: + return "0" + hex(x)[2:].upper() + else: + return hex(x)[2:].upper() + else: integer = (int, long) string = (str, unicode) + def hex2(x): + x = ord(x) + if x < 0x10: + return "0" + hex(x)[2:].upper() + else: + return hex(x)[2:].upper() + try: from multiprocessing import Array, Process diff --git a/neo4j/connection.py b/neo4j/connection.py index e8e4150bb..f763af33e 100644 --- a/neo4j/connection.py +++ b/neo4j/connection.py @@ -20,7 +20,7 @@ from __future__ import division -from collections import deque, namedtuple +from collections import deque from io import BytesIO import logging from os import environ @@ -28,9 +28,9 @@ from socket import create_connection, SHUT_RDWR from struct import pack as struct_pack, unpack as struct_unpack, unpack_from as struct_unpack_from -from .compat import perf_counter, secure_socket +from .compat import hex2, secure_socket from .exceptions import ProtocolError -from .packstream import Packer, Unpacker, Structure +from .packstream import Packer, Unpacker DEFAULT_PORT = 7687 @@ -70,13 +70,6 @@ log_error = log.error -def hex2(x): - if x < 0x10: - return "0" + hex(x)[2:].upper() - else: - return hex(x)[2:].upper() - - class ChunkChannel(object): """ Reader/writer for chunked data. From 97976fd859000ba6ba0acf8cd5e4206cc6fc8931 Mon Sep 17 00:00:00 2001 From: Nigel Small Date: Thu, 15 Oct 2015 11:30:14 +0100 Subject: [PATCH 05/10] String differences --- neo4j/session.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/neo4j/session.py b/neo4j/session.py index ea182299f..bc39f9e09 100644 --- a/neo4j/session.py +++ b/neo4j/session.py @@ -204,7 +204,14 @@ def run(self, statement, parameters=None): if isinstance(statement, bytes): statement = statement.decode("UTF-8") - parameters = dict(parameters or {}) + parameters = {} + for key, value in (parameters or {}).items(): + if isinstance(key, bytes): + key = key.decode("UTF-8") + if isinstance(value, bytes): + parameters[key] = value.decode("UTF-8") + else: + parameters[key] = value t = BenchTest() t.init = perf_counter() From 17d3f58f1a4d8014f1a70b3c2723e239d29e8a09 Mon Sep 17 00:00:00 2001 From: Nigel Small Date: Thu, 15 Oct 2015 11:33:16 +0100 Subject: [PATCH 06/10] optional ignored metadata --- neo4j/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo4j/connection.py b/neo4j/connection.py index f763af33e..11111bf15 100644 --- a/neo4j/connection.py +++ b/neo4j/connection.py @@ -192,7 +192,7 @@ def on_success(self, metadata): def on_failure(self, metadata): pass - def on_ignored(self, metadata): + def on_ignored(self, metadata=None): pass From fcbbd343130b79a684e2e0e805cb3acf332d070a Mon Sep 17 00:00:00 2001 From: Nigel Small Date: Thu, 15 Oct 2015 12:12:17 +0100 Subject: [PATCH 07/10] Specify tests to test runner --- runtests.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtests.sh b/runtests.sh index fc008321f..b7b8571eb 100755 --- a/runtests.sh +++ b/runtests.sh @@ -44,7 +44,7 @@ function runserverandtests { popd > /dev/null echo -n "Testing" - coverage run -m unittest test + coverage run -m unittest "${TESTS}" pushd ${DOT_TEST} > /dev/null ${NEO_HOME}/bin/neo4j stop @@ -93,6 +93,12 @@ do esac done +TESTS=$1 +if [ "${TESTS}" == "" ] +then + TESTS="test" +fi + if [ ${RUNNING} -eq 1 ] then runtests From c5d6cacbf827f69afd9dc5d1184266aacf2c8b8a Mon Sep 17 00:00:00 2001 From: Nigel Small Date: Thu, 15 Oct 2015 13:39:10 +0100 Subject: [PATCH 08/10] Fixed param correction --- neo4j/session.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/neo4j/session.py b/neo4j/session.py index bc39f9e09..b893ddabc 100644 --- a/neo4j/session.py +++ b/neo4j/session.py @@ -204,14 +204,15 @@ def run(self, statement, parameters=None): if isinstance(statement, bytes): statement = statement.decode("UTF-8") - parameters = {} + params = {} for key, value in (parameters or {}).items(): if isinstance(key, bytes): key = key.decode("UTF-8") if isinstance(value, bytes): - parameters[key] = value.decode("UTF-8") + params[key] = value.decode("UTF-8") else: - parameters[key] = value + params[key] = value + parameters = params t = BenchTest() t.init = perf_counter() From 19f09704f21a001e1bee5b2e4ceea9aeab55dd75 Mon Sep 17 00:00:00 2001 From: Nigel Small Date: Thu, 15 Oct 2015 13:43:12 +0100 Subject: [PATCH 09/10] Error tests --- test/session_test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/session_test.py b/test/session_test.py index 9c9f78fa5..d81c9b6f8 100644 --- a/test/session_test.py +++ b/test/session_test.py @@ -65,6 +65,24 @@ def test_can_run_simple_statement(self): session.close() assert count == 1 + def test_fails_on_bad_syntax(self): + session = GraphDatabase.driver("bolt://localhost").session() + try: + session.run("X").consume() + except CypherError: + assert True + else: + assert False + + def test_fails_on_missing_parameter(self): + session = GraphDatabase.driver("bolt://localhost").session() + try: + session.run("RETURN {x}").consume() + except CypherError: + assert True + else: + assert False + def test_can_run_simple_statement_from_bytes_string(self): session = GraphDatabase.driver("bolt://localhost").session() count = 0 From 2a4a582c37d64f5d9c8e583d885588956928d63a Mon Sep 17 00:00:00 2001 From: Zhen Date: Thu, 15 Oct 2015 16:46:03 +0200 Subject: [PATCH 10/10] Remove meaningless commits --- test/session_test.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/session_test.py b/test/session_test.py index d81c9b6f8..abfac8354 100644 --- a/test/session_test.py +++ b/test/session_test.py @@ -208,8 +208,6 @@ def test_can_rollback_transaction(self): tx.rollback() - # I do not know how this framework works to close the tx after each method call - # But it should be closed due to the rollback # Check the property value result = session.run("MATCH (a) WHERE id(a) = {n} " "RETURN a.foo", {"n": node_id})