Mercurial > ~astiob > upreckon > hgweb
annotate upreckon/problem.py @ 193:a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Specify match='regexp', and your tests and dummies will be treated
as regular expressions describing test case identifiers. Every file that
is in a suitable location and whose name matches {testcase,dummy}inname
and the given regexp will be treated as a file with test case input data.
You are free to use backreferences in the regexps, but group numbering
starts at two rather than one.
If you want test groups, you can get them magically created for you
by putting a part of the test ID in a group in the regexp sense
and specifying the tests variable as a pair consisting of the regexp
itself and the number of this regexp group (remember group numbers start
at two).
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Thu, 11 Aug 2011 23:20:52 +0300 |
parents | 0480dfa50366 |
children | 67088c1765b4 |
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 |
21 | 3 from __future__ import division, with_statement |
4 | |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
5 from .compat import * |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
6 from .exceptions import * |
193
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
7 from . import config, files, testcases |
91 | 8 from __main__ import options |
21 | 9 |
22 | 10 import os, re, sys |
21 | 11 |
16 | 12 try: |
75
007f7eb6fb2b
The test context stack is now a deque.
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
13 from collections import deque |
007f7eb6fb2b
The test context stack is now a deque.
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
14 except ImportError: |
007f7eb6fb2b
The test context stack is now a deque.
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
15 deque = list |
007f7eb6fb2b
The test context stack is now a deque.
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
16 |
007f7eb6fb2b
The test context stack is now a deque.
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
17 try: |
21 | 18 import signal |
19 except ImportError: | |
20 signalnames = () | |
21 else: | |
22 # Construct a cache of all signal names available on the current | |
23 # platform. Prefer names from the UNIX standards over other versions. | |
24 unixnames = frozenset(('HUP', 'INT', 'QUIT', 'ILL', 'ABRT', 'FPE', 'KILL', 'SEGV', 'PIPE', 'ALRM', 'TERM', 'USR1', 'USR2', 'CHLD', 'CONT', 'STOP', 'TSTP', 'TTIN', 'TTOU', 'BUS', 'POLL', 'PROF', 'SYS', 'TRAP', 'URG', 'VTALRM', 'XCPU', 'XFSZ')) | |
25 signalnames = {} | |
26 for name in dir(signal): | |
27 if re.match('SIG[A-Z]+$', name): | |
28 value = signal.__dict__[name] | |
22 | 29 if isinstance(value, int) and (value not in signalnames or name[3:] in unixnames): |
21 | 30 signalnames[value] = name |
31 del unixnames | |
16 | 32 |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
33 __all__ = 'Problem', 'TestContext', 'test_context_end', 'TestGroup' |
21 | 34 |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
35 |
26 | 36 def strerror(e): |
135
523ba6907f3a
Corrected a typo (hopefully) in problem.strerror
Oleg Oshmyan <chortos@inbox.lv>
parents:
94
diff
changeset
|
37 s = getattr(e, 'strerror', None) |
26 | 38 if not s: s = str(e) |
39 return ' (%s%s)' % (s[0].lower(), s[1:]) if s else '' | |
21 | 40 |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
41 |
21 | 42 class Cache(object): |
43 def __init__(self, mydict): | |
44 self.__dict__ = mydict | |
16 | 45 |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
46 |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
47 class TestContext(object): |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
48 __slots__ = () |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
49 |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
50 test_context_end = object() |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
51 |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
52 class TestGroup(TestContext): |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
53 __slots__ = 'points', 'case', 'log', 'correct', 'allcorrect', 'real', 'max', 'ntotal', 'nvalued', 'ncorrect', 'ncorrectvalued' |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
54 |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
55 def __init__(self, points=None): |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
56 self.points = points |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
57 self.real = self.max = self.ntotal = self.nvalued = self.ncorrect = self.ncorrectvalued = 0 |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
58 self.allcorrect = True |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
59 self.log = [] |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
60 |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
61 def case_start(self, case): |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
62 self.case = case |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
63 self.correct = False |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
64 self.ntotal += 1 |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
65 if case.points: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
66 self.nvalued += 1 |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
67 |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
68 def case_correct(self): |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
69 self.correct = True |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
70 self.ncorrect += 1 |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
71 if self.case.points: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
72 self.ncorrectvalued += 1 |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
73 |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
74 def case_end(self): |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
75 self.log.append((self.case, self.correct)) |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
76 del self.case |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
77 if not self.correct: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
78 self.allcorrect = False |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
79 |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
80 def score(self, real, max): |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
81 self.real += real |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
82 self.max += max |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
83 |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
84 def end(self): |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
85 if not self.allcorrect: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
86 self.real = 0 |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
87 if self.points is not None and self.points != self.max: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
88 max, weighted = self.points, self.real * self.points / self.max if self.max else 0 |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
89 before_weighting = ' (%g/%g before weighting)' % (self.real, self.max) |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
90 else: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
91 max, weighted = self.max, self.real |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
92 before_weighting = '' |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
93 say('Group total: %d/%d tests, %g/%g points%s' % (self.ncorrect, self.ntotal, weighted, max, before_weighting)) |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
94 # No real need to flush stdout, as it will anyway be flushed in a moment, |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
95 # when either the problem total or the next test case's ID is printed |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
96 return weighted, max, self.log |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
97 |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
98 class DummyTestGroup(TestGroup): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
99 __slots__ = () |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
100 def end(self): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
101 say('Sample total: %d/%d tests' % (self.ncorrect, self.ntotal)) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
102 return 0, 0, self.log |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
103 |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
104 |
16 | 105 class Problem(object): |
106 __slots__ = 'name', 'config', 'cache', 'testcases' | |
107 | |
108 def __init__(prob, name): | |
109 if not isinstance(name, basestring): | |
110 # This shouldn't happen, of course | |
21 | 111 raise TypeError('Problem() argument 1 must be string, not ' + type(name).__name__) |
16 | 112 prob.name = name |
21 | 113 prob.config = config.load_problem(name) |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
114 prob.cache = Cache({'padoutput': 0}) |
179
a55a1e00e121
Renamed load_problem to load_testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
149
diff
changeset
|
115 prob.testcases = load_testcases(prob) |
21 | 116 |
117 # TODO | |
118 def build(prob): | |
119 raise NotImplementedError | |
16 | 120 |
121 def test(prob): | |
23 | 122 case = None |
22 | 123 try: |
75
007f7eb6fb2b
The test context stack is now a deque.
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
124 contexts = deque((TestGroup(),)) |
22 | 125 for case in prob.testcases: |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
126 if case is test_context_end: |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
127 real, max, log = contexts.pop().end() |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
128 for case, correct in log: |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
129 contexts[-1].case_start(case) |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
130 if correct: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
131 contexts[-1].case_correct() |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
132 contexts[-1].case_end() |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
133 contexts[-1].score(real, max) |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
134 continue |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
135 elif isinstance(case, TestContext): |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
136 contexts.append(case) |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
137 continue |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
138 contexts[-1].case_start(case) |
22 | 139 granted = 0 |
140 id = str(case.id) | |
141 if case.isdummy: | |
142 id = 'sample ' + id | |
143 say('%*s: ' % (prob.cache.padoutput, id), end='') | |
144 sys.stdout.flush() | |
145 try: | |
145
d2c266c8d820
Output-only problems no longer print times
Oleg Oshmyan <chortos@inbox.lv>
parents:
135
diff
changeset
|
146 if prob.config.kind != 'outonly': |
d2c266c8d820
Output-only problems no longer print times
Oleg Oshmyan <chortos@inbox.lv>
parents:
135
diff
changeset
|
147 granted = case(lambda: (say('%7.3f%s s, ' % (case.time_stopped - case.time_started, case.time_limit_string), end=''), sys.stdout.flush())) |
d2c266c8d820
Output-only problems no longer print times
Oleg Oshmyan <chortos@inbox.lv>
parents:
135
diff
changeset
|
148 else: |
d2c266c8d820
Output-only problems no longer print times
Oleg Oshmyan <chortos@inbox.lv>
parents:
135
diff
changeset
|
149 granted = case(lambda: None) |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
150 except TestCaseSkipped: |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
151 verdict = 'skipped due to skimming mode' |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
152 except CanceledByUser: |
22 | 153 verdict = 'canceled by the user' |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
154 except WallTimeLimitExceeded: |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
77
diff
changeset
|
155 verdict = 'wall-clock time limit exceeded' |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
156 except CPUTimeLimitExceeded: |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
77
diff
changeset
|
157 verdict = 'CPU time limit exceeded' |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
158 except MemoryLimitExceeded: |
77
69eadc60f4e2
Memory limit is now applied to the RSS when os.wait4 is available
Oleg Oshmyan <chortos@inbox.lv>
parents:
76
diff
changeset
|
159 verdict = 'memory limit exceeded' |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
160 except WrongAnswer: |
22 | 161 e = sys.exc_info()[1] |
162 if e.comment: | |
163 verdict = 'wrong answer (%s)' % e.comment | |
164 else: | |
165 verdict = 'wrong answer' | |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
166 except NonZeroExitCode: |
22 | 167 e = sys.exc_info()[1] |
168 if e.exitcode < 0: | |
169 if sys.platform == 'win32': | |
170 verdict = 'terminated with error 0x%X' % (e.exitcode + 0x100000000) | |
171 elif -e.exitcode in signalnames: | |
172 verdict = 'terminated by signal %d (%s)' % (-e.exitcode, signalnames[-e.exitcode]) | |
173 else: | |
174 verdict = 'terminated by signal %d' % -e.exitcode | |
21 | 175 else: |
22 | 176 verdict = 'non-zero return code %d' % e.exitcode |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
177 except CannotStartTestee: |
26 | 178 verdict = 'cannot launch the program to test%s' % strerror(sys.exc_info()[1].upstream) |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
179 except CannotStartValidator: |
26 | 180 verdict = 'cannot launch the validator%s' % strerror(sys.exc_info()[1].upstream) |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
181 except CannotReadOutputFile: |
26 | 182 verdict = 'cannot read the output file%s' % strerror(sys.exc_info()[1].upstream) |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
183 except CannotReadInputFile: |
26 | 184 verdict = 'cannot read the input file%s' % strerror(sys.exc_info()[1].upstream) |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
185 except CannotReadAnswerFile: |
26 | 186 verdict = 'cannot read the reference output file%s' % strerror(sys.exc_info()[1].upstream) |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
187 except ExceptionWrapper: |
189
0480dfa50366
Corrected the remaining wrong references to test.py
Oleg Oshmyan <chortos@inbox.lv>
parents:
179
diff
changeset
|
188 verdict = 'unspecified reason [this may be a bug in Upreckon]%s' % strerror(sys.exc_info()[1].upstream) |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
189 except TestCaseNotPassed: |
189
0480dfa50366
Corrected the remaining wrong references to test.py
Oleg Oshmyan <chortos@inbox.lv>
parents:
179
diff
changeset
|
190 verdict = 'unspecified reason [this may be a bug in Upreckon]%s' % strerror(sys.exc_info()[1]) |
22 | 191 #except Exception: |
189
0480dfa50366
Corrected the remaining wrong references to test.py
Oleg Oshmyan <chortos@inbox.lv>
parents:
179
diff
changeset
|
192 # verdict = 'unknown error [this may be a bug in Upreckon]%s' % strerror(sys.exc_info()[1]) |
21 | 193 else: |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
194 try: |
22 | 195 granted, comment = granted |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
196 except TypeError: |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
197 comment = '' |
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
198 else: |
22 | 199 if comment: |
200 comment = ' (%s)' % comment | |
24
c23d81f4a1a3
Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
201 if granted >= 1: |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
202 contexts[-1].case_correct() |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
203 prob.testcases.send(True) |
22 | 204 verdict = 'OK' + comment |
205 elif not granted: | |
206 verdict = 'wrong answer' + comment | |
207 else: | |
208 verdict = 'partly correct' + comment | |
26 | 209 granted *= case.points |
22 | 210 say('%g/%g, %s' % (granted, case.points, verdict)) |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
211 contexts[-1].case_end() |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
212 contexts[-1].score(granted, case.points) |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
213 weighted = contexts[0].real * prob.config.taskweight / contexts[0].max if contexts[0].max else 0 |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
214 before_weighting = valued = '' |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
215 if prob.config.taskweight != contexts[0].max: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
216 before_weighting = ' (%g/%g before weighting)' % (contexts[0].real, contexts[0].max) |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
217 if contexts[0].nvalued != contexts[0].ntotal: |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
218 valued = ' (%d/%d valued)' % (contexts[0].ncorrectvalued, contexts[0].nvalued) |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
75
diff
changeset
|
219 say('Problem total: %d/%d tests%s, %g/%g points%s' % (contexts[0].ncorrect, contexts[0].ntotal, valued, weighted, prob.config.taskweight, before_weighting)) |
39
2b459f9743b4
Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
220 sys.stdout.flush() |
22 | 221 return weighted, prob.config.taskweight |
222 finally: | |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
223 if options.erase and case and case.has_iofiles: |
22 | 224 for var in 'in', 'out': |
225 name = getattr(prob.config, var + 'name') | |
226 if name: | |
227 try: | |
228 os.remove(name) | |
229 except Exception: | |
230 pass | |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
88
diff
changeset
|
231 if case.has_ansfile: |
22 | 232 if prob.config.ansname: |
233 try: | |
234 os.remove(prob.config.ansname) | |
235 except Exception: | |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
236 pass |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
237 |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
238 |
179
a55a1e00e121
Renamed load_problem to load_testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
149
diff
changeset
|
239 def load_testcases(prob, _types={'batch' : testcases.BatchTestCase, |
a55a1e00e121
Renamed load_problem to load_testcases
Oleg Oshmyan <chortos@inbox.lv>
parents:
149
diff
changeset
|
240 'outonly': testcases.OutputOnlyTestCase}): |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
241 # We will need to iterate over these configuration variables twice |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
242 try: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
243 len(prob.config.dummies) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
244 except Exception: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
245 prob.config.dummies = tuple(prob.config.dummies) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
246 try: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
247 len(prob.config.tests) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
248 except Exception: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
249 prob.config.tests = tuple(prob.config.tests) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
250 |
193
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
251 if prob.config.match == 're': |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
252 if not prob.config.usegroups: |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
253 prob.config.tests = prob.config.tests, None |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
254 elif isinstance(prob.config.tests, basestring): |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
255 prob.config.tests = prob.config.tests, 2 |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
256 parts = tuple(map(re.escape, prob.config.dummyinname.split('$'))) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
257 probname = re.escape(prob.name) + '/' if prob.name != os.curdir else '' |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
258 path = '%s%s(%s)' % (probname, parts[0], prob.config.dummies) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
259 path += r'\1'.join(parts[1:]) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
260 prob.config.dummies = regexp(path, None) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
261 parts = tuple(map(re.escape, prob.config.testcaseinname.split('$'))) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
262 path = '%s%s(%s)' % (probname, parts[0], prob.config.tests[0]) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
263 path += r'\1'.join(parts[1:]) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
264 prob.config.tests = regexp(path, prob.config.tests[1]) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
265 |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
266 if options.legacy: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
267 prob.config.usegroups = False |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
268 newtests = [] |
149 | 269 for name in prob.config.tests: |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
270 # Same here; we'll need to iterate over them twice |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
271 try: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
272 l = len(name) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
273 except Exception: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
274 try: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
275 name = tuple(name) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
276 except TypeError: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
277 name = (name,) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
278 l = len(name) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
279 if l > 1: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
280 prob.config.usegroups = True |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
281 newtests.append(name) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
282 if prob.config.usegroups: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
283 prob.config.tests = newtests |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
284 del newtests |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
285 |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
286 # Even if they have duplicate test identifiers, we must honour sequence pointmaps |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
287 if isinstance(prob.config.pointmap, dict): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
288 def getpoints(i, j, k=None): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
289 try: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
290 return prob.config.pointmap[i] |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
291 except KeyError: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
292 try: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
293 return prob.config.pointmap[None] |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
294 except KeyError: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
295 return prob.config.maxexitcode or 1 |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
296 elif prob.config.usegroups: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
297 def getpoints(i, j, k): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
298 try: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
299 return prob.config.pointmap[k][j] |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
300 except LookupError: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
301 return prob.config.maxexitcode or 1 |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
302 else: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
303 def getpoints(i, j): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
304 try: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
305 return prob.config.pointmap[j] |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
306 except LookupError: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
307 return prob.config.maxexitcode or 1 |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
308 |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
309 # First get prob.cache.padoutput right, |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
310 # then yield the actual test cases |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
311 for i in prob.config.dummies: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
312 s = 'sample ' + str(i).zfill(prob.config.paddummies) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
313 prob.cache.padoutput = max(prob.cache.padoutput, len(s)) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
314 if prob.config.usegroups: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
315 if not isinstance(prob.config.groupweight, dict): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
316 prob.config.groupweight = dict(enumerate(prob.config.groupweight)) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
317 for group in prob.config.tests: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
318 for i in group: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
319 s = str(i).zfill(prob.config.padtests) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
320 prob.cache.padoutput = max(prob.cache.padoutput, len(s)) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
321 if prob.config.dummies: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
322 yield DummyTestGroup() |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
323 for i in prob.config.dummies: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
324 s = str(i).zfill(prob.config.paddummies) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
325 if (yield _types[prob.config.kind](prob, s, True, 0)): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
326 yield |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
327 yield test_context_end |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
328 for k, group in enumerate(prob.config.tests): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
329 if not group: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
330 continue |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
331 yield TestGroup(prob.config.groupweight.get(k, prob.config.groupweight.get(None))) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
332 case_type = _types[prob.config.kind] |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
333 for j, i in enumerate(group): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
334 s = str(i).zfill(prob.config.padtests) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
335 if not (yield case_type(prob, s, False, getpoints(i, j, k))): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
336 if options.skim: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
337 case_type = testcases.SkippedTestCase |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
338 else: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
339 yield |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
340 yield test_context_end |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
341 else: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
342 for i in prob.config.tests: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
343 s = str(i).zfill(prob.config.padtests) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
344 prob.cache.padoutput = max(prob.cache.padoutput, len(s)) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
345 for i in prob.config.dummies: |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
346 s = str(i).zfill(prob.config.paddummies) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
347 if (yield _types[prob.config.kind](prob, s, True, 0)): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
348 yield |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
349 for j, i in enumerate(prob.config.tests): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
350 s = str(i).zfill(prob.config.padtests) |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
351 if (yield _types[prob.config.kind](prob, s, False, getpoints(i, j))): |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
145
diff
changeset
|
352 yield |
193
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
353 |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
354 def regexp(pattern, group): |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
355 reobj = re.compile(pattern, re.UNICODE) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
356 if not group: |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
357 ids = [] |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
358 for path, vpath in files.regexp(pattern): |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
359 ids.append(re.match(reobj, vpath).group(1)) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
360 return natsorted(ids) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
361 else: |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
362 ids = {} |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
363 for path, vpath in files.regexp(pattern): |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
364 m = re.match(reobj, vpath) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
365 g = m.group(group) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
366 ids.setdefault(g, []) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
367 ids[g].append(m.group(1)) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
368 for g in ids: |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
369 ids[g] = natsorted(ids[g]) |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
370 return [ids[g] for g in natsorted(keys(ids))] |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
371 |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
372 def natsorted(l): |
a76cdc26ba9d
Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents:
189
diff
changeset
|
373 return sorted(l, key=lambda s: [int(t) if t.isdigit() else t for t in re.split('(\d+)', s)]) |