First memgraph tests

Summary: First memgraph tests

Reviewers: buda

Reviewed By: buda

Subscribers: matej.gradicek

Differential Revision: https://phabricator.memgraph.io/D123
This commit is contained in:
Matej Gradiček 2017-03-14 14:37:00 +00:00
parent b87c420dbf
commit 54f14ef788
6 changed files with 106 additions and 43 deletions

View File

@ -9,7 +9,6 @@ neo4j-driver==1.1.2
packaging==16.8
parse==1.8.0
parse-type==0.3.4
pkg-resources==0.0.0
pyparsing==2.2.0
PyYAML==3.12
six==1.10.0

View File

@ -1,37 +1,10 @@
from behave import *
import os
import database
import graph
@given(u'the binary-tree-1 graph')
def step_impl(context):
create_given_graph('binary-tree-1', context)
graph.create_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'
graph.create_graph('binary-tree-2', context)

View File

@ -1,4 +1,4 @@
import database
import database, os
from graph_properties import GraphProperties
from behave import *
@ -12,3 +12,55 @@ def empty_graph_step(context):
def any_graph_step(context):
database.query("MATCH (n) DETACH DELETE n", context)
context.graph_properties.set_beginning_parameters()
@given('graph "{name}"')
def graph_name(context, name):
create_graph(name, context)
def create_graph(name, context):
"""
Function deletes everything from database and creates a new
graph. Graph file name is an argument of function. Function
executes queries written in a .cypher file separated by ';'
and sets graph properties to beginning values.
"""
database.query("MATCH (n) DETACH DELETE n", context)
path = find_graph_path(name, context.config.graphs_root)
q_marks = ["'", '"', '`']
with open(path, 'r') as f:
content = f.read().replace('\n', ' ')
q = ''
in_string = False
i = 0
while i < len(content):
ch = content[i]
if ch == '\\' and i != len(content)-1 and content[i+1] in q_marks:
q += ch + content[i+1]
i += 2
else:
q += ch
if in_string and q_mark == ch:
in_string = False
elif ch in q_marks:
in_string = True
q_mark = ch
if ch == ';' and not in_string:
database.query(q, context)
q = ''
i += 1
if q.strip() != '':
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'

View File

@ -5,17 +5,17 @@ import os
def parse_args():
argp = ArgumentParser(description=__doc__)
argp.add_argument("--root", default="tests/openCypher_M05/tck/features",
argp.add_argument("--root", default="tck_engine/tests/openCypher_M05/tck/features",
help="Path to folder where tests are located, default is openCypher_M05/tck/features.")
argp.add_argument("--graphs-root", default="tests/openCypher_M05/tck/graphs",
argp.add_argument("--graphs-root", default="tck_engine/tests/openCypher_M05/tck/graphs",
help="Path to folder where files with graphs queries are located, default is openCypher_M05/tck/graphs.")
argp.add_argument("--stop", action="store_true", help="Stop testing after first fail.")
argp.add_argument("--no-side-effects", action="store_true", help="Check for side effects in tests.")
argp.add_argument("--database", default="neo4j", choices=["neo4j", "memgraph"], help="Default is neo4j.")
argp.add_argument("--database-username", default="neo4j", help="Default is neo4j.")
argp.add_argument("--database-password", default="memgraph", help="Default is memgraph.")
argp.add_argument("--database-uri", default="bolt://localhost:7687", help="Default is bolt://localhost:7687.")
argp.add_argument("--output-folder", default="results/", help="Test result output folder, default is results/.")
argp.add_argument("--db", default="neo4j", choices=["neo4j", "memgraph"], help="Default is neo4j.")
argp.add_argument("--db-user", default="neo4j", help="Default is neo4j.")
argp.add_argument("--db-pass", default="memgraph", help="Default is memgraph.")
argp.add_argument("--db-uri", default="bolt://localhost:7687", help="Default is bolt://localhost:7687.")
argp.add_argument("--output-folder", default="tck_engine/results/", help="Test result output folder, default is results/.")
argp.add_argument("--logging", default="DEBUG", choices=["INFO", "DEBUG"], help="Logging level, default is DEBUG.")
return argp.parse_args()
@ -47,13 +47,13 @@ def main():
if args.no_side_effects:
behave_options.append("--no-side-effects")
behave_options.append("--database")
behave_options.append(args.database)
behave_options.append(args.db)
behave_options.append("--database-password")
behave_options.append(args.database_password)
behave_options.append(args.db_pass)
behave_options.append("--database-username")
behave_options.append(args.database_username)
behave_options.append(args.db_user)
behave_options.append("--database-uri")
behave_options.append(args.database_uri)
behave_options.append(args.db_uri)
behave_options.append("--graphs-root")
behave_options.append(args.graphs_root)
behave_options.append("--output-folder")

View File

@ -0,0 +1,37 @@
Feature: Test01
Scenario: Create and match with label
Given graph "graph_01"
When executing query:
"""
MATCH (n:Person) RETURN n
"""
Then the result should be:
| n |
| (:Person {age: 20}) |
| (:Person :Student {age: 20}) |
Scenario: Create, match with label and property
Given graph "graph_01"
When executing query:
"""
MATCH (n:Person {age: 20}) RETURN n
"""
Then the result should be:
| n |
| (:Person {age: 20}) |
| (:Person :Student {age: 20}) |
Scenario: Create, match with label and filter property using WHERE
Given graph "graph_01"
When executing query:
"""
MATCH (n:Person) WHERE n.age = 20 RETURN n
"""
Then the result should be:
| n |
| (:Person {age: 20}) |
| (:Person :Student {age: 20}) |

View File

@ -0,0 +1,2 @@
CREATE (n:Person {age: 20});
CREATE (n:Person:Student {age: 20})