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/08/26 19:15:59 UTC

tinkerpop git commit: Graph.py repr is now graph[empty]. added more test cases. found a bug in Property.py. Test cases rule.

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 b8ea0237a -> 3c8f49839


Graph.py repr is now graph[empty]. added more test cases. found a bug in Property.py. Test cases rule.


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

Branch: refs/heads/TINKERPOP-1278
Commit: 3c8f49839f357e0a7ddc3f0b2af4d9827ee421ec
Parents: b8ea023
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Aug 26 13:15:53 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Aug 26 13:15:53 2016 -0600

----------------------------------------------------------------------
 .../structure/util/empty/EmptyGraph.java        |  2 +-
 .../driver/driver_remote_connection.py          |  4 +--
 .../jython/gremlin_python/structure/graph.py    |  4 +--
 .../gremlin_python/structure/io/graphson.py     |  3 +-
 .../jython/tests/structure/io/test_graphson.py  | 20 +++++++++++-
 .../main/jython/tests/structure/test_graph.py   | 33 +++++++++++++++-----
 6 files changed, 50 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3c8f4983/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
index 40cf31f..59464c5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
@@ -102,7 +102,7 @@ public final class EmptyGraph implements Graph {
 
     @Override
     public String toString() {
-        return StringFactory.graphString(this, "vertices: 0 edges: 0");
+        return StringFactory.graphString(this, "empty");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3c8f4983/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py b/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
index f1aaeee..c67af67 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
@@ -120,7 +120,7 @@ class DriverRemoteConnection(RemoteConnection):
     def _execute_message(self, send_message):
         send_message = b"".join([b"\x21",
                                  b"application/vnd.gremlin-v2.0+json",
-                                 json.dumps(send_message).encode("utf-8")])
+                                 json.dumps(send_message, separators=(',', ':')).encode("utf-8")])
         if self._websocket.protocol is None:
             self._websocket = yield websocket.websocket_connect(self.url)
         self._websocket.write_message(send_message, binary=True)
@@ -193,7 +193,7 @@ class Response:
                                       b"".join([b"\x00", self._username.encode("utf-8"),
                                                 b"\x00", self._password.encode("utf-8")])).decode()
                               }
-                          }).encode("utf-8")]), binary=True)
+                          }, separators=(',', ':')).encode("utf-8")]), binary=True)
             results = yield self.receive()
             raise gen.Return(results)
         elif status_code == 204:

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3c8f4983/gremlin-python/src/main/jython/gremlin_python/structure/graph.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/graph.py b/gremlin-python/src/main/jython/gremlin_python/structure/graph.py
index e07aaf2..b047893 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/graph.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/graph.py
@@ -80,5 +80,5 @@ class Property(object):
     def __repr__(self):
         return "p[" + str(self.key) + "->" + str(self.value)[0:20] + "]"
 
-        def __eq__(self, other):
-            return isinstance(other, self.__class__) and self.key == other.key and self.value == other.value
+    def __eq__(self, other):
+        return isinstance(other, self.__class__) and self.key == other.key and self.value == other.value

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3c8f4983/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index 2e3f9a5..a844191 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -19,7 +19,6 @@ under the License.
 
 __author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
 
-
 import json
 from abc import abstractmethod
 from aenum import Enum
@@ -62,7 +61,7 @@ class GraphSONWriter(object):
 
     @staticmethod
     def writeObject(objectData):
-        return json.dumps(GraphSONWriter._dictify(objectData))
+        return json.dumps(GraphSONWriter._dictify(objectData), separators=(',', ':'))
 
 
 class GraphSONReader(object):

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3c8f4983/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
index f8a64f8..3153fd6 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
@@ -23,10 +23,12 @@ import json
 import unittest
 from unittest import TestCase
 
+from gremlin_python.structure.graph import Vertex
 from gremlin_python.structure.io.graphson import GraphSONReader
