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

已更改

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