-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.py
62 lines (58 loc) · 2.02 KB
/
gen.py
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
import logging
logging.basicConfig(level=20)
def execute_test_steps(test:dict, retry:int) -> bool:
steps = (el for el in test.get("steps"))
for step in steps:
for i in range(retry):
try:
if get_step_results(step) == step.get("result"):
logging.info(f"Step {step.get('name')} was completed successfully after {i+1} try.")
break
else:
logging.warning(f"Step {step.get('name')} didn't generate expected result {step.get('result')} with params {step.get('params')}.")
except Exception as e:
logging.warning(f"Step {step.get('name')} generated the following exception:\n")
logging.exception(e)
continue
else:
logging.critical(f"Test failed at step {step.get('name')} after {retry} unsucessful tries.")
return False
logging.info("All tests' steps were completed successfully.")
return True
def get_step_results(step:dict) -> object:
method = step.get("method")
logging.info(f"Executing {method.__name__} with params {step.get('params')}")
return method.__call__(step.get("params"))
def is_equal(t:tuple) -> True:
return t[0] == t[1]
if __name__ == '__main__':
test = {
"steps": [
{
"name": "sum",
"method": sum,
"params": [1,2,3,4],
"result": 10
},
{
"name": "evaluation",
"method": eval,
"params": "14",
"result": 14
},
#{
# "name": "I'm supposed to fail.",
# "method": sum,
# "params": [1,2,3],
# "result": 7,
#}
{
"name": "Is equal",
"method": is_equal,
"params": (0,0),
"result": True
}
]
}
#import pdb;pdb.set_trace()
execute_test_steps(test, 3)