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
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] ### g = Graph().traversal() bytecode = g.with_("x", "test").with_("y").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"]