TINKERPOP-1784 Added local() feature tests

Had to add a way to assert a results that matched any in a set as limit() type 
steps might force different results depending on the graph being tested.


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

Branch: refs/heads/TINKERPOP-1784
Commit: 0c99889c01cbd594aae7211eb343d842f59c8e89
Parents: 76f8839
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Oct 23 10:00:34 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Nov 2 13:37:23 2017 -0400

----------------------------------------------------------------------
 .../src/main/jython/radish/feature_steps.py     |  23 ++-
 gremlin-test/features/branch/Local.feature      | 172 +++++++++++++++++++
 2 files changed, 191 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0c99889c/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 f58f0da..2d2ae8d 100644
--- a/gremlin-python/src/main/jython/radish/feature_steps.py
+++ b/gremlin-python/src/main/jython/radish/feature_steps.py
@@ -34,7 +34,9 @@ regex_not = re.compile(r"([(.,\s])not\(")
 regex_or = re.compile(r"([(.,\s])or\(")
 
 
-ignores = ["g.V(v1Id).out().inject(v2).values(\"name\")"]
+ignores = [
+    "g.V(v1Id).out().inject(v2).values(\"name\")"  # bug in attachment won't 
connect v2
+           ]
 
 
 @given("the {graph_name:w} graph")
@@ -89,12 +91,14 @@ def assert_result(step, characterized_as):
     if step.context.ignore:
         return
 
-    if characterized_as == "empty":
+    if characterized_as == "empty":        # no results
         assert_that(len(step.context.result), equal_to(0))
-    elif characterized_as == "ordered":
+    elif characterized_as == "ordered":    # results asserted in the order of 
the data table
         _table_assertion(step.table, step.context.result, step.context, True)
-    elif characterized_as == "unordered":
+    elif characterized_as == "unordered":  # results asserted in any order
         _table_assertion(step.table, step.context.result, step.context, False)
+    elif characterized_as == "of":         # results may be of any of the 
specified items in the data table
+        _any_assertion(step.table, step.context.result, step.context)
     else:
         raise ValueError("unknown data characterization of " + 
characterized_as)
 
@@ -108,6 +112,11 @@ def assert_side_effects(step, count, traversal_string):
     assert_that(count, equal_to(t.count().next()))
 
 
+@then("only have a result count of {count:d}")
+def assert_count(step, count):
+    assert_that(count, equal_to(len(step.context.result)))
+
+
 @then("nothing should happen because")
 def nothing_happening(step):
     return
@@ -158,6 +167,12 @@ def _convert_results(val):
         return val
 
 
+def _any_assertion(data, result, ctx):
+    converted = [_convert(line[0], ctx) for line in data]
+    for r in result:
+        assert_that(r, is_in(converted))
+
+
 def _table_assertion(data, result, ctx, ordered):
     # results from traversal should have the same number of entries as the 
