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 2022/03/25 13:44:30 UTC

[tinkerpop] branch master updated: TINKERPOP-2686 Added VertexProperty assertion support in Python CTR

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/master by this push:
     new 76b2927  TINKERPOP-2686 Added VertexProperty assertion support in Python CTR
76b2927 is described below

commit 76b2927ad885f2c0c31e8dbd4e59a3ae233d690d
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Fri Mar 25 09:43:16 2022 -0400

    TINKERPOP-2686 Added VertexProperty assertion support in Python CTR
---
 .../src/main/python/radish/feature_steps.py        | 19 ++++++++++++++---
 gremlin-python/src/main/python/radish/terrain.py   |  8 ++++++--
 gremlin-python/src/main/python/radish/utils.py     | 24 +++++++++++++++++++++-
 3 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/gremlin-python/src/main/python/radish/feature_steps.py b/gremlin-python/src/main/python/radish/feature_steps.py
index 9e2e745..4a4bc70 100644
--- a/gremlin-python/src/main/python/radish/feature_steps.py
+++ b/gremlin-python/src/main/python/radish/feature_steps.py
@@ -40,7 +40,7 @@ direction = {
     "to": Direction.IN,
 }
 
-ignores = ["g.V().properties().order()"] # need a vertex property parser for result set: https://issues.apache.org/jira/browse/TINKERPOP-2686
+ignores = []
 
 
 @given("the {graph_name:w} graph")
@@ -126,6 +126,7 @@ def next_the_traversal(step):
 def raise_an_error(step):
     assert_that(step.context.failed, equal_to(True))
 
+
 @then("the result should be {characterized_as:w}")
 def assert_result(step, characterized_as):
     if step.context.ignore:
@@ -207,6 +208,8 @@ def _convert(val, ctx):
         return str(__find_cached_element(ctx, graph_name, val[2:-5], "e").id)
     elif isinstance(val, str) and re.match(r"^e\[.*\]$", val):           # parse edge
         return __find_cached_element(ctx, graph_name, val[2:-1], "e")
+    elif isinstance(val, str) and re.match(r"^vp\[.*\]$", val):          # parse vertexproperty
+        return __find_cached_element(ctx, graph_name, val[3:-1], "vp")
     elif isinstance(val, str) and re.match(r"^m\[.*\]$", val):           # parse json as a map
         return _convert(json.loads(val[2:-1]), ctx)
     elif isinstance(val, str) and re.match(r"^p\[.*\]$", val):           # parse path
@@ -234,9 +237,19 @@ def __alias_direction(d):
 
 def __find_cached_element(ctx, graph_name, identifier, element_type):
     if graph_name == "empty":
-        cache = world.create_lookup_v(ctx.remote_conn["empty"]) if element_type == "v" else world.create_lookup_e(ctx.remote_conn["empty"])
+        if element_type == "v":
+            cache = world.create_lookup_v(ctx.remote_conn["empty"])
+        elif element_type == "vp":
+            cache = world.create_lookup_vp(ctx.remote_conn["empty"])
+        else:
+            cache = world.create_lookup_e(ctx.remote_conn["empty"])
     else:
-        cache = ctx.lookup_v[graph_name] if element_type == "v" else ctx.lookup_e[graph_name]
+        if element_type == "v":
+            cache = ctx.lookup_v[graph_name]
+        elif element_type == "vp":
+            cache = ctx.lookup_vp[graph_name]
+        else:
+            cache = ctx.lookup_e[graph_name]
 
     # try to lookup the element - if it can't be found then it must be a reference Vertex
     if identifier in cache:
diff --git a/gremlin-python/src/main/python/radish/terrain.py b/gremlin-python/src/main/python/radish/terrain.py
index 24a102c..c3a4d1d 100644
--- a/gremlin-python/src/main/python/radish/terrain.py
+++ b/gremlin-python/src/main/python/radish/terrain.py
@@ -23,9 +23,9 @@ from gremlin_python.driver import serializer
 from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
 from radish import before, after, world
 
-outV = __.outV
+outV = __.out_v
 label = __.label
-inV = __.inV
+inV = __.in_v
 project = __.project
 tail = __.tail
 
@@ -41,6 +41,7 @@ def prepare_static_traversal_source(features, marker):
         cache[graph_name[0]]["remote_conn"] = __create_remote(graph_name[1])
         cache[graph_name[0]]["lookup_v"] = world.create_lookup_v(remote)
         cache[graph_name[0]]["lookup_e"] = world.create_lookup_e(remote)
+        cache[graph_name[0]]["lookup_vp"] = world.create_lookup_vp(remote)
 
     # store the cache on the global context so that remotes can be shutdown cleanly at the end of the tests
     world.cache = cache
@@ -52,15 +53,18 @@ def prepare_static_traversal_source(features, marker):
             scenario.context.remote_conn = {}
             scenario.context.lookup_v = {}
             scenario.context.lookup_e = {}
+            scenario.context.lookup_vp = {}
 
             for graph_name in ("modern", "classic", "crew", "grateful", "sink"):
                 scenario.context.remote_conn[graph_name] = cache[graph_name]["remote_conn"]
                 scenario.context.lookup_v[graph_name] = cache[graph_name]["lookup_v"]
                 scenario.context.lookup_e[graph_name] = cache[graph_name]["lookup_e"]
+                scenario.context.lookup_vp[graph_name] = cache[graph_name]["lookup_vp"]
 
             # setup the "empty" lookups as needed
             scenario.context.lookup_v["empty"] = {}
             scenario.context.lookup_e["empty"] = {}
+            scenario.context.lookup_vp["empty"] = {}
 
 
 @before.each_scenario
diff --git a/gremlin-python/src/main/python/radish/utils.py b/gremlin-python/src/main/python/radish/utils.py
index 09e565c..226aca6 100644
--- a/gremlin-python/src/main/python/radish/utils.py
+++ b/gremlin-python/src/main/python/radish/utils.py
@@ -21,6 +21,7 @@ from gremlin_python.process.anonymous_traversal import traversal
 from gremlin_python.process.graph_traversal import __
 from radish import pick
 
+
 @pick
 def create_lookup_v(remote):
     g = traversal().withRemote(remote)
@@ -37,4 +38,25 @@ def create_lookup_e(remote):
     # outgoingV-label->incomingV
     return g.E().group(). \
         by(lambda: ("it.outVertex().value('name') + '-' + it.label() + '->' + it.inVertex().value('name')", "gremlin-groovy")). \
-        by(__.tail()).next()
\ No newline at end of file
+        by(__.tail()).next()
+
+
+@pick
+def create_lookup_vp(remote):
+    g = traversal().withRemote(remote)
+
+    # hold a map of the "name"/vertexproperty for use in asserting results - "name" in this context is in the form of
+    # vertexName-propName->propVal where the propVal must be typed according to the gherkin spec. note that the toy
+    # graphs only deal in String/Int/Float/Double types so none of the other types are accounted for here.
+    return g.V().properties().group(). \
+        by(lambda: ("{ it -> \n" +
+                    "  def val = it.value()\n" +
+                    "  if (val instanceof Integer)\n" +
+                    "    val = 'd[' + val + '].i'\n" +
+                    "  else if (val instanceof Float)\n" +
+                    "    val = 'd[' + val + '].f'\n" +
+                    "  else if (val instanceof Double)\n" +
+                    "    val = 'd[' + val + '].d'\n" +
+                    "  return it.element().value('name') + '-' + it.key() + '->' + val\n" +
+                    "}", "gremlin-groovy")). \
+        by(__.tail()).next()