提交 fb01b31c 创建 作者: 宋海霞's avatar 宋海霞

modify

上级 197b5992
流水线 #156444 已失败 于阶段
用时 10 秒
......@@ -34,15 +34,22 @@ if bCI == False:
"************************************************************\n"
)
if bCI == False:
from colorama import Fore, init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
from colorama import Fore, init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
red = lambda text: '\033[0;31;1m' + text + '\033[0m'
green = lambda text: '\033[0;32;1m' + text + '\033[0m'
yellow = lambda text: '\033[0;33;1m' + text + '\033[0m'
def advanced_dat_file_compare(file1, file2):
returnVal = 1
runCommand = "diff {0} {1} -b -B -y -i -W 100".format(file1, file2)
execResult = os.system(runCommand)
if execResult != 0:
returnVal = 0
return returnVal
# 比较两个文件并把结果生成一份html文本
def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
returnVal = 0
......@@ -52,7 +59,14 @@ def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
else:
print("正在比较标准答案结果文件 {0} 和用户编写的应用程序结果文件 {1}".format(file1, file2), end=': ')
if os.path.isfile(file1) and os.path.isfile(file2) and advanced_file_compare(file1, file2):
if os.path.isfile(file1) and os.path.isfile(file2):
comResult = 0
if resultFileType == ResultFileType.writedat:
comResult = advanced_dat_file_compare(file1, file2)
else:
comResult = advanced_file_compare(file1, file2)
if comResult:
print("文件相同")
score = 40
if seqNum == caseCount:
......@@ -62,22 +76,22 @@ def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
if bCI :
promptInfo = "Case{0} 验证成功".format(seqNum)
#outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo(bCI, promptInfo, Color.green)
print("exec-score", int(score))
else:
promptInfo = "Case{0} 验证成功, 分数: {1}".format(seqNum, int(score))
#outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo(bCI, promptInfo, Color.green)
if seqNum == caseCount:
promptInfo = "恭喜你通过了所有测试!"
#outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo(bCI, promptInfo, Color.green)
returnVal = 1
return returnVal
else:
print("文件不同")
promptInfo = "Case{0} 验证失败".format(seqNum)
#outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo(bCI, promptInfo, Color.green)
if bCI == False and resultFileType != ResultFileType.writedat:
text1_lines = read_file(file1)
......@@ -100,9 +114,9 @@ def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
else:
return returnVal
if bCI == False:
# 1表示绿色,2表示红色,3表示黄色
def outputPromptInfo(bCI, promptInfo, color):
def outputPromptInfo(bCI, promptInfo, color):
if bCI :
if color == Color.green:
......@@ -132,35 +146,31 @@ if __name__ == "__main__":
os.remove(compResultFile)
promptInfo = "正在使用 makefile 文件生成项目"
# outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo(bCI, promptInfo, Color.green)
execResult = os.system("make")
if execResult != 0:
errorInfo = "生成项目失败"
# outputPromptInfo(bCI, errorInfo, Color.red)
outputPromptInfo(bCI, errorInfo, Color.red)
exit(1)
else:
score = 40
if not (os.path.isfile("output1.txt") or os.path.isfile("writefile1.txt") or os.path.isfile("writefile1.dat")):
if not (os.path.isfile("output1.txt") or not os.path.isfile("writefile1.txt") or not os.path.isfile("writefile1.dat")):
score = 100
if bCI:
promptInfo = "生成项目成功"
# outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo(bCI, promptInfo, Color.green)
promptInfo = "exec-score {0}".format(score)
print(promptInfo)
else:
promptInfo = "生成项目成功, 分数 {0}".format(score)
# outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo(bCI, promptInfo, Color.green)
dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr = getProjInfo()
# resultFileType = getResultFileType()
if resultFileType == ResultFileType.nooutput:
exit(0)
# resultFileStr = getResultFileStr(resultFileType)
# userresultFileStr = getUserResultFileStr(resultFileType)
# 获取case的数量
caseCount = 1
while 1:
......@@ -170,8 +180,6 @@ if __name__ == "__main__":
break
caseCount += 1
# dsType = getDataSourceFileType()
# dsFileStr = getDataSourceFileStr(dsType)
seqNum = 1
while 1:
dsFile = dsFileStr.format(seqNum)
......@@ -181,9 +189,9 @@ if __name__ == "__main__":
promptInfo = "该项目未提供自动化验证功能"
if bCI :
print(red(promptInfo))
# else:
# print(Fore.RED + "该项目未提供自动化验证功能", file = stream, end='')
# print(Fore.WHITE, file = stream)
else:
print(Fore.RED + "该项目未提供自动化验证功能", file = stream, end='')
print(Fore.WHITE, file = stream)
break
if not os.path.isfile(resultFile):
break
......@@ -202,16 +210,16 @@ if __name__ == "__main__":
runCmdStr =getRunProgCmdStr(dsType, resultFileType, dsFile, userresultFile)
promptInfo = "正在执行命令: {0}".format(runCmdStr)
# outputPromptInfo(bCI, promptInfo, Color.white)
outputPromptInfo(bCI, promptInfo, Color.white)
if bCI == False:
promptInfo = "提示:如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序(Ctrl+c),修改应用程序后再验证。"
# outputPromptInfo(bCI, promptInfo, Color.yellow)
outputPromptInfo(bCI, promptInfo, Color.yellow)
execResult = os.system(runCmdStr)
if execResult != 0:
errorInfo = "应用程序执行异常,返回值:{0}。".format(execResult)
# outputPromptInfo(bCI, errorInfo, Color.red)
outputPromptInfo(bCI, errorInfo, Color.red)
exit(1)
if os.path.isfile(resultFile) and os.path.isfile(userresultFile):
......@@ -221,13 +229,16 @@ if __name__ == "__main__":
print("使用的数据源文件是 {0}。".format(dsFile))
print("标准答案结果文件 {0}(左边)与用户编写的应用程序结果文件 {1}(右边)的比较结果:".format(resultFile, userresultFile))
sys.stdout.flush()
runCommand = "diff {0} {1} -b -B -y -i -W 100".format(resultFile, userresultFile)
execResult = os.system(runCommand)
if execResult != 0:
print()
exit(1)
else:
if resultFileType != 3:
promptInfo = "查看文件比较结果可帮助你查找验证失败的原因。方法是:\n选择 View 菜单中的 Explorer 打开文件列表,右键点击 result_comparation.html 文件,在弹出的菜单中选择 Open Preview"
# outputPromptInfo(bCI, promptInfo, Color.red)
outputPromptInfo(bCI, promptInfo, Color.red)
else:
print("选择 View 菜单中的 Explorer 打开文件列表,右键点击 writefile*.dat文件或user_writefile*.dat文件,在弹出的菜单中选择 Open With...,再选择 Hex Editor ")
exit(1)
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论