Skip to content

Commit 819b4d3

Browse files
committed
Merge pull request #11 from neo4j/params-test
Add failing test to illustrate issue found at hackathon
2 parents 3a29e88 + db03510 commit 819b4d3

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

neo4j/v1/packstream.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@
318318
STRING_TYPE = str
319319
else:
320320
INTEGER_TYPE = (int, long)
321-
STRING_TYPE = unicode
321+
STRING_TYPE = (str, unicode)
322322

323323
__all__ = ["Packer", "pack", "packb", "Unpacker", "unpack", "unpackb"]
324324

@@ -493,17 +493,21 @@ def pack(self, value):
493493
else:
494494
raise OverflowError("Integer %s out of range" % value)
495495

496-
# Bytes
497-
elif isinstance(value, bytes):
498-
self.pack_bytes_header(len(value))
499-
self.pack_raw(value)
500-
501496
# String
502497
elif isinstance(value, STRING_TYPE):
503-
value_bytes = value.encode(ENCODING)
498+
if isinstance(value, bytes):
499+
value_bytes = value
500+
else:
501+
value_bytes = value.encode(ENCODING)
504502
self.pack_string_header(len(value_bytes))
505503
self.pack_raw(value_bytes)
506504

505+
# Bytes (deliberately listed after String since in
506+
# Python 2, bytes should be treated as a String)
507+
elif isinstance(value, (bytes, bytearray)):
508+
self.pack_bytes_header(len(value))
509+
self.pack_raw(value)
510+
507511
# List
508512
elif isinstance(value, list):
509513
self.pack_list_header(len(value))

test/test_packstream.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,17 @@ def test_negative_float64(self):
124124
assert_packable(r, expected)
125125

126126
def test_empty_bytes(self):
127-
assert_packable(b"", b"\xCC\x00")
127+
assert_packable(bytearray(), b"\xCC\x00")
128128

129129
def test_bytes_8(self):
130-
assert_packable(b"hello", b"\xCC\x05hello")
130+
assert_packable(bytearray(b"hello"), b"\xCC\x05hello")
131131

132132
def test_bytes_16(self):
133-
b = bytes(bytearray(40000))
133+
b = bytearray(40000)
134134
assert_packable(b, b"\xCD\x9C\x40" + b)
135135

136136
def test_bytes_32(self):
137-
b = bytes(bytearray(80000))
137+
b = bytearray(80000)
138138
assert_packable(b, b"\xCE\x00\x01\x38\x80" + b)
139139

140140
def test_empty_string(self):

test/test_session.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from neo4j.v1.session import GraphDatabase, CypherError
2525
from neo4j.v1.typesystem import Node, Relationship, Path
2626

27+
2728
class RunTestCase(TestCase):
2829
def test_must_use_valid_url_scheme(self):
2930
with self.assertRaises(ValueError):
@@ -48,6 +49,18 @@ def test_can_run_simple_statement(self):
4849
session.close()
4950
assert count == 1
5051

52+
def test_can_run_simple_statement_with_params(self):
53+
session = GraphDatabase.driver("bolt://localhost").session()
54+
count = 0
55+
for record in session.run("RETURN {x} AS n", {"x": {"abc": ["d", "e", "f"]}}):
56+
assert record[0] == {"abc": ["d", "e", "f"]}
57+
assert record["n"] == {"abc": ["d", "e", "f"]}
58+
assert repr(record)
59+
assert len(record) == 1
60+
count += 1
61+
session.close()
62+
assert count == 1
63+
5164
def test_fails_on_bad_syntax(self):
5265
session = GraphDatabase.driver("bolt://localhost").session()
5366
with self.assertRaises(CypherError):

0 commit comments

Comments
 (0)