Mercurial > ~astiob > upreckon > hgweb
comparison problem.py @ 90:1fb319ec33af
Skimming mode added (-k/--skim option)
In skimming mode, as soon as a single test case within a test group
is failed, the remaining test cases in the same group are skipped.
Bug fix and simply a bit of refactoring: TestCase.has_iofiles and
TestCase.has_ansfile are now defined (the meaning should be clear
from the names).
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Mon, 28 Feb 2011 15:32:22 +0000 |
parents | cd347cfca272 |
children | c62c9bfd614a |
comparison
equal
deleted
inserted
replaced
89:3ae6cb69e4ef | 90:1fb319ec33af |
---|---|
44 class Cache(object): | 44 class Cache(object): |
45 def __init__(self, mydict): | 45 def __init__(self, mydict): |
46 self.__dict__ = mydict | 46 self.__dict__ = mydict |
47 | 47 |
48 class TestContext(object): | 48 class TestContext(object): |
49 pass | 49 __slots__ = () |
50 | 50 |
51 test_context_end = object() | 51 test_context_end = object() |
52 | 52 |
53 class TestGroup(TestContext): | 53 class TestGroup(TestContext): |
54 __slots__ = 'points', 'case', 'log', 'correct', 'allcorrect', 'real', 'max', 'ntotal', 'nvalued', 'ncorrect', 'ncorrectvalued' | 54 __slots__ = 'points', 'case', 'log', 'correct', 'allcorrect', 'real', 'max', 'ntotal', 'nvalued', 'ncorrect', 'ncorrectvalued' |
136 id = 'sample ' + id | 136 id = 'sample ' + id |
137 say('%*s: ' % (prob.cache.padoutput, id), end='') | 137 say('%*s: ' % (prob.cache.padoutput, id), end='') |
138 sys.stdout.flush() | 138 sys.stdout.flush() |
139 try: | 139 try: |
140 granted = case(lambda: (say('%7.3f%s s, ' % (case.time_stopped - case.time_started, case.time_limit_string), end=''), sys.stdout.flush())) | 140 granted = case(lambda: (say('%7.3f%s s, ' % (case.time_stopped - case.time_started, case.time_limit_string), end=''), sys.stdout.flush())) |
141 except testcases.TestCaseSkipped: | |
142 verdict = 'skipped due to skimming mode' | |
141 except testcases.CanceledByUser: | 143 except testcases.CanceledByUser: |
142 verdict = 'canceled by the user' | 144 verdict = 'canceled by the user' |
143 except testcases.WallTimeLimitExceeded: | 145 except testcases.WallTimeLimitExceeded: |
144 verdict = 'wall-clock time limit exceeded' | 146 verdict = 'wall-clock time limit exceeded' |
145 except testcases.CPUTimeLimitExceeded: | 147 except testcases.CPUTimeLimitExceeded: |
185 else: | 187 else: |
186 if comment: | 188 if comment: |
187 comment = ' (%s)' % comment | 189 comment = ' (%s)' % comment |
188 if granted >= 1: | 190 if granted >= 1: |
189 contexts[-1].case_correct() | 191 contexts[-1].case_correct() |
192 prob.testcases.send(True) | |
190 verdict = 'OK' + comment | 193 verdict = 'OK' + comment |
191 elif not granted: | 194 elif not granted: |
192 verdict = 'wrong answer' + comment | 195 verdict = 'wrong answer' + comment |
193 else: | 196 else: |
194 verdict = 'partly correct' + comment | 197 verdict = 'partly correct' + comment |
204 valued = ' (%d/%d valued)' % (contexts[0].ncorrectvalued, contexts[0].nvalued) | 207 valued = ' (%d/%d valued)' % (contexts[0].ncorrectvalued, contexts[0].nvalued) |
205 say('Problem total: %d/%d tests%s, %g/%g points%s' % (contexts[0].ncorrect, contexts[0].ntotal, valued, weighted, prob.config.taskweight, before_weighting)) | 208 say('Problem total: %d/%d tests%s, %g/%g points%s' % (contexts[0].ncorrect, contexts[0].ntotal, valued, weighted, prob.config.taskweight, before_weighting)) |
206 sys.stdout.flush() | 209 sys.stdout.flush() |
207 return weighted, prob.config.taskweight | 210 return weighted, prob.config.taskweight |
208 finally: | 211 finally: |
209 if options.erase and (not prob.config.stdio or case and | 212 if options.erase and case and case.has_iofiles: |
210 (case.validator and not callable(case.validator))): | |
211 for var in 'in', 'out': | 213 for var in 'in', 'out': |
212 name = getattr(prob.config, var + 'name') | 214 name = getattr(prob.config, var + 'name') |
213 if name: | 215 if name: |
214 try: | 216 try: |
215 os.remove(name) | 217 os.remove(name) |
216 except Exception: | 218 except Exception: |
217 pass | 219 pass |
218 if case.validator and not callable(case.validator): | 220 if case.has_ansfile: |
219 if prob.config.ansname: | 221 if prob.config.ansname: |
220 try: | 222 try: |
221 os.remove(prob.config.ansname) | 223 os.remove(prob.config.ansname) |
222 except Exception: | 224 except Exception: |
223 pass | 225 pass |