TINKERPOP-1784 Provided translation for python specific syntax

Included a way to specify element identifiers in feature files.


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

Branch: refs/heads/TINKERPOP-1784
Commit: 6c60bd1a7cf52c353961ec4f3cfa3e52675cf1c5
Parents: 30422e7
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Sep 27 12:16:08 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Oct 3 14:19:52 2017 -0400

----------------------------------------------------------------------
 .../src/main/jython/radish/feature_steps.py        | 17 +++++++++++++----
 gremlin-test/features/filter/Has.feature           | 13 +++++++++++++
 gremlin-test/features/map/Select.feature           |  2 +-
 3 files changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c60bd1a/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 8ef0f1b..989e781 100644
--- a/gremlin-python/src/main/jython/radish/feature_steps.py
+++ b/gremlin-python/src/main/jython/radish/feature_steps.py
@@ -25,6 +25,8 @@ from gremlin_python.process.traversal import P, Scope, Column
 from radish import given, when, then
 from hamcrest import *
 
+regex_as = re.compile(r"\.as\(")
+regex_in = re.compile(r"\.in\(")
 
 @given("the {graph_name:w} graph")
 def choose_graph(step, graph_name):
@@ -52,7 +54,7 @@ def translate_traversal(step):
     if hasattr(step.context, "traversal_params"):
         b.update(step.context.traversal_params)
 
-    step.context.traversal = eval(step.text, b)
+    step.context.traversal = eval(__translate(step.text), b)
 
 
 @when("iterated to list")
@@ -78,9 +80,11 @@ def __convert(val, ctx):
         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):
+    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):
+    elif isinstance(val, (str, unicode)) and re.match("^v\[.*\]\.id$", val):
+        return ctx.lookup["modern"][val[2:-4]].id
+    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')
@@ -141,4 +145,9 @@ def __unordered_assertion(step):
         else:
             raise ValueError("unknown type of " + line[0])
 
-    assert_that(len(results_to_test), is_(0))
\ No newline at end of file
+    assert_that(len(results_to_test), is_(0))
+
+
+def __translate(traversal):
+    replaced = regex_as.sub(".as_(", traversal)
+    return regex_in.sub(".in_(", replaced)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c60bd1a/gremlin-test/features/filter/Has.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/filter/Has.feature 
b/gremlin-test/features/filter/Has.feature
index 0bb82e0..4a2e085 100644
--- a/gremlin-test/features/filter/Has.feature
+++ b/gremlin-test/features/filter/Has.feature
@@ -28,3 +28,16 @@ Feature: Step - has()
       | vertex | josh   |
       | vertex | peter  |
 
+  Scenario: Use hasId() with P
+    Given the modern graph
+    And using the parameter v1 is "v[marko].id"
+    And the traversal of
+    """
+    g.V().in().hasId(P.neq(v1))
+    """
+    When iterated to list
+    Then the result should be unordered
+      | vertex | josh   |
+      | vertex | josh   |
+      | vertex | peter  |
+

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c60bd1a/gremlin-test/features/map/Select.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/map/Select.feature 
b/gremlin-test/features/map/Select.feature
index e64417a..b2d208c 100644
--- a/gremlin-test/features/map/Select.feature
+++ b/gremlin-test/features/map/Select.feature
@@ -22,7 +22,7 @@ Feature: Step - select()
     And using the parameter v1 is "v[marko]"
     And the traversal of
       """
-      g.V(v1).as_("a").out("knows").as_("b").select("a", "b")
+      g.V(v1).as("a").out("knows").as("b").select("a", "b")
       """
     When iterated to list
     Then the result should be unordered

Reply via email to