TINKERPOP-1784 Added Choose tests to .feature files
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6d2d8355 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6d2d8355 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6d2d8355 Branch: refs/heads/TINKERPOP-1784 Commit: 6d2d835542a022baca0e6042a48e06811e73dfc2 Parents: 4a6772c Author: Stephen Mallette <sp...@genoprime.com> Authored: Wed Oct 11 10:52:15 2017 -0400 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Fri Nov 10 19:55:19 2017 -0500 ---------------------------------------------------------------------- .../src/main/jython/radish/feature_steps.py | 6 +- gremlin-test/features/branch/Choose.feature | 118 +++++++++++++++++++ .../gremlin/process/FeatureCoverageTest.java | 2 + 3 files changed, 124 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6d2d8355/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 68eeeaf..a34bb8d 100644 --- a/gremlin-python/src/main/jython/radish/feature_steps.py +++ b/gremlin-python/src/main/jython/radish/feature_steps.py @@ -25,6 +25,7 @@ from gremlin_python.process.traversal import P, Scope, Column, Order, Direction, from radish import given, when, then from hamcrest import * +regex_and = re.compile(r"([(.,\s])and\(") regex_as = re.compile(r"([(.,\s])as\(") regex_in = re.compile(r"([(.,\s])in\(") regex_is = re.compile(r"([(.,\s])is\(") @@ -66,7 +67,7 @@ def translate_traversal(step): if hasattr(step.context, "traversal_params"): b.update(step.context.traversal_params) - print __translate(step.text) + print __translate(step.text + " - " + str(b)) step.context.traversal = eval(__translate(step.text), b) @@ -118,7 +119,7 @@ def __convert(val, ctx): 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) - elif isinstance(val, str) and re.match("^c\[.*\]$", val): # parse lambda + elif isinstance(val, str) and re.match("^c\[.*\]$", val): # parse lambda/closure return lambda: (val[2:-1], "gremlin-groovy") else: return val @@ -145,6 +146,7 @@ def __table_assertion(data, result, ctx, ordered): def __translate(traversal): replaced = traversal.replace("\n", "") + replaced = regex_and.sub(r"\1and_(", replaced) replaced = regex_as.sub(r"\1as_(", replaced) replaced = regex_is.sub(r"\1is_(", replaced) return regex_in.sub(r"\1in_(", replaced) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6d2d8355/gremlin-test/features/branch/Choose.feature ---------------------------------------------------------------------- diff --git a/gremlin-test/features/branch/Choose.feature b/gremlin-test/features/branch/Choose.feature new file mode 100644 index 0000000..de70485 --- /dev/null +++ b/gremlin-test/features/branch/Choose.feature @@ -0,0 +1,118 @@ +# 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_V_chooseXout_countX_optionX2L__nameX_optionX3L__valueMapX + Given the modern graph + And the traversal of + """ + g.V().choose(__.out().count()). + option(2L, __.values("name")). + option(3L, __.valueMap()) + """ + When iterated to list + Then the result should be unordered + | m[{"name":["marko"], "age":[29]}] | + | josh | + + Scenario: g_V_chooseXlabel_eqXpersonX__outXknowsX__inXcreatedXX_name + Given the modern graph + And using the parameter l1 is "c[it.label() == 'person']" + And the traversal of + """ + g.V().choose(l1, __.out("knows"), __.in("created")).values("name") + """ + When iterated to list + Then the result should be unordered + | josh | + | vadas | + | josh | + | josh | + | marko | + | peter | + + Scenario: g_V_chooseXhasLabelXpersonX_and_outXcreatedX__outXknowsX__identityX_name + Given the modern graph + And the traversal of + """ + g.V().choose(__.hasLabel("person").and().out("created"), + __.out("knows"), + __.identity()). + values("name") + """ + When iterated to list + Then the result should be unordered + | lop | + | ripple | + | josh | + | vadas | + | vadas | + + Scenario: g_V_chooseXlabelX_optionXblah__outXknowsXX_optionXbleep__outXcreatedXX_optionXnone__identityX_name + Given the modern graph + And the traversal of + """ + g.V().choose(__.label()). + option("blah", __.out("knows")). + option("bleep", __.out("created")). + option(Pick.none, __.identity()). + values("name") + """ + When iterated to list + Then the result should be unordered + | marko | + | vadas | + | peter | + | josh | + | lop | + | ripple | + + Scenario: g_V_chooseXoutXknowsX_count_isXgtX0XX__outXknowsXX_name + Given the modern graph + And the traversal of + """ + g.V().choose(__.out("knows").count().is(P.gt(0)), + __.out("knows")). + values("name") + """ + When iterated to list + Then the result should be unordered + | vadas | + | josh | + | vadas | + | josh | + | peter | + | lop | + | ripple | + + Scenario: g_V_hasLabelXpersonX_asXp1X_chooseXoutEXknowsX__outXknowsXX_asXp2X_selectXp1_p2X_byXnameX + Given the modern graph + And the traversal of + """ + g.V().hasLabel("person").as("p1"). + choose(__.outE("knows"), __.out("knows")).as("p2"). + select("p1", "p2"). + by("name") + """ + When iterated to list + Then the result should be unordered + | m[{"p1":"marko", "p2":"vadas"}] | + | m[{"p1":"marko", "p2":"josh"}] | + | m[{"p1":"vadas", "p2":"vadas"}] | + | m[{"p1":"josh", "p2":"josh"}] | + | m[{"p1":"peter", "p2":"peter"}] | http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6d2d8355/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 be01613..4ee540e 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 @@ -19,6 +19,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.filter.CoinTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexTest; @@ -58,6 +59,7 @@ public class FeatureCoverageTest { // TEMPORARY while test framework is under development - all tests should ultimately be included final List<Class<?>> temp = Arrays.asList( BranchTest.class, + ChooseTest.class, CoinTest.class, CountTest.class, GroupCountTest.class,