Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
test-vscode-c-win
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸大学计算机学院
教师群组
赵鹏翀-zpc
test-vscode-c-win
提交
13c7e432
提交
13c7e432
3月 22, 2021
创建
作者:
305350171@qq.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
fba5c4fe
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
23 行增加
和
21 行删除
+23
-21
.gitignore
.gitignore
+2
-3
.gitlab-ci.yml
.gitlab-ci.yml
+0
-2
test.py
test.py
+21
-16
没有找到文件。
.gitignore
浏览文件 @
13c7e432
*.exe
*.o
*.bak
checkgituserconfig.py
checkgituserconfig.sh
\ No newline at end of file
result_comparation.html
\ No newline at end of file
.gitlab-ci.yml
浏览文件 @
13c7e432
...
...
@@ -5,8 +5,6 @@ stages:
-
case1
-
code-analysis
variables
:
TEACHERCHECK_REPO
:
"
engintime/cpp-lab/teachers-packet/c-language/Lab011.git"
...
...
test.py
浏览文件 @
13c7e432
...
...
@@ -69,7 +69,7 @@ def advanced_file_compare(file1, file2):
return
returnVal
# 比较两个文件并把结果生成一份html文本
def
compare_file
(
file1
,
file2
,
seqNum
,
caseCount
):
def
compare_file
(
file1
,
file2
,
seqNum
,
caseCount
,
bIncludeCi
):
returnVal
=
0
if
file1
==
""
or
file2
==
""
:
print
(
'文件路径不能为空:第一个文件的路径:{0}, 第二个文件的路径:{1} .'
.
format
(
file1
,
file2
))
...
...
@@ -100,20 +100,25 @@ def compare_file(file1, file2, seqNum, caseCount):
promptInfo
=
"Case{0} 验证失败"
.
format
(
seqNum
)
outputPromptInfo
(
bIncludeCi
,
promptInfo
,
2
)
text1_lines
=
read_file
(
file1
)
text2_lines
=
read_file
(
file2
)
diff
=
difflib
.
HtmlDiff
()
# 创建HtmlDiff 对象
result
=
diff
.
make_file
(
text1_lines
,
text2_lines
)
# 通过make_file 方法输出 html 格式的对比结果
# 将结果写入到result_comparation.html文件中
try
:
with
open
(
'result_comparation.html'
,
'a+'
,
encoding
=
"utf-8"
)
as
result_file
:
promptContent
=
"<p>Case {0} 验证失败。使用的标准输入文件是 intput{0}.txt。</br>标准答案输出文件 output{0}.txt(左边)与用户编写的应用程序输出文件 user_output{0}.txt(右边)的比较结果:</p>"
.
format
(
seqNum
)
result
=
promptContent
+
result
result_file
.
write
(
result
)
except
IOError
as
error
:
print
(
'写入html文件错误:{0}'
.
format
(
error
))
finally
:
return
returnVal
if
bIncludeCi
==
False
:
text1_lines
=
read_file
(
file1
)
text2_lines
=
read_file
(
file2
)
diff
=
difflib
.
HtmlDiff
()
# 创建HtmlDiff 对象
result
=
diff
.
make_file
(
text1_lines
,
text2_lines
)
# 通过make_file 方法输出 html 格式的对比结果
# 将结果写入到result_comparation.html文件中
try
:
with
open
(
'result_comparation.html'
,
'a+'
,
encoding
=
"utf-8"
)
as
result_file
:
promptContent
=
"<p>Case {0} 验证失败。使用的标准输入文件是 intput{0}.txt。</br>标准答案输出文件 output{0}.txt(左边)与用户编写的应用程序输出文件 user_output{0}.txt(右边)的比较结果:</p>"
.
format
(
seqNum
)
result
=
promptContent
+
result
result_file
.
write
(
result
)
except
IOError
as
error
:
print
(
'写入html文件错误:{0}'
.
format
(
error
))
finally
:
return
returnVal
else
:
returnVal
# 1表示绿色,2表示红色,3表示黄色
def
outputPromptInfo
(
bIncludeCi
,
promptInfo
,
color
):
...
...
@@ -236,7 +241,7 @@ if __name__ == "__main__":
exit
(
1
)
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
,
bIncludeCi
)
==
0
:
if
bIncludeCi
:
print
(
"使用的标准输入文件是 intput{0}.txt。
\n
标准答案输出文件 output{1}.txt(左边)与用户编写的应用程序输出文件 user_output{2}.txt(右边)的比较结果:"
.
format
(
seqNum
,
seqNum
,
seqNum
))
runCommand
=
"diff {0} {1} -b -B -y -i -W 100"
.
format
(
outputFile
,
useroutputFile
)
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论