annotate upreckon/problem.py @ 255:d32b14e5a43b default tip

Added support for LZMA/XZ-compressed tar files (Python 3.3+)
author Oleg Oshmyan <chortos@inbox.lv>
date Sun, 19 Oct 2014 01:33:22 +0200
parents 2798cbebd83a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
232
f94f9724c543 Switched from str to bytes for external validator output
Oleg Oshmyan <chortos@inbox.lv>
parents: 209
diff changeset
1 # Copyright (c) 2010-2012 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()
240
2798cbebd83a Re-allowed callable output validators to give comments as Unicode strings
Oleg Oshmyan <chortos@inbox.lv>
parents: 233
diff changeset
145 comment = ''
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
146 try:
145
d2c266c8d820 Output-only problems no longer print times
Oleg Oshmyan <chortos@inbox.lv>
parents: 135
diff changeset
147 if prob.config.kind != 'outonly':
d2c266c8d820 Output-only problems no longer print times
Oleg Oshmyan <chortos@inbox.lv>
parents: 135
diff changeset
148 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
149 else:
d2c266c8d820 Output-only problems no longer print times
Oleg Oshmyan <chortos@inbox.lv>
parents: 135
diff changeset
150 granted = case(lambda: None)
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
151 except TestCaseSkipped:
90
1fb319ec33af Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents: 88
diff changeset
152 verdict = 'skipped due to skimming mode'
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
153 except CanceledByUser:
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
154 verdict = 'canceled by the user'
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
155 except WallTimeLimitExceeded:
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents: 77
diff changeset
156 verdict = 'wall-clock time limit exceeded'
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
157 except CPUTimeLimitExceeded:
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents: 77
diff changeset
158 verdict = 'CPU time limit exceeded'
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
159 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
160 verdict = 'memory limit exceeded'
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
161 except WrongAnswer:
232
f94f9724c543 Switched from str to bytes for external validator output
Oleg Oshmyan <chortos@inbox.lv>
parents: 209
diff changeset
162 verdict = 'wrong answer'
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
163 e = sys.exc_info()[1]
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
164 if e.comment:
232
f94f9724c543 Switched from str to bytes for external validator output
Oleg Oshmyan <chortos@inbox.lv>
parents: 209
diff changeset
165 comment = e.comment
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:
205
166a23999bf7 Added confvar okexitcodemask; changed the validator protocol
Oleg Oshmyan <chortos@inbox.lv>
parents: 196
diff changeset
197 correct = granted >= 1
166a23999bf7 Added confvar okexitcodemask; changed the validator protocol
Oleg Oshmyan <chortos@inbox.lv>
parents: 196
diff changeset
198 if correct:
39
2b459f9743b4 Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents: 26
diff changeset
199 contexts[-1].case_correct()
90
1fb319ec33af Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents: 88
diff changeset
200 prob.testcases.send(True)
232
f94f9724c543 Switched from str to bytes for external validator output
Oleg Oshmyan <chortos@inbox.lv>
parents: 209
diff changeset
201 verdict = 'OK'
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
202 else:
232
f94f9724c543 Switched from str to bytes for external validator output
Oleg Oshmyan <chortos@inbox.lv>
parents: 209
diff changeset
203 verdict = 'partly correct'
26
5bbb68833868 Output text improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
204 granted *= case.points
232
f94f9724c543 Switched from str to bytes for external validator output
Oleg Oshmyan <chortos@inbox.lv>
parents: 209
diff changeset
205 if comment:
f94f9724c543 Switched from str to bytes for external validator output
Oleg Oshmyan <chortos@inbox.lv>
parents: 209
diff changeset
206 say('%g/%g, %s (' % (granted, case.points, verdict), end='')
240
2798cbebd83a Re-allowed callable output validators to give comments as Unicode strings
Oleg Oshmyan <chortos@inbox.lv>
parents: 233
diff changeset
207 if isinstance(comment, type(''.encode())) and hasattr(sys.stdout, 'buffer'):
2798cbebd83a Re-allowed callable output validators to give comments as Unicode strings
Oleg Oshmyan <chortos@inbox.lv>
parents: 233
diff changeset
208 sys.stdout.flush()
233
54cdc583ab77 Fixed crashing on validator output on Python 2 (regression in f94f9724c543)
Oleg Oshmyan <chortos@inbox.lv>
parents: 232
diff changeset
209 sys.stdout.buffer.write(comment)
240
2798cbebd83a Re-allowed callable output validators to give comments as Unicode strings
Oleg Oshmyan <chortos@inbox.lv>
parents: 233
diff changeset
210 else:
2798cbebd83a Re-allowed callable output validators to give comments as Unicode strings
Oleg Oshmyan <chortos@inbox.lv>
parents: 233
diff changeset
211 say(comment, end='')
232
f94f9724c543 Switched from str to bytes for external validator output
Oleg Oshmyan <chortos@inbox.lv>
parents: 209
diff changeset
212 say(')')
f94f9724c543 Switched from str to bytes for external validator output
Oleg Oshmyan <chortos@inbox.lv>
parents: 209
diff changeset
213 else:
f94f9724c543 Switched from str to bytes for external validator output
Oleg Oshmyan <chortos@inbox.lv>
parents: 209
diff changeset
214 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
215 contexts[-1].case_end()
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 75
diff changeset
216 contexts[-1].score(granted, case.points)
39
2b459f9743b4 Test groups are now supported
Oleg Oshmyan <chortos@inbox.lv>
parents: 26
diff changeset
217 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
218 before_weighting = valued = ''
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 75
diff changeset
219 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
220 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
221 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
222 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
223 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
224 sys.stdout.flush()
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
225 return weighted, prob.config.taskweight
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
226 finally:
90
1fb319ec33af Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents: 88
diff changeset
227 if options.erase and case and case.has_iofiles:
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
228 for var in 'in', 'out':
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
229 name = getattr(prob.config, var + 'name')
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
230 if name:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
231 try:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
232 os.remove(name)
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
233 except Exception:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
234 pass
90
1fb319ec33af Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents: 88
diff changeset
235 if case.has_ansfile:
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
236 if prob.config.ansname:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
237 try:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
238 os.remove(prob.config.ansname)
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
239 except Exception:
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
240 pass
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
241
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
242
179
a55a1e00e121 Renamed load_problem to load_testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 149
diff changeset
243 def load_testcases(prob, _types={'batch' : testcases.BatchTestCase,
a55a1e00e121 Renamed load_problem to load_testcases
Oleg Oshmyan <chortos@inbox.lv>
parents: 149
diff changeset
244 'outonly': testcases.OutputOnlyTestCase}):
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
245 # 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
246 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
247 len(prob.config.dummies)
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.dummies = tuple(prob.config.dummies)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
250 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
251 len(prob.config.tests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
252 except Exception:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
253 prob.config.tests = tuple(prob.config.tests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
254
193
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
255 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
256 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
257 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
258 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
259 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
260 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
261 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
262 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
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.dummies = regexp(path, None)
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
265 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
266 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
267 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
268 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
269
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
270 if options.legacy:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
271 prob.config.usegroups = False
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
272 newtests = []
149
a1286da36d29 Small clean-up
Oleg Oshmyan <chortos@inbox.lv>
parents: 146
diff changeset
273 for name in prob.config.tests:
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
274 # 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
275 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
276 l = len(name)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
277 except Exception:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
278 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
279 name = tuple(name)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
280 except TypeError:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
281 name = (name,)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
282 l = len(name)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
283 if l > 1:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
284 prob.config.usegroups = True
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
285 newtests.append(name)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
286 if prob.config.usegroups:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
287 prob.config.tests = newtests
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
288 del newtests
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
289
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
290 # 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
291 if isinstance(prob.config.pointmap, dict):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
292 def getpoints(i, j, k=None):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
293 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
294 return prob.config.pointmap[i]
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
295 except KeyError:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
296 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
297 return prob.config.pointmap[None]
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
298 except KeyError:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
299 return prob.config.maxexitcode or 1
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
300 elif prob.config.usegroups:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
301 def getpoints(i, j, k):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
302 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
303 return prob.config.pointmap[k][j]
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
304 except LookupError:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
305 return prob.config.maxexitcode or 1
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
306 else:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
307 def getpoints(i, j):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
308 try:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
309 return prob.config.pointmap[j]
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
310 except LookupError:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
311 return prob.config.maxexitcode or 1
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
312
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
313 # First get prob.cache.padoutput right,
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
314 # then yield the actual test cases
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
315 for i in prob.config.dummies:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
316 s = 'sample ' + str(i).zfill(prob.config.paddummies)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
317 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
318 if prob.config.usegroups:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
319 if not isinstance(prob.config.groupweight, dict):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
320 prob.config.groupweight = dict(enumerate(prob.config.groupweight))
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
321 for group in prob.config.tests:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
322 for i in group:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
323 s = str(i).zfill(prob.config.padtests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
324 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
325 if prob.config.dummies:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
326 yield DummyTestGroup()
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
327 for i in prob.config.dummies:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
328 s = str(i).zfill(prob.config.paddummies)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
329 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
330 yield
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
331 yield test_context_end
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
332 for k, group in enumerate(prob.config.tests):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
333 if not group:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
334 continue
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
335 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
336 case_type = _types[prob.config.kind]
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
337 for j, i in enumerate(group):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
338 s = str(i).zfill(prob.config.padtests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
339 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
340 if options.skim:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
341 case_type = testcases.SkippedTestCase
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
342 else:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
343 yield
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
344 yield test_context_end
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
345 else:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
346 for i in prob.config.tests:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
347 s = str(i).zfill(prob.config.padtests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
348 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
349 for i in prob.config.dummies:
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
350 s = str(i).zfill(prob.config.paddummies)
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, True, 0)):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
352 yield
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
353 for j, i in enumerate(prob.config.tests):
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
354 s = str(i).zfill(prob.config.padtests)
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 145
diff changeset
355 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
356 yield
193
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
357
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
358 def regexp(pattern, group):
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
359 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
360 if not group:
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
361 ids = []
209
c03a8113685d Rewrote files.regexp as files.File.regexp (a class method)
Oleg Oshmyan <chortos@inbox.lv>
parents: 205
diff changeset
362 for f in files.File.regexp(pattern):
196
67088c1765b4 Regexps now work with test archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 193
diff changeset
363 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
364 return natsorted(ids)
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
365 else:
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
366 ids = {}
209
c03a8113685d Rewrote files.regexp as files.File.regexp (a class method)
Oleg Oshmyan <chortos@inbox.lv>
parents: 205
diff changeset
367 for f in files.File.regexp(pattern):
196
67088c1765b4 Regexps now work with test archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 193
diff changeset
368 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
369 g = m.group(group)
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
370 ids.setdefault(g, [])
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
371 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
372 for g in ids:
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
373 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
374 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
375
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
376 def natsorted(l):
a76cdc26ba9d Added conf. var. match and match='regexp' for non-archives
Oleg Oshmyan <chortos@inbox.lv>
parents: 189
diff changeset
377 return sorted(l, key=lambda s: [int(t) if t.isdigit() else t for t in re.split('(\d+)', s)])