Skip to content

Commit 581b666

Browse files
committed
Added testcase for Compare with IO
1 parent 009b0dd commit 581b666

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cyaron/compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def program(cls, *programs, **kwargs):
115115
if std_program is not None:
116116
def get_std():
117117
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))
118+
content = make_unicode(subprocess.check_output(std_program, shell=(not list_like(std_program)), stdin=input.input_file, universal_newlines=True))
119119
input_file.seek(0)
120120
return content
121121
if job_pool is not None:

cyaron/tests/compare_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ def test_fulltext_program(self):
9292
correct_out = 'python correct.py: Correct \npython incorrect.py: !!!INCORRECT!!! Hash mismatch: read 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3, expected 4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865'
9393
self.assertEqual(result, correct_out)
9494

95+
def test_file_input(self):
96+
with open("correct.py", "w") as f:
97+
f.write("print(input())")
98+
99+
with open("std.py", "w") as f:
100+
f.write("print(input())")
101+
102+
io = None
103+
with captured_output() as (out, err):
104+
io = IO()
105+
106+
io.input_writeln("233")
107+
108+
with captured_output() as (out, err):
109+
Compare.program("python correct.py", std_program="python std.py", input=io, grader="NOIPStyle")
110+
111+
result = out.getvalue().strip()
112+
correct_out = 'python correct.py: Correct'
113+
self.assertEqual(result, correct_out)
114+
95115
def test_concurrent(self):
96116
programs = ['test{}.py'.format(i) for i in range(16)]
97117
for fn in programs:

0 commit comments

Comments
 (0)