You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/12/08 22:54:04 UTC

[38/50] tinkerpop git commit: Add implementations for __.__() and __.start()

Add implementations for __.__() and __.start()


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

Branch: refs/heads/TINKERPOP-1564
Commit: da760378f81587e332241ebe07b60eaa42bbdcdb
Parents: b4c42e9
Author: Florian Hockmann <fh...@florian-hockmann.de>
Authored: Thu Dec 1 21:00:58 2016 +0100
Committer: Florian Hockmann <fh...@florian-hockmann.de>
Committed: Fri Dec 2 17:09:35 2016 +0100

----------------------------------------------------------------------
 .../python/GraphTraversalSourceGenerator.groovy        | 12 ++++++++++--
 .../jython/gremlin_python/process/graph_traversal.py   | 11 +++++++++++
 .../src/main/jython/tests/process/test_traversal.py    | 13 +++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da760378/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy b/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
index 1ffe575..9ba823c 100644
--- a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
+++ b/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
@@ -155,7 +155,15 @@ under the License.
 ////////////////////////
 // AnonymousTraversal //
 ////////////////////////
-        pythonClass.append("class __(object):\n");
+        pythonClass.append(
+                """class __(object):
+  @staticmethod
+  def start():
+    return GraphTraversal(None, None, Bytecode())
+  @staticmethod
+  def __(*args):
+    return __.inject(*args)
+""")
         __.class.getMethods().
                 findAll { GraphTraversal.class.equals(it.returnType) }.
                 findAll { Modifier.isStatic(it.getModifiers()) }.
@@ -175,7 +183,7 @@ under the License.
         __.class.getMethods().
                 findAll { GraphTraversal.class.equals(it.returnType) }.
                 findAll { Modifier.isStatic(it.getModifiers()) }.
-                findAll { !it.name.equals("__") && !it.name.equals("start") }.
+                findAll { !it.name.equals("__") }.
                 collect { SymbolHelper.toPython(it.name) }.
                 unique().
                 sort { a, b -> a <=> b }.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da760378/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
index 3c1a65d..4f9017c 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
@@ -392,6 +392,12 @@ class GraphTraversal(Traversal):
 
 class __(object):
   @staticmethod
+  def start():
+    return GraphTraversal(None, None, Bytecode())
+  @staticmethod
+  def __(*args):
+    return __.inject(*args)
+  @staticmethod
   def V(*args):
     return GraphTraversal(None, None, Bytecode()).V(*args)
   @staticmethod
@@ -1036,6 +1042,11 @@ def simplePath(*args):
 
 statics.add_static('simplePath', simplePath)
 
+def start(*args):
+      return __.start(*args)
+
+statics.add_static('start', start)
+
 def store(*args):
       return __.store(*args)
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da760378/gremlin-python/src/main/jython/tests/process/test_traversal.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/process/test_traversal.py b/gremlin-python/src/main/jython/tests/process/test_traversal.py
index e68b1e2..eb652f4 100644
--- a/gremlin-python/src/main/jython/tests/process/test_traversal.py
+++ b/gremlin-python/src/main/jython/tests/process/test_traversal.py
@@ -73,6 +73,19 @@ class TestTraversal(TestCase):
         assert "and(or(lt(b),gt(c)),or(neq(d),gte(e)))" == str(
             P.lt("b").or_(P.gt("c")).and_(P.neq("d").or_(P.gte("e"))))
 
+    def test_anonymous_traversal(self):
+        bytecode = __.__(1).bytecode
+        assert 0 == len(bytecode.bindings.keys())
+        assert 0 == len(bytecode.source_instructions)
+        assert 1 == len(bytecode.step_instructions)
+        assert "inject" == bytecode.step_instructions[0][0]
+        assert 1 == bytecode.step_instructions[0][1]
+        ##
+        bytecode = __.start().bytecode
+        assert 0 == len(bytecode.bindings.keys())
+        assert 0 == len(bytecode.source_instructions)
+        assert 0 == len(bytecode.step_instructions)
+
 
 if __name__ == '__main__':
     unittest.main()