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

已更改

上级 ba7e78b0
......@@ -13,9 +13,9 @@
"problemMatcher": "$msCompile"
},
{
"label": "test",
"label": "local_test",
"type": "shell",
"command": "python ${workspaceFolder}/local_test_c.py",
"command": "python ${workspaceFolder}/local_test.py",
"args": [],
"group": "build",
"presentation": {
......
......@@ -10,9 +10,6 @@ import filecmp
import subprocess
import platform
# 使用此文件的目录作为当前工作目录
# os.chdir(os.path.dirname(__file__))
from colorama import Fore, init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
......@@ -88,9 +85,13 @@ def compare_file(file1, file2, seqNum, caseCount):
else:
score = score + 40 / caseCount * seqNum
promptInfo = "Case{0} 验证成功".format(seqNum)
outputPromptInfo(bIncludeCi, promptInfo, 1)
print("exec-score", round(score, 2))
if bIncludeCi :
promptInfo = "Case{0} 验证成功".format(seqNum)
outputPromptInfo(bIncludeCi, promptInfo, 1)
print("exec-score", int(score))
else:
promptInfo = "Case{0} 验证成功, 分数: {1}".format(seqNum, int(score))
outputPromptInfo(bIncludeCi, promptInfo, 1)
returnVal = 1
return returnVal
......@@ -124,13 +125,17 @@ def outputPromptInfo(bIncludeCi, promptInfo, color):
print(red(promptInfo))
elif color == 3:
print(yellow(promptInfo))
else:
print(promptInfo)
else:
if color == 1:
print(Fore.GREEN + promptInfo, file = stream)
elif color == 2:
print(Fore.RED + promptInfo, file = stream)
elif color == 3:
print(Fore.YELLOW + promptInfo, file = stream)
print(Fore.YELLOW + promptInfo, file = stream)
else:
print(promptInfo)
print(Fore.WHITE, file = stream)
sys.stdout.flush()
......@@ -140,18 +145,19 @@ if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "ci":
bIncludeCi = True
promptInfo = "提示:\n1.如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序,修改应用程序后再验证。\n2.如果提示‘python’不是内部或外部命令,也不是可运行的程序或批处理文件。需要设置 Python 的环境变量并重启开发环境来解决此问题。"
outputPromptInfo(bIncludeCi, promptInfo, 3)
print("开发环境中的 Python 解释器版本号:" + platform.python_version())
print("环境变量中的 Python 解释器版本号:", end=' ')
sys.stdout.flush()
execResult = os.system("python --version")
if execResult != 0:
errorInfo = "应用程序异常,返回值:{0}。".format(execResult)
outputPromptInfo(bIncludeCi, errorInfo, 2)
if bIncludeCi == False:
promptInfo = "提示:\n1.如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序,修改应用程序后再验证。\n2.如果提示‘python’不是内部或外部命令,也不是可运行的程序或批处理文件。需要设置 Python 的环境变量并重启开发环境来解决此问题。"
outputPromptInfo(bIncludeCi, promptInfo, 3)
print("开发环境中的 Python 解释器版本号:" + platform.python_version())
print("环境变量中的 Python 解释器版本号:", end=' ')
sys.stdout.flush()
execResult = os.system("python --version")
if execResult != 0:
errorInfo = "应用程序异常,返回值:{0}。".format(execResult)
outputPromptInfo(bIncludeCi, errorInfo, 2)
exit(1)
exit(1)
print()
compResultFile = "result_comparation.html"
......@@ -166,6 +172,8 @@ if __name__ == "__main__":
if os.path.isfile(execFile):
os.remove(execFile)
promptInfo = "正在使用make生成项目"
outputPromptInfo(bIncludeCi, promptInfo, 1)
execResult = os.system("make")
if execResult != 0:
......@@ -173,12 +181,18 @@ if __name__ == "__main__":
outputPromptInfo(bIncludeCi, errorInfo, 2)
exit(1)
else:
promptInfo = "项目生成成功"
outputPromptInfo(bIncludeCi, promptInfo, 1)
promptInfo = "exec-score {0}".format(60)
score = 60
if not os.path.isfile("output1.txt"):
promptInfo = "exec-score {0}".format(100)
print(promptInfo)
score = 100
if bIncludeCi:
promptInfo = "项目生成成功"
outputPromptInfo(bIncludeCi, promptInfo, 1)
promptInfo = "exec-score {0}".format(score)
print(promptInfo)
else:
promptInfo = "项目生成成功, 分数 {0}".format(score)
outputPromptInfo(bIncludeCi, promptInfo, 1)
# 获取case的数量
caseCount = 1
......@@ -210,6 +224,10 @@ if __name__ == "__main__":
runCommand = "./app.exe < {0} > {1}".format(inputFile, useroutputFile)
if platform.system().lower() == 'windows':
runCommand = "app.exe < {0} > {1}".format(inputFile, useroutputFile)
promptInfo = "执行的命令是: {0}".format(runCommand)
outputPromptInfo(bIncludeCi, promptInfo, 0)
execResult = os.system(runCommand)
if execResult != 0:
errorInfo = "应用程序执行异常,返回值:{0}。".format(execResult)
......@@ -218,7 +236,6 @@ if __name__ == "__main__":
if os.path.isfile(outputFile) and os.path.isfile(useroutputFile):
if compare_file(outputFile, useroutputFile, seqNum, caseCount) == 0:
# runCommand = "code --diff {0} {1}".format(outputFile, useroutputFile)
if bIncludeCi :
runCommand = "diff {0} {1} -b -B -y -i -W 100".format(outputFile, useroutputFile)
execResult = os.system(runCommand)
......@@ -226,10 +243,7 @@ if __name__ == "__main__":
errorInfo = "输出结果比较异常,返回值:{0}。".format(execResult)
outputPromptInfo(bIncludeCi, errorInfo, 2)
else:
promptInfo("注意:如果读者是在jupyterlab中完成实验,请使用以下方式打开文件比较结果:\n\
选择View菜单中的Explorer菜单项,在打开的文件列表中,右击result_comparation.html文件,\n\
在弹出的菜单中选择“Open Preview”菜单项,可以打开文件比较结果,可帮助用户查找验证失败的原因。")
outputPromptInfo(bIncludeCi, errorInfo, 3)
webbrowser.open('file://' + os.path.realpath(compResultFile))
promptInfo = "提示:\n请使用以下方式打开文件的比较结果:\n选择View菜单中的Explorer菜单项,在打开的文件列表中,右击result_comparation.html文件,\n在弹出的菜单中选择\“Open Preview\”菜单项,可以打开比较结果输出文件,可帮助用户查找验证失败的原因。"
outputPromptInfo(bIncludeCi, promptInfo, 2)
exit(1)
seqNum = seqNum + 1
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论