|
1
|
|
|
from tests.framework.calls.calls_record import CallRecord |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
# pylint: disable=too-many-arguments |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class CallsRegistry: |
|
|
|
|
|
|
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
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.