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..11111bf15 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. @@ -199,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 diff --git a/neo4j/session.py b/neo4j/session.py index ea182299f..b893ddabc 100644 --- a/neo4j/session.py +++ b/neo4j/session.py @@ -204,7 +204,15 @@ def run(self, statement, parameters=None): if isinstance(statement, bytes): statement = statement.decode("UTF-8") - parameters = dict(parameters or {}) + params = {} + for key, value in (parameters or {}).items(): + if isinstance(key, bytes): + key = key.decode("UTF-8") + if isinstance(value, bytes): + params[key] = value.decode("UTF-8") + else: + params[key] = value + parameters = params t = BenchTest() t.init = perf_counter() 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..b7b8571eb 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 @@ -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,9 +93,16 @@ do esac done +TESTS=$1 +if [ "${TESTS}" == "" ] +then + TESTS="test" +fi + if [ ${RUNNING} -eq 1 ] then runtests else - runserverandtests "3.0.0-alpha" + NEOGET_ARGS="-eax" + runserverandtests "3.0.0-M01" fi diff --git a/test/session_test.py b/test/session_test.py index 7397f535e..abfac8354 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 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"