You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/09/27 17:42:40 UTC
[34/35] tinkerpop git commit: TINKERPOP-1784 Initial implementation
of a new language agnostic test suite
TINKERPOP-1784 Initial implementation of a new language agnostic test suite
Uses Gherkin to write test specifications that will be implemented by the various GLVs. Provided a basic implementation for gremlin-python.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/8286387c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/8286387c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/8286387c
Branch: refs/heads/TINKERPOP-1784
Commit: 8286387ce065035e515cbf4eab3673f94d160782
Parents: eb2585b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Sep 14 15:44:32 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Sep 27 13:41:50 2017 -0400
----------------------------------------------------------------------
gremlin-python/pom.xml | 19 +++++++
.../main/jython/radish/count_features_step.py | 59 ++++++++++++++++++++
.../src/main/jython/radish/terrain.py | 31 ++++++++++
gremlin-python/src/main/jython/setup.py | 3 +-
gremlin-test/features/Count.feature | 54 ++++++++++++++++++
5 files changed, 165 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8286387c/gremlin-python/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-python/pom.xml b/gremlin-python/pom.xml
index 379a114..4ab5f37 100644
--- a/gremlin-python/pom.xml
+++ b/gremlin-python/pom.xml
@@ -341,6 +341,10 @@ limitations under the License.
failonerror="true">
<arg line="install wheel"/>
</exec>
+ <exec dir="${project.build.directory}/python2" executable="env/bin/pip"
+ failonerror="true">
+ <arg line="install radish-bdd"/>
+ </exec>
<exec dir="${project.build.directory}/python3" executable="virtualenv"
failonerror="true">
<arg line="--python=python3 env"/>
@@ -349,6 +353,10 @@ limitations under the License.
failonerror="true">
<arg line="install wheel"/>
</exec>
+ <exec dir="${project.build.directory}/python3" executable="env/bin/pip"
+ failonerror="true">
+ <arg line="install radish-bdd"/>
+ </exec>
<exec dir="${project.build.directory}/python-packaged" executable="virtualenv"
failonerror="true">
<arg line="--python=python3 env"/>
@@ -438,6 +446,17 @@ limitations under the License.
<env key="PYTHONPATH" value=""/>
<arg line="setup.py test"/>
</exec>
+ <!-- radish seems to like all dependencies in place -->
+ <exec executable="env/bin/python" dir="${project.build.directory}/python2"
+ failonerror="true">
+ <env key="PYTHONPATH" value=""/>
+ <arg line="setup.py install"/>
+ </exec>
+ <exec executable="env/bin/radish" dir="${project.build.directory}/python2"
+ failonerror="true">
+ <env key="PYTHONPATH" value=""/>
+ <arg line="-b ${project.build.directory}/python2/radish ${project.basedir}/../gremlin-test/features/"/>
+ </exec>
</target>
</configuration>
</execution>
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8286387c/gremlin-python/src/main/jython/radish/count_features_step.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/radish/count_features_step.py b/gremlin-python/src/main/jython/radish/count_features_step.py
new file mode 100644
index 0000000..324c29c
--- /dev/null
+++ b/gremlin-python/src/main/jython/radish/count_features_step.py
@@ -0,0 +1,59 @@
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+'''
+
+from gremlin_python.structure.graph import Graph
+from gremlin_python.process.graph_traversal import __
+from gremlin_python.process.traversal import Scope
+from radish import before, given, when, then
+
+out = __.out
+
+
+@given("the {graphName:w} graph")
+def choose_graph(step, graphName):
+ # only have modern atm but graphName would be used to select the right one
+ step.context.g = Graph().traversal().withRemote(step.context.remote_conn_modern)
+
+
+@given("the traversal of")
+def translate_traversal(step):
+ g = step.context.g
+ if step.text == "g.V().count()":
+ step.context.traversal = g.V().count()
+ elif step.text == "g.V().both().both().count()":
+ step.context.traversal = g.V().both().both().count()
+ elif step.text == "g.V().fold().count(Scope.local)":
+ step.context.traversal = g.V().fold().count(Scope.local)
+ elif step.text == "g.V().has(\"no\").count()":
+ step.context.traversal = g.V().has("no").count()
+ else:
+ raise ValueError("Gremlin translation to python not found - missing: " + step.text)
+
+
+@when("iterating")
+def iterate_the_traversal(step):
+ step.context.result = step.context.traversal.toList()
+
+
+@then("the result should be {number:d}")
+def assert_single_result_of_number(step, number):
+ assert len(step.context.result) == 1
+ assert step.context.result[0] == number
+
+
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8286387c/gremlin-python/src/main/jython/radish/terrain.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/radish/terrain.py b/gremlin-python/src/main/jython/radish/terrain.py
new file mode 100644
index 0000000..389f39c
--- /dev/null
+++ b/gremlin-python/src/main/jython/radish/terrain.py
@@ -0,0 +1,31 @@
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+'''
+
+from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
+from radish import before, after
+
+
+@before.each_scenario
+def prepare_traversal_source(scenario):
+ scenario.context.remote_conn_modern = DriverRemoteConnection('ws://localhost:45940/gremlin', 'g')
+
+
+@after.each_scenario
+def close_traversal_source(scenario):
+ scenario.context.remote_conn_modern.close()
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8286387c/gremlin-python/src/main/jython/setup.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/setup.py b/gremlin-python/src/main/jython/setup.py
index e6ab493..fddd7c8 100644
--- a/gremlin-python/src/main/jython/setup.py
+++ b/gremlin-python/src/main/jython/setup.py
@@ -70,7 +70,8 @@ setup(
],
tests_require=[
'pytest',
- 'mock'
+ 'mock',
+ 'radish-bdd'
],
install_requires=install_requires,
classifiers=[
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8286387c/gremlin-test/features/Count.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/Count.feature b/gremlin-test/features/Count.feature
new file mode 100644
index 0000000..383eecf
--- /dev/null
+++ b/gremlin-test/features/Count.feature
@@ -0,0 +1,54 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+Feature: Count Step
+
+ Scenario: Count all vertices
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().count()
+ """
+ When iterating
+ Then the result should be 6
+
+ Scenario: Count vertices after traversing both() twice
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().both().both().count()
+ """
+ When iterating
+ Then the result should be 30
+
+ Scenario: Count local
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().fold().count(Scope.local)
+ """
+ When iterating
+ Then the result should be 6
+
+ Scenario: Count no vertices
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().has("no").count()
+ """
+ When iterating
+ Then the result should be 0
\ No newline at end of file