Exemplo n.º 1
0
 def test_singletons(self):
     g = Graph().traversal()
     bytecode = g.withStrategies(ReadOnlyStrategy()).bytecode
     assert 1 == len(bytecode.source_instructions)
     assert 2 == len(bytecode.source_instructions[0])
     assert "withStrategies" == bytecode.source_instructions[0][0]
     assert ReadOnlyStrategy() == bytecode.source_instructions[0][1]
     assert "ReadOnlyStrategy" == str(bytecode.source_instructions[0][1])
     assert hash(ReadOnlyStrategy()) == hash(
         bytecode.source_instructions[0][1])
     assert 0 == len(g.traversal_strategies.traversal_strategies
                     )  # these strategies are proxies
     ##
     g = g.withStrategies(ReadOnlyStrategy(), IncidentToAdjacentStrategy())
     bytecode = g.bytecode
     assert 1 == len(bytecode.source_instructions)
     assert 3 == len(bytecode.source_instructions[0])
     assert "withStrategies" == bytecode.source_instructions[0][0]
     assert ReadOnlyStrategy() == bytecode.source_instructions[0][1]
     assert IncidentToAdjacentStrategy(
     ) == bytecode.source_instructions[0][2]
     ##
     bytecode = g.V().bytecode
     assert 1 == len(bytecode.source_instructions)
     assert 3 == len(bytecode.source_instructions[0])
     assert "withStrategies" == bytecode.source_instructions[0][0]
     assert ReadOnlyStrategy() == bytecode.source_instructions[0][1]
     assert IncidentToAdjacentStrategy(
     ) == bytecode.source_instructions[0][2]
     assert 1 == len(bytecode.step_instructions)
     assert "V" == bytecode.step_instructions[0][0]
     ##
     bytecode = g.withoutStrategies(ReadOnlyStrategy()).V().bytecode
     assert 2 == len(bytecode.source_instructions)
     assert 3 == len(bytecode.source_instructions[0])
     assert 2 == len(bytecode.source_instructions[1])
     assert "withStrategies" == bytecode.source_instructions[0][0]
     assert ReadOnlyStrategy() == bytecode.source_instructions[0][1]
     assert IncidentToAdjacentStrategy(
     ) == bytecode.source_instructions[0][2]
     assert "withoutStrategies" == bytecode.source_instructions[1][0]
     assert ReadOnlyStrategy() == bytecode.source_instructions[1][1]
     assert 1 == len(bytecode.step_instructions)
     assert "V" == bytecode.step_instructions[0][0]
     ##
     bytecode = g.withoutStrategies(ReadOnlyStrategy(),
                                    LazyBarrierStrategy()).V().bytecode
     assert 2 == len(bytecode.source_instructions)
     assert 3 == len(bytecode.source_instructions[0])
     assert 3 == len(bytecode.source_instructions[1])
     assert "withStrategies" == bytecode.source_instructions[0][0]
     assert ReadOnlyStrategy() == bytecode.source_instructions[0][1]
     assert IncidentToAdjacentStrategy(
     ) == bytecode.source_instructions[0][2]
     assert "withoutStrategies" == bytecode.source_instructions[1][0]
     assert ReadOnlyStrategy() == bytecode.source_instructions[1][1]
     assert LazyBarrierStrategy() == bytecode.source_instructions[1][2]
     assert 1 == len(bytecode.step_instructions)
     assert "V" == bytecode.step_instructions[0][0]
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
    ##
    t = g.with_("x", "test").with_("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
Exemplo n.º 4
0
 def test_configurable(self):
     g = Graph().traversal()
     bytecode = g.withStrategies(MatchAlgorithmStrategy("greedy")).bytecode
     assert 1 == len(bytecode.source_instructions)
     assert 2 == len(bytecode.source_instructions[0])
     assert "withStrategies" == bytecode.source_instructions[0][0]
     assert MatchAlgorithmStrategy() == bytecode.source_instructions[0][1]
     assert "MatchAlgorithmStrategy" == str(
         bytecode.source_instructions[0][1])
     assert hash(MatchAlgorithmStrategy()) == hash(
         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
     assert 1 == len(bytecode.source_instructions)
     assert 2 == len(bytecode.source_instructions[0])
     assert "withStrategies" == bytecode.source_instructions[0][0]
     assert SubgraphStrategy() == bytecode.source_instructions[0][1]
     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"]