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:40 UTC

[27/47] tinkerpop git commit: TINKERPOP-1784 Added test for select in GLV tests

TINKERPOP-1784 Added test for select in GLV tests

Included infrastructure for validating maps and refactored other related code.


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

Branch: refs/heads/TINKERPOP-1784
Commit: 5210453a866a920b2443e0fc7520b61164ec07c0
Parents: 769e8ae
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Sat Sep 23 07:12:07 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Oct 16 11:19:30 2017 -0400

----------------------------------------------------------------------
 .../src/main/jython/radish/feature_steps.py     | 76 ++++++++++++--------
 gremlin-test/features/map/Select.feature        | 30 ++++++++
 2 files changed, 75 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5210453a/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 35103f3..8ef0f1b 100644
--- a/gremlin-python/src/main/jython/radish/feature_steps.py
+++ b/gremlin-python/src/main/jython/radish/feature_steps.py
@@ -32,14 +32,27 @@ def choose_graph(step, graph_name):
     step.context.g = Graph().traversal().withRemote(step.context.remote_conn[graph_name])
 
 
+@given("using the parameter {param_name:w} is {param:QuotedString}")
+def add_parameter(step, param_name, param):
+    if not hasattr(step.context, "traversal_params"):
+        step.context.traversal_params = {}
+
+    step.context.traversal_params[param_name.encode('utf-8')] = __convert(param, step.context)
+
+
 @given("the traversal of")
 def translate_traversal(step):
     g = step.context.g
-    step.context.traversal = eval(step.text, {"g": g,
-                                              "Column": Column,
-                                              "P": P,
-                                              "Scope": Scope,
-                                              "bothE": __.bothE})
+    b = {"g": g,
+         "Column": Column,
+         "P": P,
+         "Scope": Scope,
+         "bothE": __.bothE}
+
+    if hasattr(step.context, "traversal_params"):
+        b.update(step.context.traversal_params)
+
+    step.context.traversal = eval(step.text, b)
 
 
 @when("iterated to list")
@@ -47,18 +60,32 @@ def iterate_the_traversal(step):
     step.context.result = step.context.traversal.toList()
 
 
-def __convert(m, ctx):
-    # transform string map keys from the test spec to numbers when it encounters the appropriate patterns
-    n = {}
-    for key, value in m.items():
-        if re.match("d\[.*\]", key):
-            n[long(key[2:-1])] = value
-        elif re.match("v\[.*\]", key):
-            n[ctx.lookup["modern"][key[2:-1]]] = value
-        else:
-            n[key] = value
+@then("the result should be {characterized_as:w}")
+def assert_result(step, characterized_as):
+    if characterized_as == "empty":
+        assert_that(len(step.context.result), equal_to(0))
+    elif characterized_as == "ordered":
+        __ordered_assertion(step)
+    elif characterized_as == "unordered":
+        __unordered_assertion(step)
+    else:
+        raise ValueError("unknown data characterization of " + characterized_as)
+
 
-    return n
+def __convert(val, ctx):
+    if isinstance(val, dict):
+        n = {}
+        for key, value in val.items():
+            n[__convert(key, ctx)] = __convert(value, ctx)
+        return n
+    elif isinstance(val, (str, unicode)) and re.match("d\[.*\]", val):
+        return long(val[2:-1])
+    elif isinstance(val, (str, unicode)) and re.match("v\[.*\]", val):
+        return ctx.lookup["modern"][val[2:-1]]
+    elif isinstance(val, unicode):
+        return val.encode('utf-8')
+    else:
+        return str(val)
 
 
 def __ordered_assertion(step):
@@ -108,23 +135,10 @@ def __unordered_assertion(step):
             assert_that(v, is_in(results_to_test))
             results_to_test.remove(v)
         elif line[0] == "map":
-            val = __convert(json.load(line[1]), step.context)
+            val = __convert(json.loads(line[1]), step.context)
             assert_that(val, is_in(results_to_test))
             results_to_test.remove(val)
         else:
             raise ValueError("unknown type of " + line[0])
 
-    assert_that(len(results_to_test), is_(0))
-
-    
-@then("the result should be {characterized_as:w}")
-def assert_result(step, characterized_as):
-    if characterized_as == "empty":
-        assert_that(len(step.context.result), equal_to(0))
-    elif characterized_as == "ordered":
-        __ordered_assertion(step)
-    elif characterized_as == "unordered":
-        __unordered_assertion(step)
-    else:
-        raise ValueError("unknown data characterization of " + characterized_as)
-
+    assert_that(len(results_to_test), is_(0))
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5210453a/gremlin-test/features/map/Select.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/map/Select.feature b/gremlin-test/features/map/Select.feature
new file mode 100644
index 0000000..e64417a
--- /dev/null
+++ b/gremlin-test/features/map/Select.feature
@@ -0,0 +1,30 @@
+# 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 - select()
+
+  Scenario: Select vertices
+    Given the modern graph
+    And using the parameter v1 is "v[marko]"
+    And the traversal of
+      """
+      g.V(v1).as_("a").out("knows").as_("b").select("a", "b")
+      """
+    When iterated to list
+    Then the result should be unordered
+      | map | {"a": "v[marko]", "b": "v[vadas]"} |
+      | map | {"a": "v[marko]", "b": "v[josh]"} |
\ No newline at end of file