2
2
from cyaron .consts import *
3
3
from cyaron .graders import CYaRonGraders
4
4
import subprocess
5
+ import sys
6
+ import io
5
7
6
8
7
9
class Compare :
8
10
@staticmethod
9
- def __compare_two (name , content , std , grader ):
11
+ def __compare_two (name , content , std , grader , ** kwargs ):
10
12
(result , info ) = CYaRonGraders .invoke (grader , content , std )
11
13
12
14
info = info if info is not None else ""
13
15
status = "Correct" if result else "!!!INCORRECT!!!"
14
16
print ("%s: %s %s" % (name , status , info ))
15
17
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
+
16
36
@staticmethod
17
37
def __process_file (file ):
18
38
if isinstance (file , IO ):
@@ -33,10 +53,11 @@ def output(*args, **kwargs):
33
53
(_ , std ) = Compare .__process_file (kwargs ["std" ])
34
54
35
55
grader = kwargs .get ("grader" , DEFAULT_GRADER )
56
+ stop_on_incorrect = kwargs .get ("stop_on_incorrect" , False )
36
57
37
58
for file in args :
38
59
(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 )
40
61
41
62
@staticmethod
42
63
def program (* args , ** kwargs ):
@@ -61,9 +82,15 @@ def program(*args, **kwargs):
61
82
(_ , std ) = Compare .__process_file (kwargs ["std" ])
62
83
63
84
grader = kwargs .get ("grader" , DEFAULT_GRADER )
85
+ stop_on_incorrect = kwargs .get ("stop_on_incorrect" , False )
64
86
65
87
for program_name in args :
88
+ input .input_file .seek (0 )
66
89
content = subprocess .check_output (program_name , shell = True , stdin = input .input_file )
67
- Compare .__compare_two (program_name , content , std , grader )
68
90
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
69
95
96
+ input .input_file .seek (0 , 2 )
0 commit comments