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/10/11 18:06:30 UTC
tinkerpop git commit: TINKERPOP-1784 Added tests for optional() and
Path object assertion
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1784 d18b7c7c7 -> cf155f41b
TINKERPOP-1784 Added tests for optional() and Path object assertion
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/cf155f41
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/cf155f41
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/cf155f41
Branch: refs/heads/TINKERPOP-1784
Commit: cf155f41b45e93d7606f4ee89db1165c4f5aa704
Parents: d18b7c7
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Oct 11 14:05:54 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Oct 11 14:05:54 2017 -0400
----------------------------------------------------------------------
gremlin-python/pom.xml | 2 +-
.../src/main/jython/radish/feature_steps.py | 33 +++++----
gremlin-test/features/branch/Optional.feature | 77 ++++++++++++++++++++
.../traversal/step/branch/OptionalTest.java | 4 +-
.../gremlin/process/FeatureCoverageTest.java | 2 +
5 files changed, 101 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf155f41/gremlin-python/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-python/pom.xml b/gremlin-python/pom.xml
index 1833233..a6cede6 100644
--- a/gremlin-python/pom.xml
+++ b/gremlin-python/pom.xml
@@ -447,7 +447,7 @@ limitations under the License.
<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/"/> <!-- -no-line-jump -->
+ <arg line="-e -t -b ${project.build.directory}/python2/radish ${project.basedir}/../gremlin-test/features/"/> <!-- -no-line-jump -->
</exec>
</target>
</configuration>
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf155f41/gremlin-python/src/main/jython/radish/feature_steps.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/radish/feature_steps.py b/gremlin-python/src/main/jython/radish/feature_steps.py
index a34bb8d..1876f5b 100644
--- a/gremlin-python/src/main/jython/radish/feature_steps.py
+++ b/gremlin-python/src/main/jython/radish/feature_steps.py
@@ -19,7 +19,7 @@ under the License.
import json
import re
-from gremlin_python.structure.graph import Graph
+from gremlin_python.structure.graph import Graph, Path
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.traversal import P, Scope, Column, Order, Direction, T, Pick
from radish import given, when, then
@@ -48,7 +48,7 @@ def add_parameter(step, param_name, param):
if not hasattr(step.context, "traversal_params"):
step.context.traversal_params = {}
- step.context.traversal_params[param_name] = __convert(param, step.context)
+ step.context.traversal_params[param_name] = _convert(param, step.context)
@given("the traversal of")
@@ -67,8 +67,8 @@ def translate_traversal(step):
if hasattr(step.context, "traversal_params"):
b.update(step.context.traversal_params)
- print __translate(step.text + " - " + str(b))
- step.context.traversal = eval(__translate(step.text), b)
+ print _translate(step.text + " - " + str(b))
+ step.context.traversal = eval(_translate(step.text), b)
@when("iterated to list")
@@ -81,9 +81,9 @@ def assert_result(step, characterized_as):
if characterized_as == "empty":
assert_that(len(step.context.result), equal_to(0))
elif characterized_as == "ordered":
- __table_assertion(step.table, step.context.result, step.context, True)
+ _table_assertion(step.table, step.context.result, step.context, True)
elif characterized_as == "unordered":
- __table_assertion(step.table, step.context.result, step.context, False)
+ _table_assertion(step.table, step.context.result, step.context, False)
else:
raise ValueError("unknown data characterization of " + characterized_as)
@@ -93,16 +93,16 @@ def nothing_happening(step):
return
-def __convert(val, ctx):
+def _convert(val, ctx):
if isinstance(val, dict): # convert dictionary keys/values
n = {}
for key, value in val.items():
- n[__convert(key, ctx)] = __convert(value, ctx)
+ n[_convert(key, ctx)] = _convert(value, ctx)
return n
elif isinstance(val, unicode): # stupid unicode/string nonsense in py 2/x
- return __convert(val.encode('utf-8'), ctx)
+ return _convert(val.encode('utf-8'), ctx)
elif isinstance(val, str) and re.match("^l\[.*\]$", val): # parse list
- return list(map((lambda x: __convert(x, ctx)), val[2:-1].split(",")))
+ return list(map((lambda x: _convert(x, ctx)), val[2:-1].split(",")))
elif isinstance(val, str) and re.match("^d\[.*\]$", val): # parse numeric
return long(val[2:-1])
elif isinstance(val, str) and re.match("^v\[.*\]\.id$", val): # parse vertex id
@@ -118,14 +118,18 @@ def __convert(val, ctx):
elif isinstance(val, str) and re.match("^e\[.*\]$", val): # parse edge
return ctx.lookup_e["modern"][val[2:-1]]
elif isinstance(val, str) and re.match("^m\[.*\]$", val): # parse json as a map
- return __convert(json.loads(val[2:-1]), ctx)
+ return _convert(json.loads(val[2:-1]), ctx)
+ elif isinstance(val, str) and re.match("^p\[.*\]$", val): # parse path
+ path_objects = list(map((lambda x: _convert(x, ctx)), val[2:-1].split(",")))
+ labels = [set([]) for i in range(len(path_objects))]
+ return Path(labels, path_objects)
elif isinstance(val, str) and re.match("^c\[.*\]$", val): # parse lambda/closure
return lambda: (val[2:-1], "gremlin-groovy")
else:
return val
-def __table_assertion(data, result, ctx, ordered):
+def _table_assertion(data, result, ctx, ordered):
# results from traversal should have the same number of entries as the feature data table
assert_that(len(result), equal_to(len(data)))
@@ -134,17 +138,18 @@ def __table_assertion(data, result, ctx, ordered):
# finds a match in the results for each line of data to assert and then removes that item
# from the list - in the end there should be no items left over and each will have been asserted
for ix, line in enumerate(data):
- val = __convert(line[0], ctx)
+ val = _convert(line[0], ctx)
if ordered:
assert_that(results_to_test[ix], equal_to(val))
else:
+ print str(type(val)) + "---------" + str(type(results_to_test[0]))
assert_that(val, is_in(results_to_test))
results_to_test.remove(val)
assert_that(len(results_to_test), is_(0))
-def __translate(traversal):
+def _translate(traversal):
replaced = traversal.replace("\n", "")
replaced = regex_and.sub(r"\1and_(", replaced)
replaced = regex_as.sub(r"\1as_(", replaced)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf155f41/gremlin-test/features/branch/Optional.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/branch/Optional.feature b/gremlin-test/features/branch/Optional.feature
new file mode 100644
index 0000000..ebd0de2
--- /dev/null
+++ b/gremlin-test/features/branch/Optional.feature
@@ -0,0 +1,77 @@
+# 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: Step - choose()
+
+ Scenario: g_VX2X_optionalXoutXknowsXX
+ Given the modern graph
+ And using the parameter v2Id is "v[vadas].id"
+ And the traversal of
+ """
+ g.V(v2Id).optional(__.out("knows"))
+ """
+ When iterated to list
+ Then the result should be unordered
+ | v[vadas] |
+
+ Scenario: g_VX2X_optionalXinXknowsXX
+ Given the modern graph
+ And using the parameter v2Id is "v[vadas].id"
+ And the traversal of
+ """
+ g.V(v2Id).optional(__.in("knows"))
+ """
+ When iterated to list
+ Then the result should be unordered
+ | v[marko] |
+
+ Scenario: g_V_hasLabelXpersonX_optionalXoutXknowsX_optionalXoutXcreatedXXX_path
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().hasLabel("person").
+ optional(__.out("knows").
+ optional(__.out("created"))).
+ path()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | p[v[marko],v[vadas]] |
+ | p[v[marko],v[josh],v[ripple]] |
+ | p[v[marko],v[josh],v[lop]] |
+ | p[v[vadas]] |
+ | p[v[josh]] |
+ | p[v[peter]] |
+
+ Scenario: g_V_optionalXout_optionalXoutXX_path
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().optional(__.out().optional(__.out())).path()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | p[v[marko],v[lop]] |
+ | p[v[marko],v[vadas]] |
+ | p[v[marko],v[josh],v[ripple]] |
+ | p[v[marko],v[josh],v[lop]] |
+ | p[v[vadas]] |
+ | p[v[lop]] |
+ | p[v[josh],v[ripple]] |
+ | p[v[josh],v[lop]] |
+ | p[v[ripple]] |
+ | p[v[peter],v[lop]] |
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf155f41/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalTest.java
index 660af6c..403c413 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalTest.java
@@ -125,12 +125,12 @@ public abstract class OptionalTest extends AbstractGremlinProcessTest {
public static class Traversals extends OptionalTest {
@Override
- public Traversal<Vertex, Vertex> get_g_VX2X_optionalXoutXknowsXX(Object v2Id) {
+ public Traversal<Vertex, Vertex> get_g_VX2X_optionalXoutXknowsXX(final Object v2Id) {
return this.g.V(v2Id).optional(out("knows"));
}
@Override
- public Traversal<Vertex, Vertex> get_g_VX2X_optionalXinXknowsXX(Object v2Id) {
+ public Traversal<Vertex, Vertex> get_g_VX2X_optionalXinXknowsXX(final Object v2Id) {
return this.g.V(v2Id).optional(in("knows"));
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cf155f41/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/FeatureCoverageTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/FeatureCoverageTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/FeatureCoverageTest.java
index 4ee540e..1ac9ed8 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/FeatureCoverageTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/FeatureCoverageTest.java
@@ -20,6 +20,7 @@ package org.apache.tinkerpop.gremlin.process;
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.BranchTest;
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseTest;
+import org.apache.tinkerpop.gremlin.process.traversal.step.branch.OptionalTest;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.CoinTest;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountTest;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexTest;
@@ -60,6 +61,7 @@ public class FeatureCoverageTest {
final List<Class<?>> temp = Arrays.asList(
BranchTest.class,
ChooseTest.class,
+ OptionalTest.class,
CoinTest.class,
CountTest.class,
GroupCountTest.class,