feature data table
     assert_that(len(result), equal_to(len(data)))

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0c99889c/gremlin-test/features/branch/Local.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/branch/Local.feature 
b/gremlin-test/features/branch/Local.feature
new file mode 100644
index 0000000..53ae3ab
--- /dev/null
+++ b/gremlin-test/features/branch/Local.feature
@@ -0,0 +1,172 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contriAndor license agreements.  See the NOTICE file
+# distriAnded 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 distriAnded under the License is distriAnded 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 - local()
+
+  Scenario: g_V_localXpropertiesXlocationX_order_byXvalueX_limitX2XX_value
+    Given the crew graph
+    And the traversal of
+      """
+      g.V().local(__.properties("location").order().by(T.value, 
Order.incr).range(0, 2)).value()
+      """
+    When iterated to list
+    Then the result should be unordered
+      | brussels       |
+      | san diego      |
+      | centreville    |
+      | dulles         |
+      | baltimore      |
+      | bremen         |
+      | aachen         |
+      | kaiserslautern |
+
+  Scenario: 
g_V_hasXlabel_personX_asXaX_localXoutXcreatedX_asXbXX_selectXa_bX_byXnameX_byXidX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().has(T.label, 
"person").as("a").local(__.out("created").as("b")).select("a", 
"b").by("name").by(T.id)
+      """
+    When iterated to list
+    Then the result should be unordered
+      | m[{"a":"marko","b":3}] |
+      | m[{"a":"josh","b":5}]  |
+      | m[{"a":"josh","b":3}]  |
+      | m[{"a":"peter","b":3}] |
+
+  Scenario: g_V_localXoutE_countX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().local(__.outE().count())
+      """
+    When iterated to list
+    Then the result should be unordered
+      | d[3] |
+      | d[0] |
+      | d[0] |
+      | d[2] |
+      | d[0] |
+      | d[1] |
+
+  Scenario: g_VX1X_localXoutEXknowsX_limitX1XX_inV_name
+    Given the modern graph
+    And using the parameter v1Id defined as "v[marko].id"
+    And the traversal of
+      """
+      g.V(v1Id).local(__.outE("knows").limit(1)).inV().values("name")
+      """
+    When iterated to list
+    Then the result should be of
+      | vadas |
+      | josh  |
+    And only have a result count of 1
+
+  Scenario: g_V_localXbothEXcreatedX_limitX1XX_otherV_name
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().local(__.bothE("created").limit(1)).otherV().values("name")
+      """
+    When iterated to list
+    Then the result should be of
+      | marko  |
+      | lop    |
+      | ripple |
+      | josh   |
+      | peter  |
+    And only have a result count of 5
+
+  Scenario: g_VX4X_localXbothEX1_createdX_limitX1XX
+    Given the modern graph
+    And using the parameter v4Id defined as "v[josh].id"
+    And the traversal of
+      """
+      g.V(v4Id).local(__.bothE("created").limit(1))
+      """
+    When iterated to list
+    Then the result should be of
+      | e[josh-created->lop]    |
+      | e[josh-created->ripple] |
+    And only have a result count of 1
+
+  Scenario: g_VX4X_localXbothEXknows_createdX_limitX1XX
+    Given the modern graph
+    And using the parameter v4Id defined as "v[josh].id"
+    And the traversal of
+      """
+      g.V(v4Id).local(__.bothE("knows", "created").limit(1))
+      """
+    When iterated to list
+    Then the result should be of
+      | e[marko-knows->josh]    |
+      | e[josh-created->lop]    |
+      | e[josh-created->ripple] |
+    And only have a result count of 1
+
+  Scenario: g_VX4X_localXbothE_limitX1XX_otherV_name
+    Given the modern graph
+    And using the parameter v4Id defined as "v[josh].id"
+    And the traversal of
+      """
+      g.V(v4Id).local(__.bothE().limit(1)).otherV().values("name")
+      """
+    When iterated to list
+    Then the result should be of
+      | marko  |
+      | ripple |
+      | lop    |
+    And only have a result count of 1
+
+  Scenario: g_VX4X_localXbothE_limitX2XX_otherV_name
+    Given the modern graph
+    And using the parameter v4Id defined as "v[josh].id"
+    And the traversal of
+      """
+      g.V(v4Id).local(__.bothE().limit(2)).otherV().values("name")
+      """
+    When iterated to list
+    Then the result should be of
+      | marko  |
+      | ripple |
+      | lop    |
+    And only have a result count of 2
+
+  Scenario: g_V_localXinEXknowsX_limitX2XX_outV_name
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().local(__.inE("knows").limit(2)).outV().values("name")
+      """
+    When iterated to list
+    Then the result should be unordered
+      | marko |
+      | marko |
+
+  Scenario: 
g_V_localXmatchXproject__created_person__person_name_nameX_selectXname_projectX_by_byXnameX
+    Given the modern graph
+    And the traversal of
+      """
+      g.V().local(__.match(
+                    __.as("project").in("created").as("person"),
+                    __.as("person").values("name").as("name"))).select("name", 
"project").by().by("name")
+      """
+    When iterated to list
+    Then the result should be unordered
+      | m[{"name":"marko","project":"lop"}]   |
+      | m[{"name":"josh","project":"lop"}]    |
+      | m[{"name":"peter","project":"lop"}]   |
+      | m[{"name":"josh","project":"ripple"}] |
\ No newline at end of file

Reply via email to