Skip to content

Commit f0c01e3

Browse files
committed
Now supports both Python 2.7 and 3.5. Polished code from feedback on prvious commit
1 parent 79996d3 commit f0c01e3

File tree

4 files changed

+66
-71
lines changed

4 files changed

+66
-71
lines changed
Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import os
22
import tarfile
3-
import urllib2
4-
53

64
def clean_up():
75
dir_path = (os.path.dirname(os.path.realpath(__file__)))
@@ -13,18 +11,28 @@ def clean_up():
1311

1412
def set_up():
1513
dir_path = (os.path.dirname(os.path.realpath(__file__)))
16-
feature_url = "https://s3-eu-west-1.amazonaws.com/remoting.neotechnology.com/driver-compliance/tck.tar.gz"
17-
file_name = feature_url.split('/')[-1]
18-
tar = open(file_name, 'w')
19-
response = urllib2.urlopen(feature_url)
20-
block_sz = 1024
21-
while True:
22-
buffer = response.read(block_sz)
23-
if not buffer:
24-
break
25-
tar.write(buffer)
26-
tar.close()
14+
url = "https://s3-eu-west-1.amazonaws.com/remoting.neotechnology.com/driver-compliance/tck.tar.gz"
15+
file_name = url.split('/')[-1]
16+
_download_tar(url,file_name)
17+
2718
tar = tarfile.open(file_name)
2819
tar.extractall(dir_path)
2920
tar.close()
3021
os.remove(file_name)
22+
23+
24+
def _download_tar(url, file_name):
25+
try:
26+
import urllib2
27+
tar = open(file_name, 'w')
28+
response = urllib2.urlopen(url)
29+
block_sz = 1024
30+
while True:
31+
buffer = response.read(block_sz)
32+
if not buffer:
33+
break
34+
tar.write(buffer)
35+
tar.close()
36+
except ImportError:
37+
from urllib import request
38+
request.urlretrieve(url, file_name)

test/tck/environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def after_scenario(context, scenario):
1515
for step in scenario.steps:
1616
if step.status == 'failed':
1717
logging.error("Scenario :'%s' at step: '%s' failed! ", scenario.name, step.name)
18-
logging.debug("Expected result: %s", tck_util.as_cypger_text(context.expected))
19-
logging.debug("Actual result: %s", tck_util.as_cypger_text(context.results))
18+
logging.debug("Expected result: %s", tck_util.as_cypher_text(context.expected))
19+
logging.debug("Actual result: %s", tck_util.as_cypher_text(context.results))
2020
if step.status == 'skipped':
2121
logging.warn("Scenario :'%s' at step: '%s' was skipped! ", scenario.name, step.name)
2222
if step.status == 'passed':

test/tck/steps/bolt_type_steps.py

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from test.tck import tck_util
44

5-
from neo4j.v1.typesystem import Node, Relationship, Path
6-
75
use_step_matcher("re")
86

97

@@ -13,19 +11,19 @@ def step_impl(context):
1311
# check if running
1412

1513

16-
@given("a value (?P<Input>.+) of type (?P<BoltType>.+)")
17-
def step_impl(context, Input, BoltType):
18-
context.expected = tck_util.get_bolt_value(BoltType, Input)
14+
@given("a value (?P<input>.+) of type (?P<bolt_type>.+)")
15+
def step_impl(context, input, bolt_type):
16+
context.expected = tck_util.get_bolt_value(bolt_type, input)
1917

2018

21-
@given("a value of type (?P<BoltType>.+)")
22-
def step_impl(context, BoltType):
23-
context.expected = tck_util.get_bolt_value(BoltType, u' ')
19+
@given("a value of type (?P<bolt_type>.+)")
20+
def step_impl(context, bolt_type):
21+
context.expected = tck_util.get_bolt_value(bolt_type, u' ')
2422

2523

