我有一个如下所示的测试输出csv;
test1 test success
test2 test failed
regtest failed to build
列1包含唯一的字符串,列2包含以下三个字符串之一;测试成功,测试失败,构建失败。
我经常在新版本上运行此测试,我想将最新测试中的csv与先前测试进行比较。 我想产生一个包含状态(第2列)已更改的所有测试的新csv。最好采用以下格式:
TestName OldState NewState
这是我当前的尝试,它获取了两个文件之间的所有差异,但看起来像这样;
test1 test success
test2 test failed
regtest failed to build
test2 test success
我需要一种将第二个test2与第一个test2合并的方法,看起来像这样;
test1 test success
test2 test failed test success
regtest failed to build
我当前的代码;
import csv
import sys
with open(sys.argv[1], 'r') as t1, open(sys.argv[2], 'r') as t2, open(sys.argv[2], 'r') as t3, open(sys.argv[1], 'r') as t4:
fileOne = t1.readlines()
fileTwo = t2.readlines()
fileThree = t3.readlines()
fileFour = t4.readlines()
with open(sys.argv[3], 'w') as outFile:
for line in fileTwo:
if line not in fileOne:
outFile.write("From File 2," + line)
for line in fileFour:
if line not in fileThree:
outFile.write("\r\nFrom File 1," + line)