Completed
Push — master ( aa0ea9...358d48 )
by Wojtek
02:19
created

CallsRegistry   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add_call() 0 14 1
A get_method_calls() 0 12 1
A register_call() 0 16 3
A __init__() 0 3 1
1
from tests.framework.calls.calls_record import CallRecord
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
4
# pylint: disable=too-many-arguments
0 ignored issues
show
introduced by
Locally disabling too-many-arguments (R0913)
Loading history...
5
6
7
class CallsRegistry:
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
8
    def __init__(self):
9
        self.calls_storage = {}
10
        self.calls_counter = 0
11
12
    def register_call(self, call_record):
13
        """
14
        Register call.
15
        Args:
16
            call_record (CallRecord): represent call
17
        """
18
        self.calls_counter += 1
19
        if self.calls_storage.get(call_record.entity_name) is None:
20
            self.calls_storage[call_record.entity_name] = {}
21
        if self.calls_storage[call_record.entity_name].get(
22
                call_record.method_name) is None:
23
            self.calls_storage[call_record.entity_name][
24
                call_record.method_name] = []
25
        self.calls_storage[call_record.entity_name][
26
            call_record.method_name].append({"call": call_record,
27
                                             "calls_count": self.calls_counter})
28
29
    def get_method_calls(self, entity_name, method_name):
30
        """
31
        Return calls
32
        Args:
33
            entity_name (str): name of entity
34
            method_name (str): name of method called on entity
35
36
        Returns:
37
            list: list of call objects  (CallRecord)
38
39
        """
40
        return self.calls_storage[entity_name][method_name]
41
42
    def add_call(self, entity_name, method_name, input_parms_list, output,
43
                 count):
44
        """Add and register call of function.
45
46
        Args:
47
            entity_name (str): name of entity
48
            method_name (str): name of method
49
            input_parms_list (list): list of arguments put to function
50
            output (object):  returned value by method_name
51
            count (int): number of count
52
        """
53
        call_record = CallRecord(entity_name, method_name, input_parms_list,
54
                                 output, count)
55
        self.register_call(call_record)
56