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/05/26 12:55:37 UTC

[27/49] tinkerpop git commit: TINKERPOP-786 WIP for anonymous traversals in python DSLs

TINKERPOP-786 WIP for anonymous traversals in python DSLs

Not sure if this will be the right way to do this, but it works and tests pass. We'll see what happens once this gets review.


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

Branch: refs/heads/TINKERPOP-1618
Commit: a3d42d5f37ff90d758947f19b9568cd2a3d92f1b
Parents: 911d17f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed May 10 16:47:27 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 16 11:02:31 2017 -0400

----------------------------------------------------------------------
 .../src/main/jython/tests/process/test_dsl.py   | 30 ++++++++++++++++----
 1 file changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a3d42d5f/gremlin-python/src/main/jython/tests/process/test_dsl.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/process/test_dsl.py b/gremlin-python/src/main/jython/tests/process/test_dsl.py
index ece81dc..92196fe 100644
--- a/gremlin-python/src/main/jython/tests/process/test_dsl.py
+++ b/gremlin-python/src/main/jython/tests/process/test_dsl.py
@@ -18,14 +18,15 @@ under the License.
 '''
 import pytest
 
+from gremlin_python.process.traversal import (Bytecode, P)
 from gremlin_python.process.graph_traversal import (
-    GraphTraversalSource, GraphTraversal)
+    GraphTraversalSource, GraphTraversal, __)
 from gremlin_python.structure.graph import Graph
 
 __author__ = 'David M. Brown (davebshow@gmail.com)'
 
 
-class SocialTraversalDsl(GraphTraversal):
+class SocialTraversal(GraphTraversal):
 
     def knows(self, person_name):
         return self.out("knows").hasLabel("person").has("name", person_name)
@@ -33,12 +34,28 @@ class SocialTraversalDsl(GraphTraversal):
     def youngestFriendsAge(self):
         return self.out("knows").hasLabel("person").values("age").min()
 
+    def createdAtLeast(self, number):
+        return self.outE("created").count().is_(P.gte(number))
 
-class SocialTraversalSourceDsl(GraphTraversalSource):
+class ___(__):
+    @staticmethod
+    def knows(*args):
+        return SocialTraversal(None, None, Bytecode()).knows(*args)
+
+    @staticmethod
+    def youngestFriendsAge(*args):
+        return SocialTraversal(None, None, Bytecode()).youngestFriendsAge(*args)
+
+    @staticmethod
+    def createdAtLeast(*args):
+        return SocialTraversal(None, None, Bytecode()).createdAtLeast(*args)
+
+
+class SocialTraversalSource(GraphTraversalSource):
 
     def __init__(self, *args, **kwargs):
-        super(SocialTraversalSourceDsl, self).__init__(*args, **kwargs)
-        self.graph_traversal = SocialTraversalDsl
+        super(SocialTraversalSource, self).__init__(*args, **kwargs)
+        self.graph_traversal = SocialTraversal
 
     def persons(self):
         traversal = self.get_graph_traversal()
@@ -48,7 +65,8 @@ class SocialTraversalSourceDsl(GraphTraversalSource):
 
 
 def test_dsl(remote_connection):
-    social = Graph().traversal(SocialTraversalSourceDsl).withRemote(remote_connection)
+    social = Graph().traversal(SocialTraversalSource).withRemote(remote_connection)
     assert social.V().has("name", "marko").knows("josh").next()
     assert social.V().has("name", "marko").youngestFriendsAge().next() == 27
     assert social.persons().count().next() == 4
+    assert social.persons().filter(___.createdAtLeast(2)).count().next() == 1