forked from ricardobranco777/hawk_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hawk_test_results.py
62 lines (54 loc) · 2.91 KB
/
hawk_test_results.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
#!/usr/bin/python3
# Copyright (C) 2019 SUSE LLC
"""Define classes and functions to handle results in HAWK GUI test"""
import time
import json
from hawk_test_driver import HawkTestDriver
from hawk_test_ssh import HawkTestSSH
class ResultSet:
def __init__(self):
self.my_tests = []
self.start_time = time.time()
for func in dir(HawkTestDriver):
if func.startswith('test_') and callable(getattr(HawkTestDriver, func)):
self.my_tests.append(func)
self.results_set = {'tests': [], 'info': {}, 'summary': {}}
for test in self.my_tests:
auxd = {'name': test, 'test_index': 0, 'outcome': 'failed'}
self.results_set['tests'].append(auxd)
self.results_set['info']['timestamp'] = time.time()
with open('/etc/os-release', encoding="utf-8") as file:
lines = file.read().splitlines()
osrel = {k: v[1:-1] for (k, v) in [line.split('=') for line in lines if '=' in line]}
self.results_set['info']['distro'] = osrel['PRETTY_NAME']
self.results_set['info']['results_file'] = 'hawk_test.results'
self.results_set['summary']['duration'] = 0
self.results_set['summary']['passed'] = 0
self.results_set['summary']['num_tests'] = len(self.my_tests)
def add_ssh_tests(self):
for func in dir(HawkTestSSH):
if func.startswith('verify_') and callable(getattr(HawkTestSSH, func)):
self.my_tests.append(func)
auxd = {'name': str(func), 'test_index': 0, 'outcome': 'failed'}
self.results_set['tests'].append(auxd)
self.results_set['summary']['num_tests'] = len(self.my_tests)
def logresults(self, filename):
with open(filename, "w", encoding="utf-8") as resfh:
resfh.write(json.dumps(self.results_set))
def set_test_status(self, testname, status):
if status not in ['passed', 'failed', 'skipped']:
raise ValueError('test status must be either [passed] or [failed]')
if status == 'passed' and \
self.results_set['tests'][self.my_tests.index(testname)]['outcome'] != 'passed':
self.results_set['summary']['passed'] += 1
elif status == 'failed' and \
self.results_set['tests'][self.my_tests.index(testname)]['outcome'] != 'failed':
self.results_set['summary']['passed'] -= 1
elif status == 'skipped' and \
self.results_set['tests'][self.my_tests.index(testname)]['outcome'] != 'skipped':
self.results_set['summary']['num_tests'] -= 1
self.results_set['tests'][self.my_tests.index(testname)]['outcome'] = status
self.results_set['summary']['duration'] = time.time() - self.start_time
self.results_set['info']['timestamp'] = time.time()
def get_failed_tests_total(self):
return self.results_set['summary']['num_tests'] - self.results_set['summary']['passed']