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]
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"]