22from cyaron .consts import *
33from cyaron .graders import CYaRonGraders
44import subprocess
5+ import sys
6+ import io
57
68
79class Compare :
810 @staticmethod
9- def __compare_two (name , content , std , grader ):
11+ def __compare_two (name , content , std , grader , ** kwargs ):
1012 (result , info ) = CYaRonGraders .invoke (grader , content , std )
1113
1214 info = info if info is not None else ""
1315 status = "Correct" if result else "!!!INCORRECT!!!"
1416 print ("%s: %s %s" % (name , status , info ))
1517
18+ stop_on_incorrect = kwargs .get ("stop_on_incorrect" , False )
19+ custom_dump_data = kwargs .get ("dump_data" , None )
20+ if stop_on_incorrect and not result :
21+ if custom_dump_data :
22+ (dump_name , dump_lambda ) = custom_dump_data
23+ with open (dump_name , "w" ) as f :
24+ f .write (dump_lambda ())
25+
26+ with open ("std.out" , "w" ) as f :
27+ f .write (std )
28+ with open ("%s.out" % name , "w" ) as f :
29+ f .write (content )
30+
31+ print ("Relevant files dumped." )
32+
33+ sys .exit (0 )
34+
35+
1636 @staticmethod
1737 def __process_file (file ):
1838 if isinstance (file , IO ):
@@ -33,10 +53,11 @@ def output(*args, **kwargs):
3353 (_ , std ) = Compare .__process_file (kwargs ["std" ])
3454
3555 grader = kwargs .get ("grader" , DEFAULT_GRADER )
56+ stop_on_incorrect = kwargs .get ("stop_on_incorrect" , False )
3657
3758 for file in args :
3859 (file_name , content ) = Compare .__process_file (file )
39- Compare .__compare_two (file_name , content , std , grader )
60+ Compare .__compare_two (file_name , content , std , grader , stop_on_incorrect = stop_on_incorrect )
4061
4162 @staticmethod
4263 def program (* args , ** kwargs ):
@@ -61,9 +82,15 @@ def program(*args, **kwargs):
6182 (_ , std ) = Compare .__process_file (kwargs ["std" ])
6283
6384 grader = kwargs .get ("grader" , DEFAULT_GRADER )
85+ stop_on_incorrect = kwargs .get ("stop_on_incorrect" , False )
6486
6587 for program_name in args :
88+ input .input_file .seek (0 )
6689 content = subprocess .check_output (program_name , shell = True , stdin = input .input_file )
67- Compare .__compare_two (program_name , content , std , grader )
6890
91+ input .input_file .seek (0 )
92+ Compare .__compare_two (program_name , content , std , grader ,
93+ stop_on_incorrect = stop_on_incorrect ,
94+ dump_data = ("error_input.in" , lambda : input .input_file .read ())) # Lazy dump
6995
96+ input .input_file .seek (0 , 2 )
0 commit comments