以下代码按预期工作。正如我已经使用InputStr.txt
,我已经填充了一些语句并通过添加那些InputStr.txt语句生成Output.txt,无论是PASS还是FAIL。
Python代码:
str = "FAIL";
flag = False;
resultList = [];
#Here InputStr.txt is the file where all your output format strings are stored.
Stringlines = [line.strip() for line in open('InputStr.txt')]
out_file = open("Output.txt", "w")
for i in range (1,3):
fileName1 = "./largeFile%d.txt"%i
print fileName1;
fileName2 = "./largeFile_%d.txt"%i
with open(fileName1, 'r') as inF1:
for line in inF1:
if 'VERSION' in line:
print "VERSION FOUND";
flag = True;
if flag:
with open(fileName2, 'r') as inF2:
for line in inF2:
if 'ID' in line:
print "ID FOUND";
str = "PASS";
resultList.append(str);
out_file.write("\n %s - %s" %(Stringlines[i-1],resultList[i-1]))
out_file.close()
我得到的输出:
Output in Output.txt is:*
TEST CASE-1 PASS
TEST CASE-2 PASS
TEST CASE-3 PASS
我正在尝试打印TC1应该通过4TC应该通过,因为这些4TC我从另一个InputStr2.txt。
示例:
InputStr.txt包含以下语句:
Req 1. How How are you
Req 2. I am Fine and Thanks.
Req 3. How are you doing
InputStr2.txt包含:
TC1: ABCDEFGHIJ
TC2: KLMNOPQRST
TC3: UVWXYZABCD
TC4: EFGHIJKLMN
所以期望的输出是:
Req 1. How How are you - PASS
Req 2. I am Fine and Thanks. - PASS
Req 3. How are you doing - PASS
首先TC1到TC4的所有测试用例都应该通过(在InputStr2.txt中),然后只有我的Req 1才能通过。手段,在Output.txt我打印所有要求是通过或失败。
逻辑/建议吗?