import xlwt
from allpairspy import AllPairs
import re
def fread(file_path):
f = open(file_path, "r", encoding='utf-8')
data = f.readlines()
f.close()
return data
def parse(data):
col = []
parameters = []
for line in data:
a = line.strip('\n')
b = a.replace(' ', '')
col1 = re.split('[::]', b)[0]
col.append(col1)
c = b[b.rfind(':', 1) + 1:]
d = c[c.rfind(':', 1) + 1:]
e = re.split('[,,]', d)
parameters.append(e)
return parameters, col
def allpairs1(parameters):
p = []
print("PAIRWISE:")
for i, pairs in enumerate(AllPairs(parameters)):
if pairs[1] == '男' and pairs[0] == '张三':
continue
elif pairs[1] == '女' and pairs[0] == '张三':
continue
p.append(pairs)
return p
def allpairs(name, col, datalist):
book = xlwt.Workbook(encoding='utf-8', style_compression=0)
sheet = book.add_sheet(name, cell_overwrite_ok=True)
for i in range(0, len(col)):
sheet.write(0, i, col[i])
for i in range(0, len(datalist)):
data = datalist[i]
for j in range(0, len(col)):
sheet.write(i + 1, j, data[j])
savepath = r'{}.xls'.format(name)
book.save(savepath)
if __name__ == "__main__":
file_path = r'data1.txt'
parameters = parse(fread(file_path))[0]
col = parse(fread(file_path))[1]
datalist = allpairs1(parameters)
allpairs('测试用例', col, datalist)
|