-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessTestPlan.py
More file actions
72 lines (54 loc) · 2.82 KB
/
ProcessTestPlan.py
File metadata and controls
72 lines (54 loc) · 2.82 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
import csv, os, sys
def dict_filter(it, *keys):
for d in it:
yield dict((k, d[k]) for k in keys)
thisdir = sys.path[0]
orig_file = raw_input("Enter Original Testplan File Name, including extension (should be .csv)")
orig_testplanfile = os.path.join(thisdir, orig_file)
results_file = raw_input("Enter Corresponding Testplan Results Name, including extension (should be .csv)")
results_testplanfile = os.path.join(thisdir, results_file)
#the output file assembles some of the original testplan info and merges it into the test plan results csv...
#this single file includes the original questions, Ids and expected results with the test plan responses for each test taker.
output_file = os.path.join(thisdir,"output",orig_file.split(".")[0] + "_results." + orig_file.split(".")[1])
#build list of headers in results
with open(results_testplanfile,'rb') as results:
headers = results.readline()
headerlist = headers.split(',')
#headers for the results file, only including 'name' and date' plus any data fields
resultsheaders = [s for s in headerlist if 'Name' in s or 'Date' in s or '_data' in s]
#headers for original
origheaders = ['Procedure_ID','Test_Procedure','Expected_Results']
#--------------------
#Remove extraneous data columns from test results csv.
results_filteredtestplanfile = os.path.join(thisdir,"output",orig_file.split(".")[0] + "_filter." + orig_file.split(".")[1])
f_in = open(results_testplanfile,'rb')
f_out = open(results_filteredtestplanfile,'wb')
reader = csv.DictReader(f_in)
writer = csv.DictWriter(f_out,resultsheaders,extrasaction='ignore')
writer.writerow(dict((fn,fn) for fn in resultsheaders))
for line in reader:
writer.writerow(line)
#transpose data in filtered test results csv, convert to list...
results_transposedtestplanfile = os.path.join(thisdir,"output",orig_file.split(".")[0] + "_transposed." + orig_file.split(".")[1])
f = csv.reader(open(results_filteredtestplanfile))
f_transposed = zip(*f)
f_transposed_list = []
count = len(f_transposed)
#Remove non-delimiting commas from the mix.
for item in f_transposed:
thisrow = list(item)
newrow = []
for value in thisrow:
newrow.append(value.replace(",", "- ")) #in case users use commas, we won't upset the comma-delimted format.
f_transposed_list.append(newrow)
#Open output csv file...
f_output = open(output_file, 'wb')
#open and read all testplan lines
f_testplan = open(orig_testplanfile)
testplan_lines = f_testplan.readlines()
i=0
while i < count:
#Write the original file info (ID,Procedure,Results) then the test results (Name, James, Aja, Travis, etc). The number of lines should match (skip the
f_output.write(testplan_lines[i].strip() + "," + ",".join(f_transposed_list[i][1:]) + "\n")
i += 1
f_output.close()