26-
@given("a list value (?P<Input>.+) of type (?P<BoltType>.+)")
27-
def step_impl(context, Input, BoltType):
28-
context.expected = tck_util.get_list_from_feature_file(Input, BoltType)
24+
@given("a list value (?P<input>.+) of type (?P<bolt_type>.+)")
25+
def step_impl(context, input, bolt_type):
26+
context.expected = tck_util.get_list_from_feature_file(input, bolt_type)
2927

3028

3129
@given("an empty list L")
@@ -43,14 +41,14 @@ def step_impl(context, size):
4341
context.expected = tck_util.get_random_string(int(size))
4442

4543

46-
@given("a List of size (?P<size>\d+) and type (?P<Type>.+)")
47-
def step_impl(context, size, Type):
48-
context.expected = tck_util.get_list_of_random_type(int(size), Type)
44+
@given("a List of size (?P<size>\d+) and type (?P<type>.+)")
45+
def step_impl(context, size, type):
46+
context.expected = tck_util.get_list_of_random_type(int(size), type)
4947

5048

51-
@given("a Map of size (?P<size>\d+) and type (?P<Type>.+)")
52-
def step_impl(context, size, Type):
53-
context.expected = tck_util.get_dict_of_random_type(int(size), Type)
49+
@given("a Map of size (?P<size>\d+) and type (?P<type>.+)")
50+
def step_impl(context, size, type):
51+
context.expected = tck_util.get_dict_of_random_type(int(size), type)
5452

5553

5654
@step("adding a table of lists to the list L")
@@ -68,7 +66,7 @@ def step_impl(context):
6866
@step("adding a table of values to the map M")
6967
def step_impl(context):
7068
for row in context.table:
71-
context.M['a' + str(len(context.M))] = tck_util.get_bolt_value(row[0], row[1])
69+
context.M['a%d' % len(context.M)] = tck_util.get_bolt_value(row[0], row[1])
7270

7371

7472
@step("adding map M to list L")
@@ -79,40 +77,40 @@ def step_impl(context):
7977
@when("adding a table of lists to the map M")
8078
def step_impl(context):
8179
for row in context.table:
82-
context.M['a' + str(len(context.M))] = tck_util.get_list_from_feature_file(row[1], row[0])
80+
context.M['a%d' % len(context.M)] = tck_util.get_list_from_feature_file(row[1], row[0])
8381

8482

8583
@step("adding a copy of map M to map M")
8684
def step_impl(context):
87-
context.M['a' + str(len(context.M))] = context.M.copy()
85+
context.M['a%d' % len(context.M)] = context.M.copy()
8886

8987

9088
@when("the driver asks the server to echo this value back")
9189
def step_impl(context):
9290
context.results = {}
93-
context.results["as_string"] = tck_util.send_string("RETURN " + tck_util.as_cypger_text(context.expected))
91+
context.results["as_string"] = tck_util.send_string("RETURN " + tck_util.as_cypher_text(context.expected))
9492
context.results["as_parameters"] = tck_util.send_parameters("RETURN {input}", {'input': context.expected})
9593

9694

9795
@when("the driver asks the server to echo this list back")
9896
def step_impl(context):
9997
context.expected = context.L
10098
context.results = {}
101-
context.results["as_string"] = tck_util.send_string("RETURN " + tck_util.as_cypger_text(context.expected))
99+
context.results["as_string"] = tck_util.send_string("RETURN " + tck_util.as_cypher_text(context.expected))
102100
context.results["as_parameters"] = tck_util.send_parameters("RETURN {input}", {'input': context.expected})
103101

104102

105103
@when("the driver asks the server to echo this map back")
106104
def step_impl(context):
107105
context.expected = context.M
108106
context.results = {}
109-
context.results["as_string"] = tck_util.send_string("RETURN " + tck_util.as_cypger_text(context.expected))
107+
context.results["as_string"] = tck_util.send_string("RETURN " + tck_util.as_cypher_text(context.expected))
110108
context.results["as_parameters"] = tck_util.send_parameters("RETURN {input}", {'input': context.expected})
111109

112110

