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/03 18:20:50 UTC
[05/26] tinkerpop git commit: TINKERPOP-1784 Added coin() gherkin
tests and refactored python
TINKERPOP-1784 Added coin() gherkin tests and refactored python
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/cda7a5a3
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/cda7a5a3
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/cda7a5a3
Branch: refs/heads/TINKERPOP-1784
Commit: cda7a5a3418d34f0f193c0eb5f69dbedd7182fdf
Parents: aea5a63
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Sep 20 18:38:49 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Oct 3 14:19:51 2017 -0400
----------------------------------------------------------------------
.../main/jython/radish/count_features_step.py | 50 -------------
.../src/main/jython/radish/feature_steps.py | 77 ++++++++++++++++++++
gremlin-test/features/map/Coin.feature | 42 +++++++++++
gremlin-test/features/map/Count.feature | 46 ++++++------
4 files changed, 144 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cda7a5a3/gremlin-python/src/main/jython/radish/count_features_step.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/radish/count_features_step.py b/gremlin-python/src/main/jython/radish/count_features_step.py
deleted file mode 100644
index ec04551..0000000
--- a/gremlin-python/src/main/jython/radish/count_features_step.py
+++ /dev/null
@@ -1,50 +0,0 @@
-'''
-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.
-'''
-
-from gremlin_python.structure.graph import Graph
-from gremlin_python.process.graph_traversal import __
-from gremlin_python.process.traversal import Scope
-from radish import before, given, when, then
-
-out = __.out
-
-
-@given("the {graphName:w} graph")
-def choose_graph(step, graphName):
- # only have modern atm but graphName would be used to select the right one
- step.context.g = Graph().traversal().withRemote(step.context.remote_conn_modern)
-
-
-@given("the traversal of")
-def translate_traversal(step):
- g = step.context.g
- step.context.traversal = eval(step.text, {"g": g, "Scope": Scope})
-
-
-@when("iterating")
-def iterate_the_traversal(step):
- step.context.result = step.context.traversal.toList()
-
-
-@then("the result should be {number:d}")
-def assert_single_result_of_number(step, number):
- assert len(step.context.result) == 1
- assert step.context.result[0] == number
-
-
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cda7a5a3/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
new file mode 100644
index 0000000..61297ff
--- /dev/null
+++ b/gremlin-python/src/main/jython/radish/feature_steps.py
@@ -0,0 +1,77 @@
+'''
+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.
+'''
+
+from gremlin_python.structure.graph import Graph
+from gremlin_python.process.graph_traversal import __
+from gremlin_python.process.traversal import Scope
+from radish import before, given, when, then
+
+out = __.out
+
+
+@given("the {graphName:w} graph")
+def choose_graph(step, graphName):
+ # only have modern atm but graphName would be used to select the right one
+ step.context.g = Graph().traversal().withRemote(step.context.remote_conn_modern)
+
+
+@given("the traversal of")
+def translate_traversal(step):
+ g = step.context.g
+ step.context.traversal = eval(step.text, {"g": g, "Scope": Scope})
+
+
+@when("iterated to list")
+def iterate_the_traversal(step):
+ step.context.result = step.context.traversal.toList()
+
+
+@then("the result should be {characterized_as:w}")
+def assert_result(step, characterized_as):
+ if characterized_as == "empty":
+ assert len(step.context.result) == 0
+ elif characterized_as == "ordered":
+ data = step.table
+
+ # results from traversal should have the same number of entries as the feature data table
+ assert len(step.context.result) == len(data)
+
+ # assert the results by type where the first column will hold the type and the second column
+ # the data to assert. the contents of the second column will be dependent on the type specified
+ # in te first column
+ for ix, line in enumerate(data):
+ if line[0] == "numeric":
+ assert long(step.context.result[ix]) == long(line[1])
+ elif line[0] == "string":
+ assert str(step.context.result[ix]) == str(line[1])
+ else:
+ assert step.context.result[ix] == line[1]
+ elif characterized_as == "unordered":
+ data = step.table
+
+ # results from traversal should have the same number of entries as the feature data table
+ assert len(step.context.result) == len(data)
+
+
+
+@then("the results should be empty")
+def assert_result(step):
+ assert len(step.context.result) == 0
+
+
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cda7a5a3/gremlin-test/features/map/Coin.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/map/Coin.feature b/gremlin-test/features/map/Coin.feature
new file mode 100644
index 0000000..b21bd70
--- /dev/null
+++ b/gremlin-test/features/map/Coin.feature
@@ -0,0 +1,42 @@
+# 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 - coin()
+
+ Scenario: Use coin at 1.0
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().coin(1.0)
+ """
+ When iterated to list
+ Then the result should be unordered as
+ | vertex | person |
+ | vertex | person |
+ | vertex | person |
+ | vertex | person |
+ | vertex | software |
+ | vertex | software |
+
+ Scenario: Use coin at 0.0
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().coin(0.0)
+ """
+ When iterated to list
+ Then the result should be empty
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cda7a5a3/gremlin-test/features/map/Count.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/map/Count.feature b/gremlin-test/features/map/Count.feature
index 383eecf..316976e 100644
--- a/gremlin-test/features/map/Count.feature
+++ b/gremlin-test/features/map/Count.feature
@@ -15,40 +15,44 @@
# specific language governing permissions and limitations
# under the License.
-Feature: Count Step
+Feature: Step - count()
Scenario: Count all vertices
Given the modern graph
And the traversal of
- """
- g.V().count()
- """
- When iterating
- Then the result should be 6
+ """
+ g.V().count()
+ """
+ When iterated to list
+ Then the result should be ordered
+ | numeric | 6 |
Scenario: Count vertices after traversing both() twice
Given the modern graph
And the traversal of
- """
- g.V().both().both().count()
- """
- When iterating
- Then the result should be 30
+ """
+ g.V().both().both().count()
+ """
+ When iterated to list
+ Then the result should be ordered
+ | numeric | 30 |
Scenario: Count local
Given the modern graph
And the traversal of
- """
- g.V().fold().count(Scope.local)
- """
- When iterating
- Then the result should be 6
+ """
+ g.V().fold().count(Scope.local)
+ """
+ When iterated to list
+ Then the result should be ordered
+ | numeric | 6 |
Scenario: Count no vertices
Given the modern graph
And the traversal of
- """
- g.V().has("no").count()
- """
- When iterating
- Then the result should be 0
\ No newline at end of file
+ """
+ g.V().has("no").count()
+ """
+ When iterated to list
+ Then the result should be ordered
+ | numeric | 0 |
\ No newline at end of file