New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL generation scripts for snapshot tests DB #105
Merged
Merged
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1311ac8
SQL generation scripts for snapshot tests DB (#87)
amartyashankha 00d7eed
Fixing snapshots and compiler output
17272df
Adding copyright lines
7a7a00b
Changed commands file
163bc60
Adding docker-compose down to travis
7e4239d
Adding docker-compose commands to travis
293293a
changing coveragerc
e796892
Fixing travis and docker-compose
12804be
Fixed function name
79af4d4
FIxing copyright
1d0cc41
Adding version reading to generate_test_sql
8a3613f
Renamed data loading file and function.
1f378d5
Adding error message on DB setup.
a7fcee2
Merging duplicate scripts directories.
0fa0917
Fixing lint errors
675dfbc
Removing getcwd
387ef44
Removing sinatra XD
7c1f807
Updated coveragerc
434f3c2
Addressing comments
e47ed53
Merge branch 'master' into feat_snapshot_tests
obi1kenobi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: '3' | ||
services: | ||
orientdb: | ||
image: orientdb:2.2.30 | ||
command: server.sh | ||
ports: | ||
- "127.0.0.1:2480:2480" | ||
- "127.0.0.1:2424:2424" | ||
environment: | ||
ORIENTDB_ROOT_PASSWORD: root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2018-present Kensho Technologies, LLC. | ||
import sys | ||
import time | ||
|
||
import pytest | ||
|
||
from .test_data_tools.graph import get_test_graph | ||
|
||
|
||
# Pytest fixtures depend on name redefinitions to work, | ||
# so this check generates tons of false-positives here. | ||
# pylint: disable=redefined-outer-name | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def init_graph(): | ||
"""Return a client for an initialized db, with all test data imported.""" | ||
graph_name = 'animals' | ||
|
||
# Try to set up the database for the test up to 20 times before giving up. | ||
set_up_successfully = False | ||
for _ in range(20): | ||
try: | ||
graph_client = get_test_graph(graph_name) | ||
set_up_successfully = True | ||
break | ||
except Exception as e: # pylint: disable=broad-except | ||
sys.stderr.write(u'Failed to set up test DB: {}'.format(e)) | ||
time.sleep(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. log the exception |
||
|
||
if not set_up_successfully: | ||
raise AssertionError(u'Failed to set up database without raising an exception!') | ||
|
||
return graph_client | ||
|
||
|
||
@pytest.fixture(scope='class') | ||
def graph_client(request, init_graph): | ||
"""Get a client for an initialized db, with all test data imported.""" | ||
request.cls.graph_client = init_graph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Copyright 2018-present Kensho Technologies, LLC. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Copyright 2018-present Kensho Technologies, LLC. |
23 changes: 23 additions & 0 deletions
23
graphql_compiler/tests/snapshot_tests/snapshots/snap_test_orientdb_match_query.py
Large diffs are not rendered by default.
Oops, something went wrong.
125 changes: 125 additions & 0 deletions
125
graphql_compiler/tests/snapshot_tests/test_orientdb_match_query.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# Copyright 2018-present Kensho Technologies, LLC. | ||
from collections import Counter | ||
|
||
import pytest | ||
import six | ||
from snapshottest import TestCase | ||
|
||
from .. import test_input_data | ||
from ... import graphql_to_match | ||
from ..test_helpers import get_schema | ||
|
||
|
||
def execute_graphql(schema, test_data, client, sample_parameters): | ||
"""Compile the GraphQL query to MATCH, execute it agains the test_db, and return the results.""" | ||
if test_data.type_equivalence_hints: | ||
# For test convenience, we accept the type equivalence hints in string form. | ||
# Here, we convert them to the required GraphQL types. | ||
schema_based_type_equivalence_hints = { | ||
schema.get_type(key): schema.get_type(value) | ||
for key, value in six.iteritems(test_data.type_equivalence_hints) | ||
} | ||
else: | ||
schema_based_type_equivalence_hints = None | ||
|
||
result = graphql_to_match(schema, test_data.graphql_input, sample_parameters, | ||
type_equivalence_hints=schema_based_type_equivalence_hints) | ||
|
||
# We need to preprocess the results to be agnostic of the returned order. | ||
# For this we perform the following steps | ||
# - convert lists (returned from @fold scopes) to tuples to make them hashable | ||
# - convert each row dict to a frozenset of its items | ||
# - create a Counter (multi-set) of the row frozensets | ||
# - convert the multi-set to a frozenset of its items | ||
row_dicts = [row.oRecordData for row in client.command(result.query)] | ||
row_dicts_using_tuples = [ | ||
{ | ||
column_name: tuple(value) if isinstance(value, list) else value | ||
for column_name, value in row.items() | ||
} | ||
for row in row_dicts | ||
] | ||
row_frozensets = [frozenset(row_dict.items()) for row_dict in row_dicts_using_tuples] | ||
rows_multiset = Counter(row_frozensets) | ||
row_counters_frozenset = frozenset(rows_multiset.items()) | ||
|
||
return row_counters_frozenset | ||
|
||
|
||
# The following TestCase class uses the 'graph_client' fixture | ||
# which pylint does not recognize as a class member. | ||
# pylint: disable=no-member | ||
|
||
|
||
class OrientDBMatchQueryTests(TestCase): | ||
|
||
def setUp(self): | ||
"""Initialize the test schema once for all tests, and disable max diff limits.""" | ||
self.maxDiff = None | ||
self.schema = get_schema() | ||
|
||
@pytest.mark.usefixtures('graph_client') | ||
def test_immediate_output(self): | ||
test_data = test_input_data.immediate_output() | ||
sample_parameters = {} | ||
|
||
rows = execute_graphql(self.schema, test_data, self.graph_client, sample_parameters) | ||
|
||
self.assertMatchSnapshot(rows) | ||
|
||
@pytest.mark.usefixtures('graph_client') | ||
def test_traverse_and_output(self): | ||
test_data = test_input_data.traverse_and_output() | ||
sample_parameters = {} | ||
|
||
rows = execute_graphql(self.schema, test_data, self.graph_client, sample_parameters) | ||
|
||
self.assertMatchSnapshot(rows) | ||
|
||
@pytest.mark.usefixtures('graph_client') | ||
def test_traverse_filter_and_output(self): | ||
test_data = test_input_data.traverse_filter_and_output() | ||
sample_parameters = {'wanted': 'Nazgul__2'} | ||
|
||
rows = execute_graphql(self.schema, test_data, self.graph_client, sample_parameters) | ||
|
||
self.assertMatchSnapshot(rows) | ||
|
||
@pytest.mark.usefixtures('graph_client') | ||
def test_filter_in_optional_block(self): | ||
test_data = test_input_data.filter_in_optional_block() | ||
sample_parameters = {'name': 'Nazgul__2'} | ||
|
||
rows = execute_graphql(self.schema, test_data, self.graph_client, sample_parameters) | ||
|
||
self.assertMatchSnapshot(rows) | ||
|
||
@pytest.mark.usefixtures('graph_client') | ||
def test_optional_traverse_after_mandatory_traverse(self): | ||
test_data = test_input_data.optional_traverse_after_mandatory_traverse() | ||
sample_parameters = {} | ||
|
||
rows = execute_graphql(self.schema, test_data, self.graph_client, sample_parameters) | ||
|
||
self.assertMatchSnapshot(rows) | ||
|
||
@pytest.mark.usefixtures('graph_client') | ||
def test_optional_and_deep_traverse(self): | ||
test_data = test_input_data.optional_and_deep_traverse() | ||
sample_parameters = {} | ||
|
||
rows = execute_graphql(self.schema, test_data, self.graph_client, sample_parameters) | ||
|
||
self.assertMatchSnapshot(rows) | ||
|
||
@pytest.mark.usefixtures('graph_client') | ||
def test_fold_on_output_variable(self): | ||
test_data = test_input_data.fold_on_output_variable() | ||
sample_parameters = {} | ||
|
||
rows = execute_graphql(self.schema, test_data, self.graph_client, sample_parameters) | ||
|
||
self.assertMatchSnapshot(rows) | ||
|
||
|
||
# pylint: enable=no-member |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Copyright 2018-present Kensho Technologies, LLC. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This path doesn't exist anymore.