memgraph/tck_engine/steps/binary_tree.py
Matej Gradiček ea615a13b4 tck engine first implementation
Summary: tck engine first implementation

Reviewers: dgleich, teon.banek, buda, mferencevic

Reviewed By: buda, mferencevic

Subscribers: buda

Differential Revision: https://phabricator.memgraph.io/D95
2017-03-14 09:20:08 +00:00

38 lines
1.2 KiB
Python

from behave import *
import os
import database
@given(u'the binary-tree-1 graph')
def step_impl(context):
create_given_graph('binary-tree-1', context)
@given(u'the binary-tree-2 graph')
def step_impl(context):
create_given_graph('binary-tree-2', context)
def create_given_graph(name, context):
"""
Function deletes everything from database and creates a new
graph. Graph file name is an argument of function. Function
executes query written in a .cypher file and sets graph
properties to beginning values.
"""
database.query("MATCH (n) DETACH DELETE n", context)
path = find_graph_path(name, context.config.graphs_root)
with open(path, 'r') as f:
#TODO not good solution for all queries
q = f.read().replace('\n', ' ')
database.query(q, context)
context.graph_properties.set_beginning_parameters()
def find_graph_path(name, path):
"""
Function returns path to .cypher file with given name in
given folder or subfolders. Argument path is path to a given
folder.
"""
for root, dirs, files in os.walk(path):
if name + '.cypher' in files:
return root + '/' + name + '.cypher'