TestTraversalStrategies.test_singletons()   B
last analyzed

Complexity

Conditions 1

Size

Total Lines 52
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 52
rs 8.7018
c 0
b 0
f 0
cc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
'''
2
Licensed to the Apache Software Foundation (ASF) under one
3
or more contributor license agreements.  See the NOTICE file
4
distributed with this work for additional information
5
regarding copyright ownership.  The ASF licenses this file
6
to you under the Apache License, Version 2.0 (the
7
"License"); you may not use this file except in compliance
8
with the License.  You may obtain a copy of the License at
9
10
http://www.apache.org/licenses/LICENSE-2.0
11
12
Unless required by applicable law or agreed to in writing,
13
software distributed under the License is distributed on an
14
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
KIND, either express or implied.  See the License for the
16
specific language governing permissions and limitations
17
under the License.
18
'''
19
'''THIS FILE HAS BEEN MODIFIED BY DAVID M. BROWN TO SUPPORT PEP 492'''
20
__author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
21
22
23
from aiogremlin.structure.graph import Graph
24
from gremlin_python.process.strategies import *
25
from gremlin_python.process.graph_traversal import __
26
27
28
class TestTraversalStrategies:
29
30
    def test_singletons(self):
31
        g = Graph().traversal()
32
        bytecode = g.withStrategies(ReadOnlyStrategy()).bytecode
33
        assert 1 == len(bytecode.source_instructions)
34
        assert 2 == len(bytecode.source_instructions[0])
35
        assert "withStrategies" == bytecode.source_instructions[0][0]
36
        assert ReadOnlyStrategy() == bytecode.source_instructions[0][1]
37
        assert "ReadOnlyStrategy" == str(bytecode.source_instructions[0][1])
38
        assert hash(ReadOnlyStrategy()) == hash(bytecode.source_instructions[0][1])
39
        assert 0 == len(g.traversal_strategies.traversal_strategies)  # these strategies are proxies
40
        ##
41
        g = g.withStrategies(ReadOnlyStrategy(), IncidentToAdjacentStrategy())
42
        bytecode = g.bytecode
43
        assert 1 == len(bytecode.source_instructions)
44
        assert 3 == len(bytecode.source_instructions[0])
45
        assert "withStrategies" == bytecode.source_instructions[0][0]
46
        assert ReadOnlyStrategy() == bytecode.source_instructions[0][1]
47
        assert IncidentToAdjacentStrategy() == bytecode.source_instructions[0][2]
48
        ##
49
        bytecode = g.V().bytecode
50
        assert 1 == len(bytecode.source_instructions)
51
        assert 3 == len(bytecode.source_instructions[0])
52
        assert "withStrategies" == bytecode.source_instructions[0][0]
53
        assert ReadOnlyStrategy() == bytecode.source_instructions[0][1]
54
        assert IncidentToAdjacentStrategy() == bytecode.source_instructions[0][2]
55
        assert 1 == len(bytecode.step_instructions)
56
        assert "V" == bytecode.step_instructions[0][0]
57
        ##
58
        bytecode = g.withoutStrategies(ReadOnlyStrategy()).V().bytecode
59
        assert 2 == len(bytecode.source_instructions)
60
        assert 3 == len(bytecode.source_instructions[0])
61
        assert 2 == len(bytecode.source_instructions[1])
62
        assert "withStrategies" == bytecode.source_instructions[0][0]
63
        assert ReadOnlyStrategy() == bytecode.source_instructions[0][1]
64
        assert IncidentToAdjacentStrategy() == bytecode.source_instructions[0][2]
65
        assert "withoutStrategies" == bytecode.source_instructions[1][0]
66
        assert ReadOnlyStrategy() == bytecode.source_instructions[1][1]
67
        assert 1 == len(bytecode.step_instructions)
68
        assert "V" == bytecode.step_instructions[0][0]
69
        ##
70
        bytecode = g.withoutStrategies(ReadOnlyStrategy(), LazyBarrierStrategy()).V().bytecode
71
        assert 2 == len(bytecode.source_instructions)
72
        assert 3 == len(bytecode.source_instructions[0])
73
        assert 3 == len(bytecode.source_instructions[1])
74
        assert "withStrategies" == bytecode.source_instructions[0][0]
75
        assert ReadOnlyStrategy() == bytecode.source_instructions[0][1]
76
        assert IncidentToAdjacentStrategy() == bytecode.source_instructions[0][2]
77
        assert "withoutStrategies" == bytecode.source_instructions[1][0]
78
        assert ReadOnlyStrategy() == bytecode.source_instructions[1][1]
79
        assert LazyBarrierStrategy() == bytecode.source_instructions[1][2]
80
        assert 1 == len(bytecode.step_instructions)
81
        assert "V" == bytecode.step_instructions[0][0]
82
83
    def test_configurable(self):
84
        g = Graph().traversal()
85
        bytecode = g.withStrategies(MatchAlgorithmStrategy("greedy")).bytecode
86
        assert 1 == len(bytecode.source_instructions)
87
        assert 2 == len(bytecode.source_instructions[0])
88
        assert "withStrategies" == bytecode.source_instructions[0][0]
89
        assert MatchAlgorithmStrategy() == bytecode.source_instructions[0][1]
90
        assert "MatchAlgorithmStrategy" == str(bytecode.source_instructions[0][1])
91
        assert hash(MatchAlgorithmStrategy()) == hash(
92
            bytecode.source_instructions[0][1])  # even though different confs, same strategy
93
        assert 0 == len(g.traversal_strategies.traversal_strategies)  # these strategies are proxies
94
        ###
95
        bytecode = g.withStrategies(SubgraphStrategy(vertices=__.has("name","marko"))).bytecode
96
        assert 1 == len(bytecode.source_instructions)
97
        assert 2 == len(bytecode.source_instructions[0])
98
        assert "withStrategies" == bytecode.source_instructions[0][0]
99
        assert SubgraphStrategy() == bytecode.source_instructions[0][1]
100
        strategy = bytecode.source_instructions[0][1]
101
        assert 1 == len(strategy.configuration)
102
        assert __.has("name","marko") == strategy.configuration["vertices"]
103