-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase_class_test.py
More file actions
148 lines (120 loc) · 5.24 KB
/
base_class_test.py
File metadata and controls
148 lines (120 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
"""
base_class_test.py - used in the SmallDevops module
Author - 0pb
Link - https://github.com/0pb/smalldevops
LICENSE GNU V3
"""
# print(f"Module {__name__} imported")
# libraries
import datetime
from ..core.execute_cli import *
from abc import ABCMeta, abstractmethod
# --------------------------------------------------------------------------------------------
class top_class_test(metaclass=ABCMeta):
def __init__(self, dict_config):
self.dict_config = dict_config
@abstractmethod
def get_discover_command(self) -> list:
pass
@staticmethod
def return_date() -> str:
"""
=> str
2020-10-1-19-35-39
"""
now = datetime.datetime.now()
return f"{now.year}-{now.month}-{now.day}-{now.hour}-{now.minute}-{now.second}"
@abstractmethod
def get_last_commit(self) -> list:
pass
@abstractmethod
def true_if_error_in_tests(self, list_stats : list) -> bool:
pass
@abstractmethod
def get_timing_test(self, list_stats : list) -> float:
pass
@abstractmethod
def get_dict_failed_test(self, list_failure_test : list, list_failure_msg : list) -> dict:
pass
@abstractmethod
def get_list_failure_test(self, list_test_name : list) -> list:
pass
@abstractmethod
def get_failure(self, string : str) -> list:
pass
@abstractmethod
def get_test_names(self, string : str) -> list:
pass
@abstractmethod
def get_statistics(self, string : str) -> list:
pass
@abstractmethod
def get_list_success_test(self, list_test_name : list) -> list:
pass
@abstractmethod
def get_output_test(self) -> str:
pass
def get_execution_time(self, command : list, true_if_print_output : bool) -> float:
""" call "usr/bin/time" (!= "time" which is shell specific) with a format real|user|sys """
"""
['python3', 'mini.py', 'test/Image_viewer', 'test/test_mini.py'], false
=> float
0:00.04
['python3', 'mini.py', 'test/Image_viewer', 'test/test_mini.py'], true
=> float
0:00.04
and print the stdout output in the console, useful for log as an example
"""
str_command = shlex.split('\\time -f "%E|%U|%S" ') + command
output_from_execution = execute_command_in_cmd(str_command)
if true_if_print_output:
print(output_from_execution[0])
print(output_from_execution[1])
timing = str(output_from_execution[0]).split("\n")
return float(timing[-2].split("|")[0].split(":")[1])
def create_dict(self) -> dict:
"""
Those function are the one that need to be modified for other test (because the output is not similar)
get_last_commit() may be modified to add more commit data, but it require change in javascript file later
same for self.get_execution_time(shlexifier(self.dict_config["list_argument_module"])
, self.dict_config["show_output"])
self.get_list_success_test(list_test_name)
self.get_test_names(output_test)
self.get_failure(output_test)
self.get_statistics(output_test)
self.get_last_commit()
self.get_execution_time(shlexifier(self.dict_config["list_argument_module"])
, self.dict_config["show_output"])
self.true_if_error_in_tests(list_stats)
self.get_timing_test(list_stats)
self.get_dict_failed_test(self.get_list_failure_test(list_test_name), list_failure_msg)
"""
output_test = self.get_output_test()
try:
list_test_name = self.get_test_names(output_test)
except IndexError:
list_test_name = []
try:
list_failure_msg = self.get_failure(output_test)
except IndexError:
list_failure_msg = []
try:
list_stats = self.get_statistics(output_test)
except IndexError:
list_stats = []
list_success_tests = self.get_list_success_test(list_test_name)
amount_test_failure = len(list_failure_msg)
amount_test_success = len(list_success_tests)
return {"total_amount" : amount_test_success + amount_test_failure #
, "commit" : self.get_last_commit()
, "timing_function" : self.get_execution_time(shlexifier(self.dict_config["list_argument_module"])
, self.dict_config["show_output"])
, "failed_amount" : amount_test_failure #
, "success_amount" : amount_test_success #
, "error_unittest" : self.true_if_error_in_tests(list_stats)
, "timing_test" : self.get_timing_test(list_stats)
, "date" : self.return_date() #
, "failed_test" : self.get_dict_failed_test(self.get_list_failure_test(list_test_name), list_failure_msg)
, "success_test" : list_success_tests #
}