Passed
Push — master ( 86491c...095442 )
by Matěj
19:19 queued 14:22
created

oval_graph._builder_oval_tree   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 47
dl 0
loc 57
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _BuilderOvalTree.get_oval_tree_from_dict_of_rule() 0 14 1
A _BuilderOvalTree._get_id_defintion() 0 5 2
A _BuilderOvalTree._definition_dict_to_node() 0 27 3
1 1
import uuid
2
3 1
from .oval_node import OvalNode
4
5
6 1
class _BuilderOvalTree:
7
8 1
    @staticmethod
9
    def _definition_dict_to_node(dict_of_definition):
10 1
        children = []
11 1
        for child in dict_of_definition['node']:
12 1
            if 'operator' in child:
13 1
                children.append(
14
                    _BuilderOvalTree._definition_dict_to_node(child))
15
            else:
16 1
                children.append(
17
                    OvalNode(
18
                        node_id=child['value_id'],
19
                        node_type='value',
20
                        value=child['value'],
21
                        negation=child['negate'],
22
                        comment=child['comment'],
23
                        tag=child['tag'],
24
                        test_result_details=child['test_result_details'],
25
                    ))
26
27 1
        return OvalNode(
28
            node_id=_BuilderOvalTree._get_id_defintion(dict_of_definition),
29
            node_type='operator',
30
            value=dict_of_definition['operator'],
31
            negation=dict_of_definition['negate'],
32
            comment=dict_of_definition['comment'],
33
            tag=dict_of_definition['tag'],
34
            children=children,
35
        )
36
37 1
    @staticmethod
38
    def _get_id_defintion(dict_of_definition):
39 1
        if 'definition_id' in dict_of_definition:
40 1
            return dict_of_definition['definition_id']
41 1
        return str(uuid.uuid4())
42
43 1
    @staticmethod
44
    def get_oval_tree_from_dict_of_rule(rule):
45 1
        dict_of_definition = rule['definition']
46 1
        dict_of_definition['node']['definition_id'] = rule['definition_id']
47 1
        return OvalNode(
48
            node_id=rule['rule_id'],
49
            node_type='operator',
50
            value='and',
51
            negation=False,
52
            comment=dict_of_definition['comment'],
53
            tag="Rule",
54
            children=[
55
                _BuilderOvalTree._definition_dict_to_node(
56
                    dict_of_definition['node'])],
57
        )
58