def test_noipstyle_incorrect(self): io = None with captured_output() as (out, err): io = IO("test_compare_incorrect.in", "test_compare_incorrect.out") io.output_writeln("test123 \ntest123\n") with open("test_another_incorrect.out", "w") as f: f.write("test123\r\ntest124 ") try: with captured_output() as (out, err): Compare.output("test_another_incorrect.out", std=io) except CompareMismatch as e: self.assertEqual(e.name, 'test_another_incorrect.out') e = e.mismatch self.assertEqual(e.content, 'test123\r\ntest124 ') self.assertEqual(e.std, 'test123 \ntest123\n\n') self.assertEqual(str(e), 'On line 2 column 7, read 4, expected 3.') else: self.assertTrue(False) result = out.getvalue().strip() self.assertEqual( result, "test_another_incorrect.out: !!!INCORRECT!!! " "On line 2 column 7, read 4, expected 3.")
def test_concurrent(self): programs = ['test{}.py'.format(i) for i in range(16)] for fn in programs: with open(fn, 'w') as f: f.write('print({})'.format(16)) with open('std.py', 'w') as f: f.write('print({})'.format(16)) with IO() as test: Compare.program(*[(sys.executable, prog) for prog in programs], std_program=(sys.executable, 'std.py'), max_workers=None, input=test) ios = [IO() for i in range(16)] try: for f in ios: f.output_write('16') with IO() as std: std.output_write('16') Compare.output(*ios, std=std, max_workers=None) finally: for io in ios: io.close()
def test_noipstyle_correct(self): io = None with captured_output() as (out, err): io = IO("test_compare.in", "test_compare.out") io.output_writeln("test123 \ntest123\n") with open("test_another.out", "w") as f: f.write("test123\r\ntest123 ") with captured_output() as (out, err): Compare.output("test_another.out", std=io) result = out.getvalue().strip() self.assertEqual(result, "test_another.out: Correct")
def test_noipstyle_incorrect(self): io = None with captured_output() as (out, err): io = IO("test_compare_incorrect.in", "test_compare_incorrect.out") io.output_writeln("test123 \ntest123\n") with open("test_another_incorrect.out", "w") as f: f.write("test123\r\ntest124 ") with captured_output() as (out, err): Compare.output("test_another_incorrect.out", std=io) result = out.getvalue().strip() self.assertEqual( result, "test_another_incorrect.out: !!!INCORRECT!!! On line 2 column 7, read 4, expected 3." )
def test_noipstyle_incorrect(self): io = None with captured_output() as (out, err): io = IO("test_compare_incorrect.in", "test_compare_incorrect.out") io.output_writeln("test123 \ntest123\n") with open("test_another_incorrect.out", "wb") as f: f.write(b"test123\r\ntest124 ") try: with captured_output() as (out, err): Compare.output("test_another_incorrect.out", std=io) except CompareMismatch as e: self.assertEqual(e.name, 'test_another_incorrect.out') e = e.mismatch self.assertEqual(e.content, 'test123\r\ntest124 ') # AssertionError self.assertEqual(e.std, 'test123 \ntest123\n\n') # AssertionError self.assertEqual( str(e), 'On line 2 column 7, read 4, expected 3.') # AssertionError # try: # self.assertEqual(e.content, 'test123\r\ntest124 ') # self.assertEqual(e.std, 'test123 \ntest123\n\n') # self.assertEqual(str(e), 'On line 2 column 7, read 4, expected 3.') # except AssertionError: # pass # # TODO... # # When this file run in python3.7, the function will throw AssertionError else: self.assertTrue(False) result = out.getvalue().strip() self.assertEqual( result, "test_another_incorrect.out: !!!INCORRECT!!! On line 2 column 7, read 4, expected 3." )