113111
@then("the result returned from the server should be a single record with a single value")
114112
def step_impl(context):
115-
assert len(context.results) > 0
113+
assert context.results
116114
for result in context.results.values():
117115
assert len(result) == 1
118116
assert len(result[0]) == 1
@@ -123,18 +121,4 @@ def step_impl(context):
123121
assert len(context.results) > 0
124122
for result in context.results.values():
125123
result_value = result[0].values()[0]
126-
assert result_value == context.expected
127-
128-
129-
@step("the node value given in the result should be the same as what was sent")
130-
def step_impl(context):
131-
assert len(context.results) > 0
132-
for result in context.results.values():
133-
result_value = result[0].values()[0]
134-
assert result_value == context.expected
135-
assert result_value.labels == context.expected.labels
136-
assert result_value.keys() == context.expected.keys()
137-
assert result_value.values() == context.expected.values()
138-
assert result_value.items() == context.expected.items()
139-
assert len(result_value) == len(context.expected)
140-
assert iter(result_value) == iter(context.expected)
124+
assert result_value == context.expected

test/tck/tck_util.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import string
22
import random
3-
4-
import sys
3+
from neo4j.v1 import compat
54

65
from neo4j.v1 import GraphDatabase
76

@@ -28,40 +27,40 @@ def get_bolt_value(type, value):
2827
if type == 'Float':
2928
return float(value)
3029
if type == 'String':
31-
return value
30+
return to_unicode(value)
3231
if type == 'Null':
3332
return None
3433
if type == 'Boolean':
3534
return bool(value)
36-
raise ValueError('No such type : %s', type)
35+
raise ValueError('No such type : %s' % type)
3736

3837

39-
def as_cypger_text(expected):
38+
def as_cypher_text(expected):
4039
if expected is None:
4140
return "Null"
42-
if isinstance(expected, unicode):
43-
return '"' + expected + '"'
41+
if isinstance(expected, (str, compat.string)):
42+
return '"' + expected + '"'
4443
if isinstance(expected, float):
4544
return repr(expected).replace('+', '')
4645
if isinstance(expected, list):
4746
l = u'['
4847
for i, val in enumerate(expected):
49-
l += as_cypger_text(val)
48+
l += as_cypher_text(val)
5049
if i < len(expected)-1:
5150
l+= u','
5251
l += u']'
5352
return l
5453
if isinstance(expected, dict):
5554
d = u'{'
5655
for i, (key, val) in enumerate(expected.items()):
57-
d += unicode(key) + ':'
58-
d += as_cypger_text(val)
56+
d += to_unicode(key) + ':'
57+
d += as_cypher_text(val)
5958
if i < len(expected.items())-1:
6059
d+= u','
6160
d += u'}'
6261
return d
6362
else:
64-
return unicode(expected)
63+
return to_unicode(expected)
6564

6665

6766
def get_list_from_feature_file(string_list, bolt_type):
@@ -89,7 +88,7 @@ def get_none():
8988

9089
if type == 'Integer':
9190
fu = random.randint
92-
args = [-sys.maxint - 1, sys.maxint]
91+
args = [-9223372036854775808, 9223372036854775808]
9392
elif type == 'Float':
9493
fu = random.random
9594
args = []
@@ -103,7 +102,7 @@ def get_none():
103102
fu = get_random_bool
104103
args = []
105104
else:
106-
raise ValueError('No such type : %s', type)
105+
raise ValueError('No such type : %s' % type)
107106
return (fu, args)
108107

109108

@@ -114,7 +113,11 @@ def get_list_of_random_type(size, type):
114113

115114
def get_dict_of_random_type(size, type):
116115
fu, args = _get_random_func(type)
117-
map = {}
118-
for i in range(size):
119-
map['a' + str(i)] = fu(*args)
120-
return map
116+
return {'a%d' % i: fu(*args) for i in range(size)}
117+
118+
def to_unicode(val):
119+
try:
120+
return unicode(val)
121+
except NameError:
122+
return str(val)
123+

0 commit comments

Comments
 (0)