forked from xurongzhong/mobile_data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test_cases_data.py
87 lines (70 loc) · 2.59 KB
/
parse_test_cases_data.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: xurongzhong#126.com wechat:pythontesting qq:37391319
# CreateDate: 2018-1-8
# parse_test_cases_data.py
'''
汇总测试用例生成的数据。
使用方法:
参数input_directory:为包含测试结果的目录。input_directory下面有测试人员的拼音名目录,
拼音名目录下有数字目录,比如01,对应测试用用例的序号。01目录下面有log.xls之类的测试记录
文件。
参数:output:为汇总测试的输出文件。
'''
import traceback
import re
import shutil
import os
import pandas
from data_common import maps, produce_xls
input_directory = r"D:\test"
output = r"D:\output.xls"
file_type = "xls"
def get_result(file_name, type_=0):
'''
统计测试工具生成的用例。
'''
try:
if file_name.endswith('csv'):
records = pandas.read_csv(file_name)
else:
records = pandas.read_excel(file_name)
total = len(records)
compare = len(records[records['比对'] == '通过'])
live = len(records[records['活体'] == '通过'])
eye = len(records[records['睁闭眼'] == '通过'])
success = len(records[records['结果'] == '通过'])
test = len(records[records['当前尝试次数'] == 1])
except Exception as info:
print('Error in reading: {}'.format(file_name))
print(info)
traceback.print_exc()
print('continue...')
total = compare = live = eye = success = test = 0
if type_ != 0 :
print(records)
return (total, compare, live, eye, success, test)
else:
return (total, compare, live, success, test)
def get_results(input_directory,file_name='xls', type_=0):
# 遍历目录以统计测试工具生成的xls文件
results = {}
for root, dirs, files in os.walk(input_directory):
for file_name in files:
if file_name.endswith(file_type):
seq = int(root.split(os.sep)[-1].lstrip('0'))
result = get_result(
u"{}{}{}".format(root, os.sep, file_name),type_)
if seq not in results:
results[seq] = []
results[seq].append(result)
if str(seq) not in file_name:
os.chdir(root)
shutil.move(file_name, u"{}_{}".format(seq, file_name))
return results
results = get_results(input_directory,type_=0)
print(results)
produce_xls(results, output, 50, type_=0)
#results = get_results(input_directory,type_=1)
#print(results)
#produce_xls(results, output, 76, type_=1)