Skip to content

Commit 1cd5547

Browse files
committed
修复bug
1 parent 572aaa0 commit 1cd5547

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

cyaron/compare.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def __init__(self, name, mismatch):
1515
super(CompareMismatch, self).__init__(name, mismatch)
1616
self.name = name
1717
self.mismatch = mismatch
18-
18+
1919
def __str__(self):
20-
return self.mismatch.__str__()
20+
return 'In program: \'{}\'. {}'.format(self.name,self.mismatch)
2121

2222

2323
class Compare:
@@ -114,7 +114,10 @@ def program(cls, *programs, **kwargs):
114114

115115
if std_program is not None:
116116
def get_std():
117-
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
118121
if job_pool is not None:
119122
std = job_pool.submit(get_std).result()
120123
else:
@@ -138,6 +141,7 @@ def do(program_name):
138141
content = make_unicode(subprocess.check_output(program_name, shell=(not list_like(program_name)), stdin=input_file, universal_newlines=True))
139142
else:
140143
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)
141145
cls.__compare_two(program_name, content, std, grader)
142146

143147
if job_pool is not None:

cyaron/graders/noipstyle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def noipstyle(content, std):
2424
std_lines[i][j:j + 5]))
2525
if len(std_lines[i]) > len(content_lines[i]):
2626
return False, TextMismatch(
27-
content, std, 'Too short on line {}.'.format(i), i + 1,
27+
content, std, 'Too short on line {}.'.format(i + 1), i + 1,
2828
j + 1, content_lines[i][j:j + 5], std_lines[i][j:j + 5])
2929
if len(std_lines[i]) < len(content_lines[i]):
3030
return False, TextMismatch(
31-
content, std, 'Too long on line {}.'.format(i), i + 1,
31+
content, std, 'Too long on line {}.'.format(i + 1), i + 1,
3232
j + 1, content_lines[i][j:j + 5], std_lines[i][j:j + 5])
3333

3434
return True, None

0 commit comments

Comments
 (0)