Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-2053 91573d5c7 -> 16c324e67
TINKERPOP-2053 Python support for OptionsStrategy Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/16c324e6 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/16c324e6 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/16c324e6 Branch: refs/heads/TINKERPOP-2053 Commit: 16c324e67686b5c7dbebe941928b56113048d21a Parents: 91573d5 Author: Stephen Mallette <[email protected]> Authored: Tue Oct 2 11:44:22 2018 -0400 Committer: Stephen Mallette <[email protected]> Committed: Tue Oct 2 11:44:22 2018 -0400 ---------------------------------------------------------------------- .../main/jython/gremlin_python/process/strategies.py | 5 +++++ .../src/main/jython/tests/driver/test_client.py | 11 +++++++++++ .../src/main/jython/tests/process/test_strategies.py | 12 +++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/16c324e6/gremlin-python/src/main/jython/gremlin_python/process/strategies.py ---------------------------------------------------------------------- diff --git a/gremlin-python/src/main/jython/gremlin_python/process/strategies.py b/gremlin-python/src/main/jython/gremlin_python/process/strategies.py index f5ba9fb..9da8900 100644 --- a/gremlin-python/src/main/jython/gremlin_python/process/strategies.py +++ b/gremlin-python/src/main/jython/gremlin_python/process/strategies.py @@ -45,6 +45,11 @@ class HaltedTraverserStrategy(TraversalStrategy): self.configuration["haltedTraverserFactory"] = halted_traverser_factory +class OptionsStrategy(TraversalStrategy): + def __init__(self, options=None): + TraversalStrategy.__init__(self, configuration=options) + + class PartitionStrategy(TraversalStrategy): def __init__(self, partition_key=None, write_partition=None, read_partitions=None, include_meta_properties=None): TraversalStrategy.__init__(self) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/16c324e6/gremlin-python/src/main/jython/tests/driver/test_client.py ---------------------------------------------------------------------- diff --git a/gremlin-python/src/main/jython/tests/driver/test_client.py b/gremlin-python/src/main/jython/tests/driver/test_client.py index 42e2c07..edc5bea 100644 --- a/gremlin-python/src/main/jython/tests/driver/test_client.py +++ b/gremlin-python/src/main/jython/tests/driver/test_client.py @@ -21,6 +21,7 @@ import pytest from gremlin_python.driver.client import Client from gremlin_python.driver.protocol import GremlinServerError from gremlin_python.driver.request import RequestMessage +from gremlin_python.process.strategies import OptionsStrategy from gremlin_python.process.graph_traversal import __ from gremlin_python.structure.graph import Graph @@ -70,6 +71,16 @@ def test_client_bytecode(client): assert len(result_set.all().result()) == 6 +def test_client_bytecode_options(client): + # smoke test to validate serialization of OptionsStrategy. no way to really validate this from an integration + # test perspective because there's no way to access the internals of the strategy via bytecode + g = Graph().traversal() + t = g.withStrategies(OptionsStrategy(options={"x": "test", "y": True})).V() + message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode, 'aliases': {'g': 'gmodern'}}) + result_set = client.submit(message) + assert len(result_set.all().result()) == 6 + + def test_iterate_result_set(client): g = Graph().traversal() t = g.V() http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/16c324e6/gremlin-python/src/main/jython/tests/process/test_strategies.py ---------------------------------------------------------------------- diff --git a/gremlin-python/src/main/jython/tests/process/test_strategies.py b/gremlin-python/src/main/jython/tests/process/test_strategies.py index 008ec80..9025a96 100644 --- a/gremlin-python/src/main/jython/tests/process/test_strategies.py +++ b/gremlin-python/src/main/jython/tests/process/test_strategies.py @@ -90,7 +90,7 @@ class TestTraversalStrategies(object): bytecode.source_instructions[0][1]) # even though different confs, same strategy assert 0 == len(g.traversal_strategies.traversal_strategies) # these strategies are proxies ### - bytecode = g.withStrategies(SubgraphStrategy(vertices=__.has("name","marko"))).bytecode + bytecode = g.withStrategies(SubgraphStrategy(vertices=__.has("name", "marko"))).bytecode assert 1 == len(bytecode.source_instructions) assert 2 == len(bytecode.source_instructions[0]) assert "withStrategies" == bytecode.source_instructions[0][0] @@ -98,3 +98,13 @@ class TestTraversalStrategies(object): strategy = bytecode.source_instructions[0][1] assert 1 == len(strategy.configuration) assert __.has("name","marko") == strategy.configuration["vertices"] + ### + bytecode = g.withStrategies(OptionsStrategy(options={"x": "test", "y": True})).bytecode + assert 1 == len(bytecode.source_instructions) + assert 2 == len(bytecode.source_instructions[0]) + assert "withStrategies" == bytecode.source_instructions[0][0] + assert OptionsStrategy() == bytecode.source_instructions[0][1] + strategy = bytecode.source_instructions[0][1] + assert 2 == len(strategy.configuration) + assert "test" == strategy.configuration["x"] + assert strategy.configuration["y"]
