|
| 1 | +from collections import deque |
| 2 | + |
| 3 | +from behave import * |
| 4 | + |
| 5 | +from neo4j.v1 import Path, Relationship |
| 6 | +from test.tck.tck_util import send_string |
| 7 | + |
| 8 | +use_step_matcher("re") |
| 9 | + |
| 10 | + |
| 11 | +@step("`(?P<key>.+)` is single value result of: (?P<statement>.+)") |
| 12 | +def step_impl(context, key, statement): |
| 13 | + records = list(send_string(statement).stream()) |
| 14 | + assert len(records) == 1 |
| 15 | + assert len(records[0]) == 1 |
| 16 | + context.values[key] = records[0][0] |
| 17 | + |
| 18 | + |
| 19 | +@step("`(?P<key1>.+)` is a copy of `(?P<key2>.+)` path with flipped relationship direction") |
| 20 | +def step_impl(context, key1, key2): |
| 21 | + path = context.values[key2] |
| 22 | + nodes = path.nodes |
| 23 | + new_relationships = [] |
| 24 | + for r in path.relationships: |
| 25 | + start = r.end |
| 26 | + end = r.start |
| 27 | + tmp_r = Relationship(start, end, r.type, r.properties) |
| 28 | + tmp_r.identity = r.identity |
| 29 | + new_relationships.append(tmp_r) |
| 30 | + entities = [nodes[0]] |
| 31 | + for i in range(1,len(nodes)): |
| 32 | + entities.append(new_relationships[i-1]) |
| 33 | + entities.append(nodes[i]) |
| 34 | + |
| 35 | + context.values[key1] = Path(*entities) |
| 36 | + |
| 37 | + |
| 38 | +@step("saved values should all equal") |
| 39 | +def step_impl(context): |
| 40 | + values = context.values.values() |
| 41 | + assert len(values) > 1 |
| 42 | + first_val = values.pop() |
| 43 | + for item in values: |
| 44 | + assert item == first_val |
| 45 | + |
| 46 | + |
| 47 | +@step("none of the saved values should be equal") |
| 48 | +def step_impl(context): |
| 49 | + values = context.values.values() |
| 50 | + assert len(values) > 1 |
| 51 | + first_val = values.pop() |
| 52 | + for item in values: |
| 53 | + assert item != first_val |
0 commit comments