1+ from behave import *
2+
3+ from test .tck import tck_util
4+
5+ use_step_matcher ("re" )
6+
7+
8+ @given ("A running database" )
9+ def step_impl (context ):
10+ return None
11+ # check if running
12+
13+
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 )
17+
18+
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' ' )
22+
23+
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 )
27+
28+
29+ @given ("an empty list L" )
30+ def step_impl (context ):
31+ context .L = []
32+
33+
34+ @given ("an empty map M" )
35+ def step_impl (context ):
36+ context .M = {}
37+
38+
39+ @given ("a String of size (?P<size>\d+)" )
40+ def step_impl (context , size ):
41+ context .expected = tck_util .get_random_string (int (size ))
42+
43+
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 )
47+
48+
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 )
52+
53+
54+ @step ("adding a table of lists to the list L" )
55+ def step_impl (context ):
56+ for row in context .table :
57+ context .L .append (tck_util .get_list_from_feature_file (row [1 ], row [0 ]))
58+
59+
60+ @step ("adding a table of values to the list L" )
61+ def step_impl (context ):
62+ for row in context .table :
63+ context .L .append (tck_util .get_bolt_value (row [0 ], row [1 ]))
64+
65+
66+ @step ("adding a table of values to the map M" )
67+ def step_impl (context ):
68+ for row in context .table :
69+ context .M ['a%d' % len (context .M )] = tck_util .get_bolt_value (row [0 ], row [1 ])
70+
71+
72+ @step ("adding map M to list L" )
73+ def step_impl (context ):
74+ context .L .append (context .M )
75+
76+
77+ @when ("adding a table of lists to the map M" )
78+ def step_impl (context ):
79+ for row in context .table :
80+ context .M ['a%d' % len (context .M )] = tck_util .get_list_from_feature_file (row [1 ], row [0 ])
81+
82+
83+ @step ("adding a copy of map M to map M" )
84+ def step_impl (context ):
85+ context .M ['a%d' % len (context .M )] = context .M .copy ()
86+
87+
88+ @when ("the driver asks the server to echo this value back" )
89+ def step_impl (context ):
90+ context .results = {}
91+ context .results ["as_string" ] = tck_util .send_string ("RETURN " + tck_util .as_cypher_text (context .expected ))
92+ context .results ["as_parameters" ] = tck_util .send_parameters ("RETURN {input}" , {'input' : context .expected })
93+
94+
95+ @when ("the driver asks the server to echo this list back" )
96+ def step_impl (context ):
97+ context .expected = context .L
98+ context .results = {}
99+ context .results ["as_string" ] = tck_util .send_string ("RETURN " + tck_util .as_cypher_text (context .expected ))
100+ context .results ["as_parameters" ] = tck_util .send_parameters ("RETURN {input}" , {'input' : context .expected })
101+
102+
103+ @when ("the driver asks the server to echo this map back" )
104+ def step_impl (context ):
105+ context .expected = context .M
106+ context .results = {}
107+ context .results ["as_string" ] = tck_util .send_string ("RETURN " + tck_util .as_cypher_text (context .expected ))
108+ context .results ["as_parameters" ] = tck_util .send_parameters ("RETURN {input}" , {'input' : context .expected })
109+
110+
111+ @then ("the result returned from the server should be a single record with a single value" )
112+ def step_impl (context ):
113+ assert context .results
114+ for result in context .results .values ():
115+ assert len (result ) == 1
116+ assert len (result [0 ]) == 1
117+
118+
119+ @step ("the value given in the result should be the same as what was sent" )
120+ def step_impl (context ):
121+ assert len (context .results ) > 0
122+ for result in context .results .values ():
123+ result_value = result [0 ].values ()[0 ]
124+ assert result_value == context .expected
0 commit comments