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/16 15:20:39 UTC

[26/47] tinkerpop git commit: TINKERPOP-1784 Added support for testing branch() with gherkin

TINKERPOP-1784 Added support for testing branch() with gherkin


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/bd5e0282
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/bd5e0282
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/bd5e0282

Branch: refs/heads/TINKERPOP-1784
Commit: bd5e0282b286e21f9a55a5955146ef0549d58faf
Parents: b582a22
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Oct 10 13:17:55 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Oct 16 11:19:30 2017 -0400

----------------------------------------------------------------------
 .../src/main/jython/radish/feature_steps.py     | 12 ++--
 gremlin-test/features/branch/Branch.feature     | 76 ++++++++++++++++++++
 .../gremlin/process/FeatureCoverageTest.java    |  2 +
 3 files changed, 86 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bd5e0282/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 a2efb67..0d52d75 100644
--- a/gremlin-python/src/main/jython/radish/feature_steps.py
+++ b/gremlin-python/src/main/jython/radish/feature_steps.py
@@ -21,7 +21,7 @@ import json
 import re
 from gremlin_python.structure.graph import Graph
 from gremlin_python.process.graph_traversal import __
-from gremlin_python.process.traversal import P, Scope, Column, Order, Direction, T
+from gremlin_python.process.traversal import P, Scope, Column, Order, Direction, T, Pick
 from radish import given, when, then
 from hamcrest import *
 
@@ -58,15 +58,17 @@ def translate_traversal(step):
          "Column": Column,
          "Direction": Direction,
          "Order": Order,
-         "P": P,
-         "gt": P.gt,
+         "P": P, "gt": P.gt,
+         "Pick": Pick, "any": Pick.any,
          "Scope": Scope,
          "T": T,
          "as_": __.as_,
          "bothE": __.bothE,
          "in_": __.in_,
+         "label": __.label,
          "out": __.out,
-         "repeat": __.repeat}
+         "repeat": __.repeat,
+         "values": __.values}
 
     if hasattr(step.context, "traversal_params"):
         b.update(step.context.traversal_params)
@@ -123,6 +125,8 @@ 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
+        return lambda: (val[2:-1], "gremlin-groovy")
     else:
         return val
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bd5e0282/gremlin-test/features/branch/Branch.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/branch/Branch.feature b/gremlin-test/features/branch/Branch.feature
new file mode 100644
index 0000000..d12fc0f
--- /dev/null
+++ b/gremlin-test/features/branch/Branch.feature
@@ -0,0 +1,76 @@
+# 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 - branch()
+
+  Scenario: g_V_branchXlabel_eq_person__a_bX_optionXa__ageX_optionXb__langX_optionXb__nameX
+    Given the modern graph
+    And using the parameter l1 is "c[it.get().label() == 'person' ? 'a' : 'b']"
+    And the traversal of
+      """
+      g.V().branch(l1).option("a", values("age")).option("b", values("lang")).option("b", values("name"))
+      """
+    When iterated to list
+    Then the result should be unordered
+      | java |
+      | java |
+      | lop |
+      | ripple |
+      | d[29] |
+      | d[27] |
+      | d[32] |
+      | d[35] |
+
+  Scenario: g_V_branchXlabel_isXpersonX_countX_optionX1__ageX_optionX0__langX_optionX0__nameX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().branch(label().is("person").count()).option(1L, values("age")).option(0L, values("lang")).option(0L, values("name"))
+      """
+    When iterated to list
+    Then the result should be unordered
+      | java |
+      | java |
+      | lop |
+      | ripple |
+      | d[29] |
+      | d[27] |
+      | d[32] |
+      | d[35] |
+
+  Scenario: g_V_branchXlabel_isXpersonX_countX_optionX1__ageX_optionX0__langX_optionX0__nameX_optionXany__labelX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().branch(label().is("person").count()).option(1L, values("age")).option(0L, values("lang")).option(0L, values("name")).option(any, label())
+      """
+    When iterated to list
+    Then the result should be unordered
+      | java |
+      | java |
+      | lop |
+      | ripple |
+      | d[29] |
+      | d[27] |
+      | d[32] |
+      | d[35] |
+      | person |
+      | person |
+      | person |
+      | person |
+      | software |
+      | software |
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bd5e0282/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 ce66889..be01613 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
@@ -18,6 +18,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.filter.CoinTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexTest;
@@ -56,6 +57,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,
                 CoinTest.class,
                 CountTest.class,
                 GroupCountTest.class,