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 2019/09/04 13:22:35 UTC

[tinkerpop] 25/40: Fixed a basic integration test runs for python 2.

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch TINKERPOP-2279
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit f74ff214e3f023ca15d382105e6fe84996dd2f7d
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Tue Aug 13 11:46:50 2019 -0400

    Fixed a basic integration test runs for python 2.
---
 .../src/main/jython/gremlin_python/driver/serializer.py    |  8 +++++++-
 .../jython/gremlin_python/structure/io/graphbinaryV1.py    | 14 ++++++++++----
 gremlin-python/src/main/jython/tests/conftest.py           |  6 +++++-
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/serializer.py b/gremlin-python/src/main/jython/gremlin_python/driver/serializer.py
index a95d292..a0493f4 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/serializer.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/serializer.py
@@ -237,7 +237,13 @@ class GraphBinarySerializersV1(object):
         ba.extend(struct.pack(">i", len(args)))
         for k, v in args.items():
             ba.extend(self._graphbinary_writer.writeObject(k))
-            ba.extend(self._graphbinary_writer.writeObject(v))
+
+            # processor_obj.get_op_args in serialize_message() seems to already handle bytecode. in python 3
+            # because bytearray isn't bound to a type in graphbinary it falls through the writeObject() and
+            # just works but python 2 bytearray is bound to ByteBufferType so it writes DataType.bytebuffer
+            # rather than DataType.bytecode and the server gets confused. special casing this for now until
+            # it can be refactored
+            ba.extend(v if k == "gremlin" else self._graphbinary_writer.writeObject(v))
 
         return bytes(ba)
 
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py
index dd829cf..e730c8e 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py
@@ -40,6 +40,7 @@ from gremlin_python.statics import FloatType, FunctionType, IntType, LongType, T
 from gremlin_python.process.traversal import Barrier, Binding, Bytecode, Cardinality, Column, Direction, Operator, \
                                              Order, Pick, Pop, P, Scope, TextP, Traversal, Traverser, \
                                              TraversalStrategy, T
+from gremlin_python.process.graph_traversal import GraphTraversal
 from gremlin_python.structure.graph import Graph, Edge, Property, Vertex, VertexProperty, Path
 
 log = logging.getLogger(__name__)
@@ -663,17 +664,18 @@ class BytecodeIO(_GraphBinaryTypeIO):
 
     @classmethod
     def dictify(cls, obj, writer, as_value=False, nullable=True):
+        bc = obj.bytecode if isinstance(obj, Traversal) else obj
         ba = bytearray()
-        ba.extend(struct.pack(">i", len(obj.step_instructions)))
-        for inst in obj.step_instructions:
+        ba.extend(struct.pack(">i", len(bc.step_instructions)))
+        for inst in bc.step_instructions:
             inst_name, inst_args = inst[0], inst[1:] if len(inst) > 1 else []
             ba.extend(cls.string_as_bytes(inst_name))
             ba.extend(struct.pack(">i", len(inst_args)))
             for arg in inst_args:
                 ba.extend(writer.writeObject(arg))
 
-        ba.extend(struct.pack(">i", len(obj.source_instructions)))
-        for inst in obj.source_instructions:
+        ba.extend(struct.pack(">i", len(bc.source_instructions)))
+        for inst in bc.source_instructions:
             inst_name, inst_args = inst[0], inst[1:] if len(inst) > 1 else []
             ba.extend(cls.string_as_bytes(inst_name))
             ba.extend(struct.pack(">i", len(inst_args)))
@@ -720,6 +722,10 @@ class BytecodeIO(_GraphBinaryTypeIO):
         return bytecode
 
 
+class TraversalIO(BytecodeIO):
+    python_type = GraphTraversal
+
+
 class LambdaIO(_GraphBinaryTypeIO):
 
     python_type = FunctionType
diff --git a/gremlin-python/src/main/jython/tests/conftest.py b/gremlin-python/src/main/jython/tests/conftest.py
index 9597f4d..a1224ac 100644
--- a/gremlin-python/src/main/jython/tests/conftest.py
+++ b/gremlin-python/src/main/jython/tests/conftest.py
@@ -32,6 +32,7 @@ from gremlin_python.driver.serializer import (
     GraphBinarySerializersV1)
 from gremlin_python.driver.tornado.transport import TornadoTransport
 
+# docker Gremlin Server = 172.17.0.2
 gremlin_server_host = "localhost"
 gremlin_server_url = 'ws://' + gremlin_server_host + ':45940/gremlin'
 
@@ -92,8 +93,11 @@ def remote_connection(request):
         elif request.param == 'graphsonv2':
             remote_conn = DriverRemoteConnection(gremlin_server_url, 'gmodern',
                                                  message_serializer=serializer.GraphSONSerializersV2d0())
+        elif request.param == 'graphsonv3':
+            remote_conn = DriverRemoteConnection(gremlin_server_url, 'gmodern',
+                                                 message_serializer=serializer.GraphSONSerializersV3d0())
         else:
-            remote_conn = DriverRemoteConnection(gremlin_server_url, 'gmodern')
+            raise ValueError("Invalid serializer option - " + request.param)
     except OSError:
         pytest.skip('Gremlin Server is not running')
     else: