annotate upreckon/problem.py @ 205:166a23999bf7

Added confvar okexitcodemask; changed the validator protocol Callable validators now return three-tuples (number granted, bool correct, str comment) instead of two-tuples (number granted, str comment). They are still allowed to return single numbers. Callable validators must now explicitly raise upreckon.exceptions.WrongAnswer if they want the verdict to be Wrong Answer rather than Partly Correct. okexitcodemask specifies a bitmask ANDed with the exit code of the external validator to get a boolean flag showing whether the answer is to be marked as 'OK' rather than 'partly correct'. The bits covered by the bitmask are reset to zeroes before devising the number of points granted from the resulting number.
author Oleg Oshmyan <chortos@inbox.lv>
date Wed, 17 Aug 2011 20:44:54 +0300
parents 67088c1765b4
children c03a8113685d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
2
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
3 from __future__ import division, with_statement
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
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
c62c9bfd614a Removed import_error
Oleg Oshmyan <chortos@inbox.lv>
parents: 90
diff changeset
8 from __main__ import options
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
9
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
10 import os, re, sys
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
11
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
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
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
18 import signal
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
19 except ImportError:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
20 signalnames = ()
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
21 else:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
22 # Construct a cache of all signal names available on the current
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
23 # platform. Prefer names from the UNIX standards over other versions.
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
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'))
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
25 signalnames = {}
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
26 for name in dir(signal):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
27 if re.match('SIG[A-Z]+$', name):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
28 value = signal.__dict__[name]
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
29 if isinstance(value, int) and (value not in signalnames or name[3:] in unixnames):
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
30 signalnames[value] = name
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
31 del unixnames
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
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
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
34
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
35
26
5bbb68833868 Output text improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
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
5bbb68833868 Output text improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
38 if not s: s = str(e)
5bbb68833868 Output text improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
39 return ' (%s%s)' % (s[0].lower(), s[1:]) if s else ''
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
40
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
41
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
42 class Cache(object):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
43 def __init__(self, mydict):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
44 self.__dict__ = mydict
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
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
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
105 class Problem(object):
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
106 __slots__ = 'name', 'config', 'cache', 'testcases'
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
107
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
108 def __init__(prob, name):
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
109 if not isinstance(name, basestring):
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
110 # This shouldn't happen, of course
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
111 raise TypeError('Problem() argument 1 must be string, not ' + type(name).__name__)
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
112 prob.name = name
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
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
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
116
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
117 # TODO
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
118 def build(prob):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
119 raise NotImplementedError
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
120
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
121 def test(prob):
23
c1f52b5d80d6 Compatibility and bug fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 22
diff changeset
122 case = None
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
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
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
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
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
139 granted = 0
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
140 id = str(case.id)
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
141 if case.isdummy:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
142 id = 'sample ' + id
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
143 say('%*s: ' % (prob.cache.padoutput, id), end='')
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
144 sys.stdout.flush()
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
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
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
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
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
161 e = sys.exc_info()[1]
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
162 if e.comment:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
163 verdict = 'wrong answer (%s)' % e.comment
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
164 else:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
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
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
167 e = sys.exc_info()[1]
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
168 if e.exitcode < 0:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
169 if sys.platform == 'win32':
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
170 verdict = 'terminated with error 0x%X' % (e.exitcode + 0x100000000)
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
171 elif -e.exitcode in signalnames:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
172 verdict = 'terminated by signal %d (%s)' % (-e.exitcode, signalnames[-e.exitcode])
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
173 else:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
174 verdict = 'terminated by signal %d' % -e.exitcode
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
175 else:
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
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
5bbb68833868 Output text improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
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
5bbb68833868 Output text improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
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
5bbb68833868 Output text improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
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
5bbb68833868 Output text improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
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
5bbb68833868 Output text improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
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
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
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
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
193 else:
39
2b459f9743b4 Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents: 26
diff changeset
194 try:
205
166a23999bf7 Added confvar okexitcodemask; changed the validator protocol
Oleg Oshmyan <chortos@inbox.lv>
parents: 196
diff changeset
195 granted, correct, 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 = ''
205
166a23999bf7 Added confvar okexitcodemask; changed the validator protocol
Oleg Oshmyan <chortos@inbox.lv>
parents: 196
diff changeset
198 correct = granted >= 1
39
2b459f9743b4 Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents: 26
diff changeset
199 else:
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
200 if comment:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
201 comment = ' (%s)' % comment
205
166a23999bf7 Added confvar okexitcodemask; changed the validator protocol
Oleg Oshmyan <chortos@inbox.lv>
parents: 196
diff changeset
202 if correct:
39
2b459f9743b4 Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents: 26
diff changeset
203 contexts[-1].case_correct()
90
1fb319ec33af Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents: 88
diff changeset
204 prob.testcases.send(True)
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
205 verdict = 'OK' + comment
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
206 else:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
207 verdict = 'partly correct' + comment
26
5bbb68833868 Output text improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
208 granted *= case.points
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
209 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
210 contexts[-1].case_end()
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 75
diff changeset
211 contexts[-1].score(granted, case.points)
39
2b459f9743b4 Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents: 26
diff changeset
212 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
213 before_weighting = valued = ''
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 75
diff changeset
214 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
215 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
216 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
217 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
218 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
219 sys.stdout.flush()
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
220 return weighted, prob.config.taskweight
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
221 finally:
90
1fb319ec33af Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents: 88
diff changeset
222 if options.erase and case and case.has_iofiles:
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
223 for var in 'in', 'out':
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
224 name = getattr(prob.config, var + 'name')
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
225 if name:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
226 try:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
227 os.remove(name)
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
228 except Exception:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
229 pass
90
1fb319ec33af Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents: 88
diff changeset
230 if case.has_ansfile:
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
231 if prob.config.ansname:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
232 try:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
233 os.remove(prob.config.ansname)
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
234 except Exception:
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
235 pass
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
236
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
237
179
a55a1e00e121 Renamed load_problem to load_testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 149
diff changeset
238 def load_testcases(prob, _types={'batch' : testcases.BatchTestCase,
a55a1e00e121 Renamed load_problem to load_testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 149
diff changeset
239 'outonly': testcases.OutputOnlyTestCase}):
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
240 # 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
241 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
242 len(prob.config.dummies)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
243 except Exception:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
244 prob.config.dummies = tuple(prob.config.dummies)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
245 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
246 len(prob.config.tests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
247 except Exception:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
248 prob.config.tests = tuple(prob.config.tests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
249
193
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
250 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
251 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
252 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
253 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
254 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
255 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
256 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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
265 if options.legacy:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
266 prob.config.usegroups = False
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
267 newtests = []
149
a1286da36d29 Small clean-up
Oleg Oshmyan <chortos@inbox.lv>
parents: 146
diff changeset
268 for name in prob.config.tests:
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
269 # 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
270 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
271 l = len(name)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
272 except Exception:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
273 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
274 name = tuple(name)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
275 except TypeError:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
276 name = (name,)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
277 l = len(name)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
278 if l > 1:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
279 prob.config.usegroups = True
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
280 newtests.append(name)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
281 if prob.config.usegroups:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
282 prob.config.tests = newtests
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
283 del newtests
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
284
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
285 # 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
286 if isinstance(prob.config.pointmap, dict):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
287 def getpoints(i, j, k=None):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
288 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
289 return prob.config.pointmap[i]
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
290 except KeyError:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
291 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
292 return prob.config.pointmap[None]
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
293 except KeyError:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
294 return prob.config.maxexitcode or 1
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
295 elif prob.config.usegroups:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
296 def getpoints(i, j, k):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
297 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
298 return prob.config.pointmap[k][j]
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
299 except LookupError:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
300 return prob.config.maxexitcode or 1
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
301 else:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
302 def getpoints(i, j):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
303 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
304 return prob.config.pointmap[j]
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
305 except LookupError:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
306 return prob.config.maxexitcode or 1
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
307
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
308 # First get prob.cache.padoutput right,
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
309 # then yield the actual test cases
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
310 for i in prob.config.dummies:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
311 s = 'sample ' + str(i).zfill(prob.config.paddummies)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
312 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
313 if prob.config.usegroups:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
314 if not isinstance(prob.config.groupweight, dict):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
315 prob.config.groupweight = dict(enumerate(prob.config.groupweight))
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
316 for group in prob.config.tests:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
317 for i in group:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
318 s = str(i).zfill(prob.config.padtests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
319 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
320 if prob.config.dummies:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
321 yield DummyTestGroup()
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
322 for i in prob.config.dummies:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
323 s = str(i).zfill(prob.config.paddummies)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
324 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
325 yield
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
326 yield test_context_end
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
327 for k, group in enumerate(prob.config.tests):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
328 if not group:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
329 continue
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
330 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
331 case_type = _types[prob.config.kind]
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
332 for j, i in enumerate(group):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
333 s = str(i).zfill(prob.config.padtests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
334 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
335 if options.skim:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
336 case_type = testcases.SkippedTestCase
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
337 else:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
338 yield
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
339 yield test_context_end
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
340 else:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
341 for i in prob.config.tests:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
342 s = str(i).zfill(prob.config.padtests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
343 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
344 for i in prob.config.dummies:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
345 s = str(i).zfill(prob.config.paddummies)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
346 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
347 yield
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
348 for j, i in enumerate(prob.config.tests):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
349 s = str(i).zfill(prob.config.padtests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
350 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
351 yield
193
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
352
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
353 def regexp(pattern, group):
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
354 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
355 if not group:
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
356 ids = []
196
67088c1765b4 Regexps now work with test archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 193
diff changeset
357 for f in files.regexp(pattern):
67088c1765b4 Regexps now work with test archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 193
diff changeset
358 ids.append(re.match(reobj, f.virtual_path).group(1))
193
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
359 return natsorted(ids)
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
360 else:
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
361 ids = {}
196
67088c1765b4 Regexps now work with test archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 193
diff changeset
362 for f in files.regexp(pattern):
67088c1765b4 Regexps now work with test archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 193
diff changeset
363 m = re.match(reobj, f.virtual_path)
193
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
364 g = m.group(group)
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
365 ids.setdefault(g, [])
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
366 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
367 for g in ids:
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
368 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
369 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
370
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
371 def natsorted(l):
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
372 return sorted(l, key=lambda s: [int(t) if t.isdigit() else t for t in re.split('(\d+)', s)])