Skip to content

Commit bb758ab

Browse files
committed
Updated tests after new feature file design
1 parent 683e39e commit bb758ab

File tree

5 files changed

+247
-307
lines changed

5 files changed

+247
-307
lines changed

test/tck/configure_feature_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ def _download_tar(url, file_name):
5656
tar.close()
5757
except ImportError:
5858
from urllib import request
59-
request.urlretrieve(url, file_name)
59+
request.urlretrieve(url, file_name)

test/tck/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ def before_feature(context, feature):
3434

3535
def before_scenario(context, scenario):
3636
if "reset_database" in scenario.tags:
37-
tck_util.send_string("MATCH (n) DETACH DELETE n")
37+
tck_util.send_string("MATCH (n) DETACH DELETE n")

test/tck/resultparser.py

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
# Copyright (c) 2002-2016 "Neo Technology,"
5+
# Network Engine for Objects in Lund AB [http://neotechnology.com]
6+
#
7+
# This file is part of Neo4j.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
21+
import json
22+
import re
23+
from neo4j.v1 import Node, Relationship, Path
24+
from tck_util import Value
25+
26+
27+
def parse_values_to_comparable(row):
28+
return _parse(row, True)
29+
30+
31+
def parse_values(row):
32+
return _parse(row, False)
33+
34+
35+
def _parse(row, comparable=False):
36+
if is_array(row):
37+
values = get_array(row)
38+
result = []
39+
for val in values:
40+
result.append(_parse(val, comparable))
41+
return result
42+
elif is_map(row):
43+
if comparable:
44+
raise ValueError("No support for pasing maps of Node/Rels/paths atm")
45+
return get_map(row)
46+
else:
47+
if comparable:
48+
return value_to_comparable_object(row)
49+
else:
50+
return value_to_object(row)
51+
52+
53+
def is_array(val):
54+
return val[0] == '[' and val[-1] == ']' and val[1] != ':'
55+
56+
57+
def get_array(val):
58+
return val[1:-1].split(',')
59+
60+
61+
def is_map(val):
62+
return val[0] == '{' and val[-1] == '}'
63+
64+
65+
def get_map(val):
66+
return json.loads(val)
67+
68+
69+
def value_to_comparable_object(val):
70+
return Value(value_to_object(val))
71+
72+
73+
def value_to_object(val):
74+
val = val.strip()
75+
print("VAL")
76+
print(val)
77+
PATH = '^(<\().*(\)>)$'
78+
NODE = '^(\().*(\))$'
79+
RELATIONSHIP = '^(\[:).*(\])$'
80+
INTEGER = '^(-?[0-9]+)$'
81+
STRING = '^(").*(")$'
82+
NULL = '^null$'
83+
BOOLEAN = '^(false|true)$'
84+
# TEST FLOAT AFTER INT
85+
FLOAT = '^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$'
86+
if re.match(PATH, val):
87+
return get_path(val)[0]
88+
if re.match(RELATIONSHIP, val):
89+
return get_relationship(val)[0]
90+
if re.match(NODE, val):
91+
return get_node(val)[0]
92+
if re.match(NULL, val):
93+
return None
94+
if re.match(BOOLEAN, val):
95+
return bool(val)
96+
if re.match(STRING, val):
97+
return val[1:-1]
98+
if re.match(INTEGER, val):
99+
return int(val)
100+
if re.match(FLOAT, val):
101+
return float(val)
102+
raise TypeError("String value does not match any type. Got: %s" % val)
103+
104+
105+
def get_properties(prop):
106+
split_at = prop.find('{')
107+
if split_at != -1:
108+
n_start, prop = split_two(prop, split_at)
109+
split_at = prop.find('}')
110+
if split_at == -1:
111+
raise ValueError(
112+
"Node properties not correctly representetd. Found starrting '{' but no ending '}' in : %s" % prop)
113+
prop, n_end = split_two(prop, split_at + 1)
114+
n = n_start + n_end
115+
properties = json.loads(prop)
116+
return properties, n
117+
else:
118+
return {}, prop
119+
120+
121+
def get_labels(labels):
122+
labels = labels.split(':')
123+
if len(labels) == 1:
124+
return [], labels[0]
125+
n = labels[0]
126+
labels = labels[1:]
127+
if labels[-1].find(' ') != -1:
128+
labels[-1], n_end = split_two(labels[-1], labels[-1].find(' '))
129+
n += n_end
130+
return labels, n
131+
132+
133+
def get_labels_and_properties(n):
134+
prop, n = get_properties(n)
135+
labels, n = get_labels(n)
136+
return labels, prop, n
137+
138+
139+
def split_two(string_entity, split_at):
140+
return string_entity[:split_at], string_entity[split_at:]
141+
142+
143+
def get_node(string_entity):
144+
if string_entity[0] != "(":
145+
raise ValueError("Excpected node which shuld start with '('. Got: %s" % string_entity[0])
146+
split_at = string_entity.find(')')
147+
if split_at == -1:
148+
raise ValueError("Excpected node which shuld end with ')'. Found no such character in: %s" % string_entity)
149+
n, string_entity = split_two(string_entity, split_at + 1)
150+
n = n[1:-1]
151+
labels, properties, n = get_labels_and_properties(n)
152+
node = Node(labels=labels, properties=properties)
153+
return node, string_entity
154+
155+
156+
def get_relationship(string_entity):
157+
point_up = None
158+
if string_entity[:3] == "<-[":
159+
point_up = False
160+
string_entity = string_entity[3:]
161+
rel = string_entity[:string_entity.find(']-')]
162+
string_entity = string_entity[string_entity.find(']-') + 2:]
163+
elif string_entity[:2] == "-[":
164+
point_up = True
165+
string_entity = string_entity[2:]
166+
rel = string_entity[:string_entity.find(']-')]
167+
string_entity = string_entity[string_entity.find(']->') + 3:]
168+
elif string_entity[0] == "[":
169+
string_entity = string_entity[1:]
170+
rel = string_entity[:string_entity.find(']')]
171+
string_entity = string_entity[string_entity.find(']') + 1:]
172+
else:
173+
raise ValueError("Cant identify relationship from: %s" % string_entity)
174+
type, properties, str = get_labels_and_properties(rel)
175+
if len(type) > 1:
176+
raise ValueError("Relationship can only have one type. Got: %s" % type)
177+
relationship = Relationship(1, 2, type[0], properties=properties)
178+
return relationship, string_entity, point_up
179+
180+
181+
def get_path(string_path):
182+
id = 0
183+
string_path = string_path[1:-1]
184+
n, string_path = get_node(string_path)
185+
list_of_nodes_and_rel = [n]
186+
n.identity = ++id
187+
while string_path != '':
188+
r, string_path, point_up = get_relationship(string_path)
189+
n, string_path = get_node(string_path)
190+
n.identity = ++id
191+
if point_up:
192+
r.start = list_of_nodes_and_rel[-1].identity
193+
r.end = n.identity
194+
r.identity = 0
195+
else:
196+
r.start = n.identity
197+
r.end = list_of_nodes_and_rel[-1].identity
198+
r.identity = 0
199+
list_of_nodes_and_rel.append(r)
200+
list_of_nodes_and_rel.append(n)
201+
path = Path(list_of_nodes_and_rel[0], *list_of_nodes_and_rel[1:])
202+
return path, string_path

0 commit comments

Comments
 (0)