Mercurial > ~astiob > upreckon > hgweb
annotate testcases.py @ 132:cdd0f970d112
Fixed several small bugs in the files module
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Thu, 19 May 2011 02:55:36 +0100 |
parents | 652028850ea4 |
children | e84f33a60a5c |
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 |
21 | 37 try: |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
38 from win32 import * |
72
7520b6bb6636
Windows Error Reporting is now suppressed (at least the dialogs)
Oleg Oshmyan <chortos@inbox.lv>
parents:
71
diff
changeset
|
39 except Exception: |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
40 from unix import * |
22 | 41 |
21 | 42 __all__ = ('TestCase', 'load_problem', 'TestCaseNotPassed', |
22 | 43 'TimeLimitExceeded', 'CanceledByUser', 'WrongAnswer', |
44 'NonZeroExitCode', 'CannotStartTestee', | |
45 'CannotStartValidator', 'CannotReadOutputFile', | |
81
24752db487c5
Fixed errors in the win32 module
Oleg Oshmyan <chortos@inbox.lv>
parents:
79
diff
changeset
|
46 'CannotReadInputFile', 'CannotReadAnswerFile', |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
47 'MemoryLimitExceeded', 'CPUTimeLimitExceeded', |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
48 'WallTimeLimitExceeded') |
21 | 49 |
50 | |
51 | |
52 # Exceptions | |
53 | |
54 class TestCaseNotPassed(Exception): __slots__ = () | |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
55 class TestCaseSkipped(TestCaseNotPassed): __slots__ = () |
21 | 56 class TimeLimitExceeded(TestCaseNotPassed): __slots__ = () |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
57 class CPUTimeLimitExceeded(TimeLimitExceeded): __slots__ = () |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
58 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
|
59 class MemoryLimitExceeded(TestCaseNotPassed): __slots__ = () |
22 | 60 class CanceledByUser(TestCaseNotPassed): __slots__ = () |
21 | 61 |
62 class WrongAnswer(TestCaseNotPassed): | |
63 __slots__ = 'comment' | |
64 def __init__(self, comment=''): | |
65 self.comment = comment | |
66 | |
67 class NonZeroExitCode(TestCaseNotPassed): | |
68 __slots__ = 'exitcode' | |
69 def __init__(self, exitcode): | |
70 self.exitcode = exitcode | |
71 | |
72 class ExceptionWrapper(TestCaseNotPassed): | |
73 __slots__ = 'upstream' | |
74 def __init__(self, upstream): | |
75 self.upstream = upstream | |
76 | |
77 class CannotStartTestee(ExceptionWrapper): __slots__ = () | |
78 class CannotStartValidator(ExceptionWrapper): __slots__ = () | |
79 class CannotReadOutputFile(ExceptionWrapper): __slots__ = () | |
80 class CannotReadInputFile(ExceptionWrapper): __slots__ = () | |
81 class CannotReadAnswerFile(ExceptionWrapper): __slots__ = () | |
82 | |
83 | |
84 | |
22 | 85 # Helper context managers |
86 | |
87 class CopyDeleting(object): | |
88 __slots__ = 'case', 'file', 'name' | |
89 | |
90 def __init__(self, case, file, name): | |
91 self.case = case | |
92 self.file = file | |
93 self.name = name | |
94 | |
95 def __enter__(self): | |
96 if self.name: | |
97 try: | |
98 self.file.copy(self.name) | |
99 except: | |
100 try: | |
101 self.__exit__(None, None, None) | |
102 except: | |
103 pass | |
104 raise | |
105 | |
106 def __exit__(self, exc_type, exc_val, exc_tb): | |
107 if self.name: | |
108 self.case.files_to_delete.append(self.name) | |
109 | |
110 | |
111 class Copying(object): | |
112 __slots__ = 'file', 'name' | |
113 | |
114 def __init__(self, file, name): | |
115 self.file = file | |
116 self.name = name | |
117 | |
118 def __enter__(self): | |
119 if self.name: | |
120 self.file.copy(self.name) | |
121 | |
122 def __exit__(self, exc_type, exc_val, exc_tb): | |
123 pass | |
124 | |
125 | |
126 | |
21 | 127 # Test case types |
16 | 128 |
129 class TestCase(object): | |
21 | 130 __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
|
131 'process', 'time_started', 'time_stopped', |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
132 'realinname', 'realoutname', 'maxcputime', 'maxwalltime', |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
133 '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
|
134 '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
|
135 'time_limit_string') |
106
aa0378ea1f93
Replaced constant properties with regular attributes
Oleg Oshmyan <chortos@inbox.lv>
parents:
105
diff
changeset
|
136 has_ansfile = has_iofiles = False |
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
137 needs_realinname = True |
21 | 138 |
139 if ABCMeta: | |
140 __metaclass__ = ABCMeta | |
16 | 141 |
21 | 142 def __init__(case, prob, id, isdummy, points): |
16 | 143 case.problem = prob |
21 | 144 case.id = id |
145 case.isdummy = isdummy | |
146 case.points = points | |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
147 case.maxcputime = case.problem.config.maxcputime |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
148 case.maxwalltime = case.problem.config.maxwalltime |
21 | 149 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
|
150 if case.maxcputime: |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
151 case.cpu_time_limit_string = '/%.3f' % case.maxcputime |
21 | 152 else: |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
153 case.cpu_time_limit_string = '' |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
154 if case.maxwalltime: |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
155 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
|
156 else: |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
157 case.wall_time_limit_string = '' |
21 | 158 if not isdummy: |
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
159 if case.needs_realinname: |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
160 case.realinname = case.problem.config.testcaseinname |
21 | 161 case.realoutname = case.problem.config.testcaseoutname |
162 else: | |
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
163 if case.needs_realinname: |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
164 case.realinname = case.problem.config.dummyinname |
21 | 165 case.realoutname = case.problem.config.dummyoutname |
166 | |
167 @abstractmethod | |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
168 def test(case): |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
169 raise NotImplementedError |
16 | 170 |
22 | 171 def __call__(case, callback): |
172 case.has_called_back = False | |
173 case.files_to_delete = [] | |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
174 case.time_limit_string = case.wall_time_limit_string |
21 | 175 try: |
22 | 176 return case.test(callback) |
21 | 177 finally: |
22 | 178 now = clock() |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
179 if getattr(case, 'time_started', None) is None: |
22 | 180 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
|
181 elif getattr(case, 'time_stopped', None) is None: |
22 | 182 case.time_stopped = now |
183 if not case.has_called_back: | |
184 callback() | |
21 | 185 case.cleanup() |
186 | |
187 def cleanup(case): | |
188 #if getattr(case, 'infile', None): | |
189 # case.infile.close() | |
190 #if getattr(case, 'outfile', None): | |
191 # case.outfile.close() | |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
192 if getattr(case, 'process', None) and case.process.returncode is None: |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
193 # Try KILLing after three unsuccessful TERM attempts in a row |
21 | 194 for i in range(3): |
195 try: | |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
196 terminate(case.process) |
21 | 197 except Exception: |
198 time.sleep(0) | |
199 else: | |
128
42c8f5c152a5
Fixed EINTR fatally breaking poll/wait on Python 2.6- (for real this time)
Oleg Oshmyan <chortos@inbox.lv>
parents:
108
diff
changeset
|
200 wait(case.process) |
21 | 201 break |
202 else: | |
203 # If killing the process is unsuccessful three times in a row, | |
204 # just silently stop trying | |
205 for i in range(3): | |
206 try: | |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
81
diff
changeset
|
207 kill(case.process) |
21 | 208 except Exception: |
209 time.sleep(0) | |
210 else: | |
128
42c8f5c152a5
Fixed EINTR fatally breaking poll/wait on Python 2.6- (for real this time)
Oleg Oshmyan <chortos@inbox.lv>
parents:
108
diff
changeset
|
211 wait(case.process) |
21 | 212 break |
22 | 213 if case.files_to_delete: |
214 for name in case.files_to_delete: | |
215 try: | |
216 os.remove(name) | |
217 except Exception: | |
218 # It can't be helped | |
219 pass | |
21 | 220 |
221 def open_infile(case): | |
222 try: | |
223 case.infile = files.File('/'.join((case.problem.name, case.realinname.replace('$', case.id)))) | |
224 except IOError: | |
225 e = sys.exc_info()[1] | |
226 raise CannotReadInputFile(e) | |
227 | |
228 def open_outfile(case): | |
229 try: | |
230 case.outfile = files.File('/'.join((case.problem.name, case.realoutname.replace('$', case.id)))) | |
231 except IOError: | |
232 e = sys.exc_info()[1] | |
233 raise CannotReadAnswerFile(e) | |
234 | |
16 | 235 |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
236 class SkippedTestCase(TestCase): |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
237 __slots__ = () |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
238 |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
239 def test(case, callback): |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
240 raise TestCaseSkipped |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
241 |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
242 |
21 | 243 class ValidatedTestCase(TestCase): |
244 __slots__ = 'validator' | |
245 | |
246 def __init__(case, *args): | |
247 TestCase.__init__(case, *args) | |
248 if not case.problem.config.tester: | |
249 case.validator = None | |
250 else: | |
251 case.validator = case.problem.config.tester | |
252 | |
253 def validate(case, output): | |
254 if not case.validator: | |
255 # Compare the output with the reference output | |
256 case.open_outfile() | |
257 with case.outfile.open() as refoutput: | |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
258 for line, refline in zip_longest(output, refoutput): |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
259 if refline is not None and not isinstance(refline, basestring): |
21 | 260 line = bytes(line, sys.getdefaultencoding()) |
261 if line != refline: | |
22 | 262 raise WrongAnswer |
24
c23d81f4a1a3
Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
263 return 1 |
21 | 264 elif callable(case.validator): |
265 return case.validator(output) | |
266 else: | |
267 # Call the validator program | |
268 output.close() | |
23 | 269 if case.problem.config.ansname: |
270 case.open_outfile() | |
271 case.outfile.copy(case.problem.config.ansname) | |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
272 try: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
273 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
|
274 except OSError: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
275 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
|
276 with signal_ignorer: |
218b8c28549c
Fixed a crash due to SIGCHLD interrupting validator output pipe reads
Oleg Oshmyan <chortos@inbox.lv>
parents:
106
diff
changeset
|
277 comment = case.process.communicate()[0].strip() |
26 | 278 match = re.match(r'(?i)(ok|(?:correct|wrong)(?:(?:\s|_)*answer)?)(?:$|\s+|[.,!:]+\s*)', comment) |
21 | 279 if match: |
280 comment = comment[match.end():] | |
281 if not case.problem.config.maxexitcode: | |
282 if case.process.returncode: | |
283 raise WrongAnswer(comment) | |
284 else: | |
24
c23d81f4a1a3
Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
285 return 1, comment |
21 | 286 else: |
24
c23d81f4a1a3
Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
287 return case.process.returncode / case.problem.config.maxexitcode, comment |
21 | 288 |
289 | |
290 class BatchTestCase(ValidatedTestCase): | |
291 __slots__ = () | |
292 | |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
293 @property |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
294 def has_iofiles(case): |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
295 return (not case.problem.config.stdio or |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
296 case.validator and not callable(case.validator)) |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
297 |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
298 @property |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
299 def has_ansfile(case): |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
300 return case.validator and not callable(case.validator) |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
301 |
22 | 302 def test(case, callback): |
21 | 303 case.open_infile() |
304 if case.problem.config.stdio: | |
54 | 305 if options.erase and not case.validator or not case.problem.config.inname: |
22 | 306 # TODO: re-use the same file name if possible |
21 | 307 # FIXME: 2.5 lacks the delete parameter |
308 with tempfile.NamedTemporaryFile(delete=False) as f: | |
22 | 309 inputdatafname = f.name |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
310 contextmgr = CopyDeleting(case, case.infile, inputdatafname) |
21 | 311 else: |
312 inputdatafname = case.problem.config.inname | |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
313 contextmgr = Copying(case.infile, inputdatafname) |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
314 with contextmgr: |
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
77
diff
changeset
|
315 with open(inputdatafname) as infile: |
83 | 316 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
|
317 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
|
318 if config.globalconf.force_zero_exitcode and case.process.returncode or case.process.returncode < 0: |
22 | 319 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
|
320 case.has_called_back = True |
22 | 321 callback() |
322 outfile.seek(0) | |
323 return case.validate(outfile) | |
21 | 324 else: |
22 | 325 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
|
326 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
|
327 if config.globalconf.force_zero_exitcode and case.process.returncode or case.process.returncode < 0: |
21 | 328 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
|
329 case.has_called_back = True |
22 | 330 callback() |
105
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
331 try: |
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
332 output = open(case.problem.config.outname, 'rU') |
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
333 except IOError: |
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
334 raise CannotReadOutputFile(sys.exc_info()[1]) |
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
335 with output as output: |
21 | 336 return case.validate(output) |
337 | |
338 | |
339 # This is the only test case type not executing any programs to be tested | |
340 class OutputOnlyTestCase(ValidatedTestCase): | |
341 __slots__ = () | |
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
342 needs_realinname = False |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
343 |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
344 def cleanup(case): |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
345 pass |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
346 |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
347 def test(case, callback): |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
348 case.time_stopped = case.time_started = 0 |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
349 case.has_called_back = True |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
350 callback() |
105
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
351 try: |
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
352 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
|
353 except IOError: |
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
354 raise CannotReadOutputFile(sys.exc_info()[1]) |
9f922b11c98a
Absent output files no longer crash Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents:
104
diff
changeset
|
355 with output as output: |
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
356 return case.validate(output) |
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
357 |
21 | 358 |
359 class BestOutputTestCase(ValidatedTestCase): | |
360 __slots__ = () | |
361 | |
104
8f46e84922f9
Output-only problems are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
103
diff
changeset
|
362 |
21 | 363 # This is the only test case type executing two programs simultaneously |
364 class ReactiveTestCase(TestCase): | |
365 __slots__ = () | |
366 # The basic idea is to launch the program to be tested and the grader | |
367 # and to pipe their standard I/O from and to each other, | |
368 # and then to capture the grader's exit code and use it | |
26 | 369 # like the exit code of an output validator is used. |
21 | 370 |
371 | |
71
1bee3a0beeb5
Added a 'Sample total' line when using test groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
69
diff
changeset
|
372 class DummyTestContext(problem.TestGroup): |
1bee3a0beeb5
Added a 'Sample total' line when using test groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
69
diff
changeset
|
373 __slots__ = () |
1bee3a0beeb5
Added a 'Sample total' line when using test groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
69
diff
changeset
|
374 def end(self): |
1bee3a0beeb5
Added a 'Sample total' line when using test groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
69
diff
changeset
|
375 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
|
376 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
|
377 |
21 | 378 def load_problem(prob, _types={'batch' : BatchTestCase, |
379 'outonly' : OutputOnlyTestCase, | |
380 'bestout' : BestOutputTestCase, | |
381 'reactive': ReactiveTestCase}): | |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
382 # 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
|
383 try: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
384 len(prob.config.dummies) |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
385 except Exception: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
386 prob.config.dummies = tuple(prob.config.dummies) |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
387 try: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
388 len(prob.config.tests) |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
389 except Exception: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
390 prob.config.tests = tuple(prob.config.tests) |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
391 |
23 | 392 if options.legacy: |
393 prob.config.usegroups = False | |
58 | 394 newtests = [] |
23 | 395 for i, name in enumerate(prob.config.tests): |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
396 # Same here; we'll need to iterate over them twice |
23 | 397 try: |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
398 l = len(name) |
23 | 399 except Exception: |
400 try: | |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
401 name = tuple(name) |
23 | 402 except TypeError: |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
403 name = (name,) |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
404 l = len(name) |
58 | 405 if l > 1: |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
406 prob.config.usegroups = True |
58 | 407 newtests.append(name) |
408 if prob.config.usegroups: | |
409 prob.config.tests = newtests | |
410 del newtests | |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
411 |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
412 # 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
|
413 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
|
414 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
|
415 try: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
416 return prob.config.pointmap[i] |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
417 except KeyError: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
418 try: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
419 return prob.config.pointmap[None] |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
420 except KeyError: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
421 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
|
422 elif prob.config.usegroups: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
423 def getpoints(i, j, k): |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
424 try: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
425 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
|
426 except LookupError: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
427 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
|
428 else: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
429 def getpoints(i, j): |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
430 try: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
431 return prob.config.pointmap[j] |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
432 except LookupError: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
433 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
|
434 |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
435 # First get prob.cache.padoutput right, |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
436 # then yield the actual test cases |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
437 for i in prob.config.dummies: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
438 s = 'sample ' + str(i).zfill(prob.config.paddummies) |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
439 prob.cache.padoutput = max(prob.cache.padoutput, len(s)) |
16 | 440 if prob.config.usegroups: |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
441 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
|
442 prob.config.groupweight = dict(enumerate(prob.config.groupweight)) |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
443 for group in prob.config.tests: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
444 for i in group: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
445 s = str(i).zfill(prob.config.padtests) |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
446 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
|
447 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
|
448 yield DummyTestContext() |
3ae6cb69e4ef
Sample total is no longer printed if there are no samples
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
449 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
|
450 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
|
451 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
|
452 yield |
89
3ae6cb69e4ef
Sample total is no longer printed if there are no samples
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
453 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
|
454 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
|
455 if not group: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
456 continue |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
457 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
|
458 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
|
459 for j, i in enumerate(group): |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
460 s = str(i).zfill(prob.config.padtests) |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
461 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
|
462 if options.skim: |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
463 case_type = SkippedTestCase |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
464 else: |
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
89
diff
changeset
|
465 yield |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
27
diff
changeset
|
466 yield problem.test_context_end |
16 | 467 else: |
468 for i in prob.config.tests: | |
21 | 469 s = str(i).zfill(prob.config.padtests) |
470 prob.cache.padoutput = max(prob.cache.padoutput, len(s)) | |
471 for i in prob.config.dummies: | |
472 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
|
473 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
|
474 yield |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
72
diff
changeset
|
475 for j, i in enumerate(prob.config.tests): |
21 | 476 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
|
477 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
|
478 yield |