Mercurial > ~astiob > upreckon > hgweb
annotate testcases.py @ 143:92f76baebcc6
Corrected mixed indentation (and a few line lengths) in compat.py
| author | Oleg Oshmyan <chortos@inbox.lv> |
|---|---|
| date | Wed, 25 May 2011 22:20:56 +0100 |
| parents | ed4035661b85 |
| children |
| rev | line source |
|---|---|
|
77
69eadc60f4e2
Memory limit is now applied to the RSS when os.wait4 is available
Oleg Oshmyan <chortos@inbox.lv>
parents:
76
diff
changeset
|
1 # Copyright (c) 2010-2011 Chortos-2 <chortos@inbox.lv> |
| 16 | 2 |
| 43 | 3 # TODO: copy the ansfile if not options.erase even if no validator is used |
| 4 | |
| 21 | 5 from __future__ import division, with_statement |
| 6 | |
| 91 | 7 from compat import * |
| 8 import files, problem, config | |
| 9 from __main__ import options | |
| 21 | 10 |
| 11 import glob, re, sys, tempfile, time | |
| 12 from subprocess import Popen, PIPE, STDOUT | |
| 13 | |
| 14 import os | |
| 15 devnull = open(os.path.devnull, 'w+') | |
| 16 | |
|
85
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
17 if options.autotime: |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
18 # This is really a dirty hack that assumes that sleep() does not spend |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
19 # the CPU time of the current process and that if clock() measures |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
20 # wall-clock time, then it is more precise than time() is. Both these |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
21 # assumptions are true on all platforms I have tested this on so far, |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
22 # but I am not aware of any guarantee that they will both be true |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
23 # on every other platform. |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
24 c = time.clock() |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
25 time.sleep(1) |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
26 c = time.clock() - c |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
27 if int(c + .5) == 1: |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
28 clock = time.clock |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
29 else: |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
30 clock = time.time |
|
741ae3391b61
Moved clock/time detection into platform-specific modules and testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
83
diff
changeset
|
31 |
|
108
218b8c28549c
Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents:
106
diff
changeset
|
32 class DummySignalIgnorer(object): |
|
218b8c28549c
Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents:
106
diff
changeset
|
33 def __enter__(self): pass |
|
218b8c28549c
Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents:
106
diff
changeset
|
34 def __exit__(self, exc_type, exc_value, traceback): pass |
|
218b8c28549c
Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents:
106
diff
changeset
|
35 signal_ignorer = DummySignalIgnorer() |
|
218b8c28549c
Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents:
106
diff
changeset
|
36 |
|
136
ed4035661b85
Added a C implementation of the unix module (called _unix)
Oleg Oshmyan <chortos@inbox.lv>
parents:
134
diff
changeset
|
37 # win32 and unix are imported a bit later |
| 22 | 38 |
| 21 | 39 __all__ = ('TestCase', 'load_problem', 'TestCaseNotPassed', |
| 22 | 40 'TimeLimitExceeded', 'CanceledByUser', 'WrongAnswer', |
| 41 'NonZeroExitCode', 'CannotStartTestee', | |
| 42 'CannotStartValidator', 'CannotReadOutputFile', | |
|
81
24752db487c5
Fixed errors in the win32 module
Oleg Oshmyan <chortos@inbox.lv>
parents:
79
diff
changeset
|
43 'CannotReadInputFile', 'CannotReadAnswerFile', |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
44 'MemoryLimitExceeded', 'CPUTimeLimitExceeded', |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
45 'WallTimeLimitExceeded') |
| 21 | 46 |
| 47 | |
| 48 | |
| 49 # Exceptions | |
| 50 | |
| 51 class TestCaseNotPassed(Exception): __slots__ = () | |
|
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
52 class TestCaseSkipped(TestCaseNotPassed): __slots__ = () |
| 21 | 53 class TimeLimitExceeded(TestCaseNotPassed): __slots__ = () |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
54 class CPUTimeLimitExceeded(TimeLimitExceeded): __slots__ = () |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
55 class WallTimeLimitExceeded(TimeLimitExceeded): __slots__ = () |
|
77
69eadc60f4e2
Memory limit is now applied to the RSS when os.wait4 is available
Oleg Oshmyan <chortos@inbox.lv>
parents:
76
diff
changeset
|
56 class MemoryLimitExceeded(TestCaseNotPassed): __slots__ = () |
| 22 | 57 class CanceledByUser(TestCaseNotPassed): __slots__ = () |
| 21 | 58 |
| 59 class WrongAnswer(TestCaseNotPassed): | |
| 60 __slots__ = 'comment' | |
| 61 def __init__(self, comment=''): | |
| 62 self.comment = comment | |
| 63 | |
| 64 class NonZeroExitCode(TestCaseNotPassed): | |
| 65 __slots__ = 'exitcode' | |
| 66 def __init__(self, exitcode): | |
| 67 self.exitcode = exitcode | |
| 68 | |
| 69 class ExceptionWrapper(TestCaseNotPassed): | |
| 70 __slots__ = 'upstream' | |
| 71 def __init__(self, upstream): | |
| 72 self.upstream = upstream | |
| 73 | |
| 74 class CannotStartTestee(ExceptionWrapper): __slots__ = () | |
| 75 class CannotStartValidator(ExceptionWrapper): __slots__ = () | |
| 76 class CannotReadOutputFile(ExceptionWrapper): __slots__ = () | |
| 77 class CannotReadInputFile(ExceptionWrapper): __slots__ = () | |
| 78 class CannotReadAnswerFile(ExceptionWrapper): __slots__ = () | |
| 79 | |
|
136
ed4035661b85
Added a C implementation of the unix module (called _unix)
Oleg Oshmyan <chortos@inbox.lv>
parents:
134
diff
changeset
|
80 # Import platform-specific code now that exception classes are defined |
|
ed4035661b85
Added a C implementation of the unix module (called _unix)
Oleg Oshmyan <chortos@inbox.lv>
parents:
134
diff
changeset
|
81 try: |
|
ed4035661b85
Added a C implementation of the unix module (called _unix)
Oleg Oshmyan <chortos@inbox.lv>
parents:
134
diff
changeset
|
82 from win32 import * |
|
ed4035661b85
Added a C implementation of the unix module (called _unix)
Oleg Oshmyan <chortos@inbox.lv>
parents:
134
diff
changeset
|
83 except Exception: |
|
ed4035661b85
Added a C implementation of the unix module (called _unix)
Oleg Oshmyan <chortos@inbox.lv>
parents:
134
diff
changeset
|
84 from unix import * |
|
ed4035661b85
Added a C implementation of the unix module (called _unix)
Oleg Oshmyan <chortos@inbox.lv>
parents:
134
diff
changeset
|
85 |
| 21 | 86 |
| 87 | |
| 22 | 88 # Helper context managers |
| 89 | |
| 90 class CopyDeleting(object): | |
| 91 __slots__ = 'case', 'file', 'name' | |
| 92 | |
| 93 def __init__(self, case, file, name): | |
| 94 self.case = case | |
| 95 self.file = file | |
| 96 self.name = name | |
| 97 | |
| 98 def __enter__(self): | |
| 99 if self.name: | |
| 100 try: | |
| 101 self.file.copy(self.name) | |
| 102 except: | |
| 103 try: | |
| 104 self.__exit__(None, None, None) | |
| 105 except: | |
| 106 pass | |
| 107 raise | |
| 108 | |
| 109 def __exit__(self, exc_type, exc_val, exc_tb): | |
| 110 if self.name: | |
| 111 self.case.files_to_delete.append(self.name) | |
| 112 | |
| 113 | |
| 114 class Copying(object): | |
| 115 __slots__ = 'file', 'name' | |
| 116 | |
| 117 def __init__(self, file, name): | |
| 118 self.file = file | |
| 119 self.name = name | |
| 120 | |
| 121 def __enter__(self): | |
| 122 if self.name: | |
| 123 self.file.copy(self.name) | |
| 124 | |
| 125 def __exit__(self, exc_type, exc_val, exc_tb): | |
| 126 pass | |
| 127 | |
| 128 | |
| 129 | |
| 21 | 130 # Test case types |
| 16 | 131 |
| 132 class TestCase(object): | |
| 21 | 133 __slots__ = ('problem', 'id', 'isdummy', 'infile', 'outfile', 'points', |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
134 'process', 'time_started', 'time_stopped', |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
135 'realinname', 'realoutname', 'maxcputime', 'maxwalltime', |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
136 'maxmemory', 'has_called_back', 'files_to_delete', |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
137 'cpu_time_limit_string', 'wall_time_limit_string', |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
138 'time_limit_string') |
|
106
aa0378ea1f93
Replaced constant properties with regular attributes
Oleg Oshmyan <chortos@inbox.lv>
parents:
105
diff
changeset
|
139 has_ansfile = has_iofiles = False |
|
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
140 needs_realinname = True |
| 21 | 141 |
| 142 if ABCMeta: | |
| 143 __metaclass__ = ABCMeta | |
| 16 | 144 |
| 21 | 145 def __init__(case, prob, id, isdummy, points): |
| 16 | 146 case.problem = prob |
| 21 | 147 case.id = id |
| 148 case.isdummy = isdummy | |
| 149 case.points = points | |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
150 case.maxcputime = case.problem.config.maxcputime |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
151 case.maxwalltime = case.problem.config.maxwalltime |
| 21 | 152 case.maxmemory = case.problem.config.maxmemory |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
153 if case.maxcputime: |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
154 case.cpu_time_limit_string = '/%.3f' % case.maxcputime |
| 21 | 155 else: |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
156 case.cpu_time_limit_string = '' |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
157 if case.maxwalltime: |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
158 case.wall_time_limit_string = '/%.3f' % case.maxwalltime |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
159 else: |
|
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
160 case.wall_time_limit_string = '' |
| 21 | 161 if not isdummy: |
|
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
162 if case.needs_realinname: |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
163 case.realinname = case.problem.config.testcaseinname |
| 21 | 164 case.realoutname = case.problem.config.testcaseoutname |
| 165 else: | |
|
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
166 if case.needs_realinname: |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
167 case.realinname = case.problem.config.dummyinname |
| 21 | 168 case.realoutname = case.problem.config.dummyoutname |
| 169 | |
| 170 @abstractmethod | |
|
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
171 def test(case): |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
172 raise NotImplementedError |
| 16 | 173 |
| 22 | 174 def __call__(case, callback): |
| 175 case.has_called_back = False | |
| 176 case.files_to_delete = [] | |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
177 case.time_limit_string = case.wall_time_limit_string |
| 21 | 178 try: |
| 22 | 179 return case.test(callback) |
| 21 | 180 finally: |
| 22 | 181 now = clock() |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
182 if getattr(case, 'time_started', None) is None: |
| 22 | 183 case.time_started = case.time_stopped = now |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
184 elif getattr(case, 'time_stopped', None) is None: |
| 22 | 185 case.time_stopped = now |
| 186 if not case.has_called_back: | |
| 187 callback() | |
| 21 | 188 case.cleanup() |
| 189 | |
| 190 def cleanup(case): | |
|
136
ed4035661b85
Added a C implementation of the unix module (called _unix)
Oleg Oshmyan <chortos@inbox.lv>
parents:
134
diff
changeset
|
191 # Note that native extensions clean up on their own |
|
ed4035661b85
Added a C implementation of the unix module (called _unix)
Oleg Oshmyan <chortos@inbox.lv>
parents:
134
diff
changeset
|
192 # and never let this condition be satisfied |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
193 if getattr(case, 'process', None) and case.process.returncode is None: |
|
134
e84f33a60a5c
Moved process killing logic into platform-specific modules
Oleg Oshmyan <chortos@inbox.lv>
parents:
130
diff
changeset
|
194 kill(case.process) |
|
e84f33a60a5c
Moved process killing logic into platform-specific modules
Oleg Oshmyan <chortos@inbox.lv>
parents:
130
diff
changeset
|
195 for name in case.files_to_delete: |
|
e84f33a60a5c
Moved process killing logic into platform-specific modules
Oleg Oshmyan <chortos@inbox.lv>
parents:
130
diff
changeset
|
196 try: |
|
e84f33a60a5c
Moved process killing logic into platform-specific modules
Oleg Oshmyan <chortos@inbox.lv>
parents:
130
diff
changeset
|
197 os.remove(name) |
|
e84f33a60a5c
Moved process killing logic into platform-specific modules
Oleg Oshmyan <chortos@inbox.lv>
parents:
130
diff
changeset
|
198 except OSError: |
|
e84f33a60a5c
Moved process killing logic into platform-specific modules
Oleg Oshmyan <chortos@inbox.lv>
parents:
130
diff
changeset
|
199 # It can't be helped |
|
e84f33a60a5c
Moved process killing logic into platform-specific modules
Oleg Oshmyan <chortos@inbox.lv>
parents:
130
diff
changeset
|
200 pass |
| 21 | 201 |
| 202 def open_infile(case): | |
| 203 try: | |
| 204 case.infile = files.File('/'.join((case.problem.name, case.realinname.replace('$', case.id)))) | |
| 205 except IOError: | |
| 206 e = sys.exc_info()[1] | |
| 207 raise CannotReadInputFile(e) | |
| 208 | |
| 209 def open_outfile(case): | |
| 210 try: | |
| 211 case.outfile = files.File('/'.join((case.problem.name, case.realoutname.replace('$', case.id)))) | |
| 212 except IOError: | |
| 213 e = sys.exc_info()[1] | |
| 214 raise CannotReadAnswerFile(e) | |
| 215 | |
| 16 | 216 |
|
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
217 class SkippedTestCase(TestCase): |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
218 __slots__ = () |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
219 |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
220 def test(case, callback): |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
221 raise TestCaseSkipped |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
222 |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
223 |
| 21 | 224 class ValidatedTestCase(TestCase): |
| 225 __slots__ = 'validator' | |
| 226 | |
| 227 def __init__(case, *args): | |
| 228 TestCase.__init__(case, *args) | |
| 229 if not case.problem.config.tester: | |
| 230 case.validator = None | |
| 231 else: | |
| 232 case.validator = case.problem.config.tester | |
| 233 | |
| 234 def validate(case, output): | |
| 235 if not case.validator: | |
| 236 # Compare the output with the reference output | |
| 237 case.open_outfile() | |
| 238 with case.outfile.open() as refoutput: | |
|
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
239 for line, refline in zip_longest(output, refoutput): |
|
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
240 if refline is not None and not isinstance(refline, basestring): |
| 21 | 241 line = bytes(line, sys.getdefaultencoding()) |
| 242 if line != refline: | |
| 22 | 243 raise WrongAnswer |
|
24
c23d81f4a1a3
Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
244 return 1 |
| 21 | 245 elif callable(case.validator): |
| 246 return case.validator(output) | |
| 247 else: | |
| 248 # Call the validator program | |
| 249 output.close() | |
| 23 | 250 if case.problem.config.ansname: |
| 251 case.open_outfile() | |
| 252 case.outfile.copy(case.problem.config.ansname) | |
|
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
253 try: |
|
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
254 case.process = Popen(case.validator, stdin=devnull, stdout=PIPE, stderr=STDOUT, universal_newlines=True, bufsize=-1) |
|
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
255 except OSError: |
|
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
256 raise CannotStartValidator(sys.exc_info()[1]) |
|
108
218b8c28549c
Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents:
106
diff
changeset
|
257 with signal_ignorer: |
|
218b8c28549c
Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents:
106
diff
changeset
|
258 comment = case.process.communicate()[0].strip() |
| 26 | 259 match = re.match(r'(?i)(ok|(?:correct|wrong)(?:(?:\s|_)*answer)?)(?:$|\s+|[.,!:]+\s*)', comment) |
| 21 | 260 if match: |
| 261 comment = comment[match.end():] | |
| 262 if not case.problem.config.maxexitcode: | |
| 263 if case.process.returncode: | |
| 264 raise WrongAnswer(comment) | |
| 265 else: | |
|
24
c23d81f4a1a3
Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
266 return 1, comment |
| 21 | 267 else: |
|
24
c23d81f4a1a3
Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
268 return case.process.returncode / case.problem.config.maxexitcode, comment |
| 21 | 269 |
| 270 | |
| 271 class BatchTestCase(ValidatedTestCase): | |
| 272 __slots__ = () | |
| 273 | |
|
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
274 @property |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
275 def has_iofiles(case): |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
276 return (not case.problem.config.stdio or |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
277 case.validator and not callable(case.validator)) |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
278 |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
279 @property |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
280 def has_ansfile(case): |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
281 return case.validator and not callable(case.validator) |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
282 |
| 22 | 283 def test(case, callback): |
| 21 | 284 case.open_infile() |
| 285 if case.problem.config.stdio: | |
| 54 | 286 if options.erase and not case.validator or not case.problem.config.inname: |
| 22 | 287 # TODO: re-use the same file name if possible |
| 21 | 288 # FIXME: 2.5 lacks the delete parameter |
| 289 with tempfile.NamedTemporaryFile(delete=False) as f: | |
| 22 | 290 inputdatafname = f.name |
|
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
291 contextmgr = CopyDeleting(case, case.infile, inputdatafname) |
| 21 | 292 else: |
| 293 inputdatafname = case.problem.config.inname | |
|
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
294 contextmgr = Copying(case.infile, inputdatafname) |
|
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
295 with contextmgr: |
|
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
77
diff
changeset
|
296 with open(inputdatafname) as infile: |
| 83 | 297 with tempfile.TemporaryFile('w+') if options.erase and (not case.validator or callable(case.validator)) else open(case.problem.config.outname, 'w+') as outfile: |
|
130
652028850ea4
Removed useless arguments to call() from testcases.BatchTestCase.test()
Oleg Oshmyan <chortos@inbox.lv>
parents:
128
diff
changeset
|
298 call(case.problem.config.path, case=case, stdin=infile, stdout=outfile, stderr=devnull) |
|
62
593ad09cd69b
Multiple exit code handling fixes
Oleg Oshmyan <chortos@inbox.lv>
parents:
61
diff
changeset
|
299 if config.globalconf.force_zero_exitcode and case.process.returncode or case.process.returncode < 0: |
| 22 | 300 raise NonZeroExitCode(case.process.returncode) |
|
103
4e6f231f055f
Fixed race condition resulting in calling back twice from TestCase.test
Oleg Oshmyan <chortos@inbox.lv>
parents:
99
diff
changeset
|
301 case.has_called_back = True |
| 22 | 302 callback() |
| 303 outfile.seek(0) | |
| 304 return case.validate(outfile) | |
| 21 | 305 else: |
| 22 | 306 case.infile.copy(case.problem.config.inname) |
|
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
307 call(case.problem.config.path, case=case, stdin=devnull, stdout=devnull, stderr=STDOUT) |
|
62
593ad09cd69b
Multiple exit code handling fixes
Oleg Oshmyan <chortos@inbox.lv>
parents:
61
diff
changeset
|
308 if config.globalconf.force_zero_exitcode and case.process.returncode or case.process.returncode < 0: |
| 21 | 309 raise NonZeroExitCode(case.process.returncode) |
|
103
4e6f231f055f
Fixed race condition resulting in calling back twice from TestCase.test
Oleg Oshmyan <chortos@inbox.lv>
parents:
99
diff
changeset
|
310 case.has_called_back = True |
| 22 | 311 callback() |
|
105
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
312 try: |
|
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
313 output = open(case.problem.config.outname, 'rU') |
|
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
314 except IOError: |
|
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
315 raise CannotReadOutputFile(sys.exc_info()[1]) |
|
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
316 with output as output: |
| 21 | 317 return case.validate(output) |
| 318 | |
| 319 | |
| 320 # This is the only test case type not executing any programs to be tested | |
| 321 class OutputOnlyTestCase(ValidatedTestCase): | |
| 322 __slots__ = () | |
|
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
323 needs_realinname = False |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
324 |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
325 def cleanup(case): |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
326 pass |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
327 |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
328 def test(case, callback): |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
329 case.time_stopped = case.time_started = 0 |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
330 case.has_called_back = True |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
331 callback() |
|
105
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
332 try: |
|
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
333 output = open(case.problem.config.outname.replace('$', case.id), 'rU') |
|
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
334 except IOError: |
|
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
335 raise CannotReadOutputFile(sys.exc_info()[1]) |
|
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
336 with output as output: |
|
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
337 return case.validate(output) |
|
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
338 |
| 21 | 339 |
| 340 class BestOutputTestCase(ValidatedTestCase): | |
| 341 __slots__ = () | |
| 342 | |
|
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
343 |
| 21 | 344 # This is the only test case type executing two programs simultaneously |
| 345 class ReactiveTestCase(TestCase): | |
| 346 __slots__ = () | |
| 347 # The basic idea is to launch the program to be tested and the grader | |
| 348 # and to pipe their standard I/O from and to each other, | |
| 349 # and then to capture the grader's exit code and use it | |
| 26 | 350 # like the exit code of an output validator is used. |
| 21 | 351 |
| 352 | |
|
71
1bee3a0beeb5
Added a 'Sample total' line when using test groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
69
diff
changeset
|
353 class DummyTestContext(problem.TestGroup): |
|
1bee3a0beeb5
Added a 'Sample total' line when using test groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
69
diff
changeset
|
354 __slots__ = () |
|
1bee3a0beeb5
Added a 'Sample total' line when using test groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
69
diff
changeset
|
355 def end(self): |
|
1bee3a0beeb5
Added a 'Sample total' line when using test groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
69
diff
changeset
|
356 say('Sample total: %d/%d tests' % (self.ncorrect, self.ntotal)) |
|
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
357 return 0, 0, self.log |
|
71
1bee3a0beeb5
Added a 'Sample total' line when using test groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
69
diff
changeset
|
358 |
| 21 | 359 def load_problem(prob, _types={'batch' : BatchTestCase, |
| 360 'outonly' : OutputOnlyTestCase, | |
| 361 'bestout' : BestOutputTestCase, | |
| 362 'reactive': ReactiveTestCase}): | |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
363 # We will need to iterate over these configuration variables twice |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
364 try: |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
365 len(prob.config.dummies) |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
366 except Exception: |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
367 prob.config.dummies = tuple(prob.config.dummies) |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
368 try: |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
369 len(prob.config.tests) |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
370 except Exception: |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
371 prob.config.tests = tuple(prob.config.tests) |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
372 |
| 23 | 373 if options.legacy: |
| 374 prob.config.usegroups = False | |
| 58 | 375 newtests = [] |
| 23 | 376 for i, name in enumerate(prob.config.tests): |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
377 # Same here; we'll need to iterate over them twice |
| 23 | 378 try: |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
379 l = len(name) |
| 23 | 380 except Exception: |
| 381 try: | |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
382 name = tuple(name) |
| 23 | 383 except TypeError: |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
384 name = (name,) |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
385 l = len(name) |
| 58 | 386 if l > 1: |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
387 prob.config.usegroups = True |
| 58 | 388 newtests.append(name) |
| 389 if prob.config.usegroups: | |
| 390 prob.config.tests = newtests | |
| 391 del newtests | |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
392 |
|
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
393 # Even if they have duplicate test identifiers, we must honour sequence pointmaps |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
394 if isinstance(prob.config.pointmap, dict): |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
395 def getpoints(i, j, k=None): |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
396 try: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
397 return prob.config.pointmap[i] |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
398 except KeyError: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
399 try: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
400 return prob.config.pointmap[None] |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
401 except KeyError: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
402 return prob.config.maxexitcode or 1 |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
403 elif prob.config.usegroups: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
404 def getpoints(i, j, k): |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
405 try: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
406 return prob.config.pointmap[k][j] |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
407 except LookupError: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
408 return prob.config.maxexitcode or 1 |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
409 else: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
410 def getpoints(i, j): |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
411 try: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
412 return prob.config.pointmap[j] |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
413 except LookupError: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
414 return prob.config.maxexitcode or 1 |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
415 |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
416 # First get prob.cache.padoutput right, |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
417 # then yield the actual test cases |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
418 for i in prob.config.dummies: |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
419 s = 'sample ' + str(i).zfill(prob.config.paddummies) |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
420 prob.cache.padoutput = max(prob.cache.padoutput, len(s)) |
| 16 | 421 if prob.config.usegroups: |
|
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
422 if not isinstance(prob.config.groupweight, dict): |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
423 prob.config.groupweight = dict(enumerate(prob.config.groupweight)) |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
424 for group in prob.config.tests: |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
425 for i in group: |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
426 s = str(i).zfill(prob.config.padtests) |
|
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
427 prob.cache.padoutput = max(prob.cache.padoutput, len(s)) |
|
89
3ae6cb69e4ef
Sample total is no longer printed if there are no samples
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
428 if prob.config.dummies: |
|
3ae6cb69e4ef
Sample total is no longer printed if there are no samples
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
429 yield DummyTestContext() |
|
3ae6cb69e4ef
Sample total is no longer printed if there are no samples
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
430 for i in prob.config.dummies: |
|
3ae6cb69e4ef
Sample total is no longer printed if there are no samples
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
431 s = str(i).zfill(prob.config.paddummies) |
|
99
9b41934b2e95
Fixed a major regression introduced in changeset 1fb319ec33af
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
432 if (yield _types[prob.config.kind](prob, s, True, 0)): |
|
9b41934b2e95
Fixed a major regression introduced in changeset 1fb319ec33af
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
433 yield |
|
89
3ae6cb69e4ef
Sample total is no longer printed if there are no samples
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
434 yield problem.test_context_end |
|
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
435 for k, group in enumerate(prob.config.tests): |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
436 if not group: |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
437 continue |
|
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
438 yield problem.TestGroup(prob.config.groupweight.get(k, prob.config.groupweight.get(None))) |
|
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
439 case_type = _types[prob.config.kind] |
|
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
440 for j, i in enumerate(group): |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
441 s = str(i).zfill(prob.config.padtests) |
|
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
442 if not (yield case_type(prob, s, False, getpoints(i, j, k))): |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
443 if options.skim: |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
444 case_type = SkippedTestCase |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
445 else: |
|
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
446 yield |
|
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
447 yield problem.test_context_end |
| 16 | 448 else: |
| 449 for i in prob.config.tests: | |
| 21 | 450 s = str(i).zfill(prob.config.padtests) |
| 451 prob.cache.padoutput = max(prob.cache.padoutput, len(s)) | |
| 452 for i in prob.config.dummies: | |
| 453 s = str(i).zfill(prob.config.paddummies) | |
|
99
9b41934b2e95
Fixed a major regression introduced in changeset 1fb319ec33af
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
454 if (yield _types[prob.config.kind](prob, s, True, 0)): |
|
9b41934b2e95
Fixed a major regression introduced in changeset 1fb319ec33af
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
455 yield |
|
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
456 for j, i in enumerate(prob.config.tests): |
| 21 | 457 s = str(i).zfill(prob.config.padtests) |
|
99
9b41934b2e95
Fixed a major regression introduced in changeset 1fb319ec33af
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
458 if (yield _types[prob.config.kind](prob, s, False, getpoints(i, j))): |
|
9b41934b2e95
Fixed a major regression introduced in changeset 1fb319ec33af
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
459 yield |