+from gremlin_python.structure.io.graphson import GraphSONWriter
 
 
-class TestGraphSON(TestCase):
+class TestGraphSONReader(TestCase):
     def test_numbers(self):
         x = GraphSONReader.readObject(json.dumps({
             "@type": "g:Int32",
@@ -56,6 +58,22 @@ class TestGraphSON(TestCase):
         assert isinstance(x, float)
         assert 31.2 == x
 
+    def test_graph(self):
+        vertex = GraphSONReader.readObject(
+            """{"@type":"g:Vertex", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","outE":{"created":[{"id":{"@type":"g:Int32","@value":9},"inV":{"@type":"g:Int32","@value":3},"properties":{"weight":{"@type":"g:Double","@value":0.4}}}],"knows":[{"id":{"@type":"g:Int32","@value":7},"inV":{"@type":"g:Int32","@value":2},"properties":{"weight":{"@type":"g:Double","@value":0.5}}},{"id":{"@type":"g:Int32","@value":8},"inV":{"@type":"g:Int32","@value":4},"properties":{"weight":{"@type":"g:Double","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":0},"value":"marko"}],"age":[{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29}}]}}}""")
+        assert isinstance(vertex, Vertex)
+        assert "person" == vertex.label
+        assert 1 == vertex.id
+        assert isinstance(vertex.id, int)
+        assert vertex == Vertex(1)
+
+class TestGraphSONWriter(TestCase):
+    def test_numbers(self):
+        assert """{"@type":"g:Int32","@value":1}""" == GraphSONWriter.writeObject(1)
+        assert """{"@type":"g:Int64","@value":2}""" == GraphSONWriter.writeObject(2L)
+        assert """{"@type":"g:Float","@value":3.2}""" == GraphSONWriter.writeObject(3.2)
+        assert """true""" == GraphSONWriter.writeObject(True)
+
 
 if __name__ == '__main__':
     unittest.main()

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3c8f4983/gremlin-python/src/main/jython/tests/structure/test_graph.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/structure/test_graph.py b/gremlin-python/src/main/jython/tests/structure/test_graph.py
index 9ba32c9..888f587 100644
--- a/gremlin-python/src/main/jython/tests/structure/test_graph.py
+++ b/gremlin-python/src/main/jython/tests/structure/test_graph.py
@@ -23,6 +23,7 @@ import unittest
 from unittest import TestCase
 
 from gremlin_python.structure import Edge
+from gremlin_python.structure import Property
 from gremlin_python.structure import Vertex
 from gremlin_python.structure import VertexProperty
 
@@ -41,15 +42,31 @@ class TestGraph(TestCase):
         assert Vertex("hello") == edge.inV
         assert "said" == edge.label
         assert "phrase" == edge.inV.label
+        assert edge.inV != edge.outV
         #
-        vp = VertexProperty(24L, "name", "marko")
-        assert "vp[name->marko]" == str(vp)
-        assert "name" == vp.label
-        assert "name" == vp.key
-        assert "marko" == vp.value
-        assert 24L == vp.id
-        assert isinstance(vp.id, long)
-        assert vp == VertexProperty(24L, "name", "marko")
+        vertex_property = VertexProperty(24L, "name", "marko")
+        assert "vp[name->marko]" == str(vertex_property)
+        assert "name" == vertex_property.label
+        assert "name" == vertex_property.key
+        assert "marko" == vertex_property.value
+        assert 24L == vertex_property.id
+        assert isinstance(vertex_property.id, long)
+        assert vertex_property == VertexProperty(24L, "name", "marko")
+        #
+        property = Property("age", 29)
+        assert "p[age->29]" == str(property)
+        assert "age" == property.key
+        assert 29 == property.value
+        assert isinstance(property.value, int)
+        assert property == Property("age", 29)
+        assert property != Property("age", 29L)
+        #
+        for i in [vertex, edge, vertex_property, property]:
+            for j in [vertex, edge, vertex_property, property]:
+                if type(i) != type(j):
+                    assert i != j
+                else:
+                    assert i == j
 
 
 if __name__ == '__main__':