-
Notifications
You must be signed in to change notification settings - Fork 1
/
qa_test_log.py
89 lines (71 loc) · 3.11 KB
/
qa_test_log.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
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
import sys
import os
from qa_common import *
from pathlib import Path
class QATestLog(object):
def __init__(self,root_dir,incremental_testing):
self.successful_tests = root_dir+'/successful_tests.log'
self.successful_regression_tests = root_dir+'/successful_regression_tests.log'
self.failed_tests = root_dir+'/failed_tests.log'
self.unrun_tests = root_dir+'/unrun_tests.log'
self.past_tests = None
self.past_regression_tests = None
self.directory_dict = {}
# initialize each file
if incremental_testing:
with open(self.successful_tests,'r') as f:
self.past_tests = set(f)
with open(self.successful_regression_tests,'r') as f:
self.past_regression_tests = set(f)
open(self.successful_tests,'w').close()
open(self.successful_regression_tests,'w').close()
open(self.failed_tests,'w').close()
open(self.unrun_tests,'w').close()
def log_success(self,path,test):
with open(self.successful_tests,"a+") as f:
f.write('{}/{} \n'.format(path,test))
def log_regression(self,path,test):
with open(self.successful_regression_tests,"a+") as f:
f.write('{}/{} \n'.format(path,test))
def log_failure(self,path,test):
with open(self.fauled_tests,"a+") as f:
f.write('{}/{} \n'.format(path,test))
def log_unrun(self,path,test):
with open(unrun_tests,"a+") as f:
f.write('{}/{} \n'.format(path,test))
def log_directory_names(self,directory_title,path):
self.directory_dict[path] = directory_title
def get_directory_titles(self):
return self.directory_dict
def _copy_contents_to_file(self,file_to_read,file_to_write):
with open(file_to_read, "r") as f1:
with open(file_to_write, "a+") as f2:
for line in f1:
f2.write(line)
def read_contents(self,regression=False):
if regression:
tests = self.successful_regression_tests
past_tests = self.past_regression_tests
else:
tests = self.successful_tests
past_tests = self.past_tests
log_dict = {}
if past_tests:
for val in past_tests:
match = False
with open(tests,'r+') as f:
for line in f:
if line.strip() == val.strip():
match = True
if not match:
f.write('{} \n'.format(val.strip()))
with open(tests,'r') as f:
for line in f:
tests = line.strip().split('/')
s = '/'
folder_path = s.join(tests[0:-1])
if folder_path in log_dict.keys():
log_dict[folder_path].append(tests[-1])
else:
log_dict[folder_path] = [tests[-1]]
return log_dict