Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions neo4j/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 4 additions & 11 deletions neo4j/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@

from __future__ import division

from collections import deque, namedtuple
from collections import deque
from io import BytesIO
import logging
from os import environ
from select import select
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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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


Expand Down
10 changes: 9 additions & 1 deletion neo4j/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions neoget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -161,4 +161,3 @@ then
else
download
fi

13 changes: 10 additions & 3 deletions runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
18 changes: 18 additions & 0 deletions test/session_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/typesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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"


Expand Down