Skip to content

Commit 4eefc6c

Browse files
author
Toto Lin
authored
Merge pull request #39 from Himself65/master
修复对拍器比较异常问题
2 parents cd3dfb9 + d649b3e commit 4eefc6c

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

cyaron/compare.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def __init__(self, name, mismatch):
1616
self.name = name
1717
self.mismatch = mismatch
1818

19+
def __str__(self):
20+
return 'In program: \'{}\'. {}'.format(self.name,self.mismatch)
21+
1922

2023
class Compare:
2124
@staticmethod
@@ -111,7 +114,10 @@ def program(cls, *programs, **kwargs):
111114

112115
if std_program is not None:
113116
def get_std():
114-
return make_unicode(subprocess.check_output(std_program, shell=(not list_like(std_program)), stdin=input.input_file, universal_newlines=True))
117+
with open(os.dup(input.input_file.fileno()), 'r', newline='\n') as input_file:
118+
content = make_unicode(subprocess.check_output(std_program, shell=(not list_like(std_program)), stdin=input.input_file, universal_newlines=True))
119+
input_file.seek(0)
120+
return content
115121
if job_pool is not None:
116122
std = job_pool.submit(get_std).result()
117123
else:
@@ -135,6 +141,7 @@ def do(program_name):
135141
content = make_unicode(subprocess.check_output(program_name, shell=(not list_like(program_name)), stdin=input_file, universal_newlines=True))
136142
else:
137143
content = make_unicode(subprocess.check_output(program_name, shell=(not list_like(program_name)), stdin=input_file, universal_newlines=True, timeout=timeout))
144+
input_file.seek(0)
138145
cls.__compare_two(program_name, content, std, grader)
139146

140147
if job_pool is not None:

cyaron/graders/noipstyle.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@ def noipstyle(content, std):
1414
if std_lines[i] != content_lines[i]:
1515
for j in range(min(len(std_lines[i]), len(content_lines[i]))):
1616
if std_lines[i][j] != content_lines[i][j]:
17-
return (False, TextMismatch(content, std, 'On line {} column {}, read {}, expected {}.',
18-
i + 1, j + 1, content_lines[i][j:j + 5], std_lines[i][j:j + 5]))
17+
return (False,
18+
TextMismatch(
19+
content, std,
20+
'On line {} column {}, read {}, expected {}.',
21+
i + 1, j + 1, content_lines[i][j:j + 5],
22+
std_lines[i][j:j + 5]))
1923
if len(std_lines[i]) > len(content_lines[i]):
20-
return False, TextMismatch(content, std, 'Too short on line {}.', i)
24+
return False, TextMismatch(
25+
content, std, 'Too short on line {}.', i + 1, j + 1,
26+
content_lines[i][j:j + 5], std_lines[i][j:j + 5])
2127
if len(std_lines[i]) < len(content_lines[i]):
22-
return False, TextMismatch(content, std, 'Too long on line {}.', i)
28+
return False, TextMismatch(
29+
content, std, 'Too long on line {}.', i + 1, j + 1,
30+
content_lines[i][j:j + 5], std_lines[i][j:j + 5])
2331

2432
return True, None

0 commit comments

Comments
 (0)