annotate config.py @ 90:1fb319ec33af

Skimming mode added (-k/--skim option) In skimming mode, as soon as a single test case within a test group is failed, the remaining test cases in the same group are skipped. Bug fix and simply a bit of refactoring: TestCase.has_iofiles and TestCase.has_ansfile are now defined (the meaning should be clear from the names).
author Oleg Oshmyan <chortos@inbox.lv>
date Mon, 28 Feb 2011 15:32:22 +0000
parents cd347cfca272
children c62c9bfd614a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
78
d46bd7ee3e69 Updated copyright notices
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
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
5 try:
25
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
6 from compat import *
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
7 import files
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
8 except ImportError:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
9 import __main__
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
10 __main__.import_error(sys.exc_info()[1])
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
11 else:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
12 from __main__ import options
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
13
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
14 if files.ZipArchive:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
15 try:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
16 import zipimport
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
17 except ImportError:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
18 zipimport = None
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
19 else:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
20 zipimport = None
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
21
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
22 import imp, os, sys, tempfile
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
23
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
24 __all__ = 'load_problem', 'load_global', 'globalconf'
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
25
74
aea4fc87698a Minimal code clean-up
Oleg Oshmyan <chortos@inbox.lv>
parents: 73
diff changeset
26 defaults_problem = {'kind': 'batch',
aea4fc87698a Minimal code clean-up
Oleg Oshmyan <chortos@inbox.lv>
parents: 73
diff changeset
27 'usegroups': False,
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents: 79
diff changeset
28 'maxcputime': None,
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents: 79
diff changeset
29 'maxwalltime': None,
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
30 'maxmemory': None,
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
31 'dummies': {},
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
32 'testsexcluded': (),
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
33 'padtests': 0,
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
34 'paddummies': 0,
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
35 'taskweight': 100,
76
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
36 'groupweight': {},
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
37 'pointmap': {},
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
38 'stdio': False,
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
39 'dummyinname': '',
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
40 'dummyoutname': '',
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
41 'tester': None,
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
42 'maxexitcode': 0,
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
43 'inname': '',
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
44 'ansname': ''}
79
ee8a99dcaaed Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents: 78
diff changeset
45 defaults_global = {'problems': None,
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
46 'force_zero_exitcode': True}
43
81f58c938ec5 Fixed the -s option
Oleg Oshmyan <chortos@inbox.lv>
parents: 38
diff changeset
47 defaults_noerase = {'inname': '%.in',
81f58c938ec5 Fixed the -s option
Oleg Oshmyan <chortos@inbox.lv>
parents: 38
diff changeset
48 'outname': '%.out',
81f58c938ec5 Fixed the -s option
Oleg Oshmyan <chortos@inbox.lv>
parents: 38
diff changeset
49 'ansname': '%.ans'}
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
50 patterns = ('inname', 'outname', 'ansname', 'testcaseinname',
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
51 'testcaseoutname', 'dummyinname', 'dummyoutname')
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
52
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
53 class Config(object):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
54 __slots__ = 'modules', '__dict__'
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
55
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
56 def __init__(self, *modules):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
57 self.modules = modules
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
58
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
59 def __getattr__(self, name):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
60 for module in self.modules:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
61 try:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
62 return getattr(module, name)
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
63 except AttributeError:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
64 pass
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
65 # TODO: provide a message
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
66 raise AttributeError(name)
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
67
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
68 # A helper context manager
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
69 class ReadDeleting(object):
25
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
70 __slots__ = 'name', 'file'
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
71
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
72 def __init__(self, name):
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
73 self.name = name
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
74
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
75 def __enter__(self):
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
76 try:
25
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
77 self.file = open(self.name, 'rU')
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
78 return self.file
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
79 except:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
80 try:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
81 self.__exit__(None, None, None)
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
82 except:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
83 pass
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
84 raise
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
85
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
86 def __exit__(self, exc_type, exc_val, exc_tb):
25
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
87 self.file.close()
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
88 os.remove(self.name)
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
89
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
90 def load_problem(problem_name):
70
b9d5857f7b9a Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents: 60
diff changeset
91 global builtins
83
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
92 try:
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
93 dwb = sys.dont_write_bytecode
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
94 sys.dont_write_bytecode = True
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
95 except AttributeError:
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
96 pass
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
97 metafile = files.File('/'.join((problem_name, 'testconf.py')), True, 'configuration')
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
98 module = None
70
b9d5857f7b9a Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents: 60
diff changeset
99 with CompatBuiltins() as builtins:
25
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
100 if zipimport and isinstance(metafile.archive, files.ZipArchive):
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
101 try:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
102 module = zipimport.zipimporter(os.path.dirname(metafile.full_real_path)).load_module('testconf')
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
103 except zipimport.ZipImportError:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
104 pass
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
105 else:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
106 del sys.modules['testconf']
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
107 if not module:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
108 try:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
109 with metafile.open() as f:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
110 module = imp.load_module('testconf', f, metafile.full_real_path, ('.py', 'r', imp.PY_SOURCE))
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
111 # Handle the case when f is not a true file object but imp requires one
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
112 except ValueError:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
113 # FIXME: 2.5 lacks the delete parameter
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
114 with tempfile.NamedTemporaryFile(delete=False) as f:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
115 inputdatafname = f.name
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
116 metafile.copy(inputdatafname)
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
117 with ReadDeleting(inputdatafname) as f:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
118 module = imp.load_module('testconf', f, metafile.full_real_path, ('.py', 'r', imp.PY_SOURCE))
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
119 del sys.modules['testconf']
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
120 if hasattr(module, 'padwithzeroestolength'):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
121 if not hasattr(module, 'padtests'):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
122 try:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
123 module.padtests = module.padwithzeroestolength[0]
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
124 except TypeError:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
125 module.padtests = module.padwithzeroestolength
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
126 if not hasattr(module, 'paddummies'):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
127 try:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
128 module.paddummies = module.padwithzeroestolength[1]
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
129 except TypeError:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
130 module.paddummies = module.padwithzeroestolength
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
131 for name in defaults_problem:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
132 if not hasattr(globalconf, name):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
133 setattr(module, name, getattr(module, name, defaults_problem[name]))
38
a6d554679ce8 Fixed a bug with nested configuration namespaces in config.py
Oleg Oshmyan <chortos@inbox.lv>
parents: 27
diff changeset
134 module = Config(module, globalconf)
27
dc4be35d17e0 Bug fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 25
diff changeset
135 if not module.dummyinname:
dc4be35d17e0 Bug fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 25
diff changeset
136 module.dummyinname = getattr(module, 'testcaseinname', module.dummyinname)
dc4be35d17e0 Bug fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 25
diff changeset
137 if not module.dummyoutname:
dc4be35d17e0 Bug fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 25
diff changeset
138 module.dummyoutname = getattr(module, 'testcaseoutname', module.dummyoutname)
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
139 if not hasattr(module, 'path'):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
140 if hasattr(module, 'name'):
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
141 module.path = module.name
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
142 elif sys.platform != 'win32':
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
143 module.path = os.path.join(os.path.curdir, problem_name)
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
144 else:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
145 module.path = problem_name
76
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
146 for name in 'pointmap', 'groupweight':
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
147 oldmap = getattr(module, name)
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
148 if isinstance(oldmap, dict):
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
149 newmap = {}
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
150 for key in oldmap:
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
151 if not options.legacy and isinstance(key, basestring):
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
152 newmap[key] = oldmap[key]
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
153 else:
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
154 try:
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
155 for k in key:
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
156 newmap[k] = oldmap[key]
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
157 except TypeError:
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
158 newmap[key] = oldmap[key]
0e5ae28e0b2b Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents: 74
diff changeset
159 setattr(module, name, newmap)
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
160 if options.no_maxtime:
82
06356af50bf9 Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents: 79
diff changeset
161 module.maxcputime = module.maxwalltime = 0
83
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
162 try:
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
163 sys.dont_write_bytecode = dwb
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
164 except NameError:
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
165 pass
24
c23d81f4a1a3 Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents: 22
diff changeset
166 for name in patterns:
c23d81f4a1a3 Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents: 22
diff changeset
167 if hasattr(module, name):
c23d81f4a1a3 Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents: 22
diff changeset
168 setattr(module, name, getattr(module, name).replace('%', problem_name))
c23d81f4a1a3 Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents: 22
diff changeset
169 return module
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
170
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
171 def load_global():
70
b9d5857f7b9a Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents: 60
diff changeset
172 global builtins
83
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
173 try:
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
174 dwb = sys.dont_write_bytecode
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
175 sys.dont_write_bytecode = True
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
176 except AttributeError:
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
177 pass
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
178 metafile = files.File('testconf.py', True, 'configuration')
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
179 module = None
70
b9d5857f7b9a Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents: 60
diff changeset
180 with CompatBuiltins() as builtins:
25
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
181 if zipimport and isinstance(metafile.archive, files.ZipArchive):
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
182 try:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
183 module = zipimport.zipimporter(os.path.dirname(metafile.full_real_path)).load_module('testconf')
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
184 except zipimport.ZipImportError:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
185 pass
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
186 else:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
187 del sys.modules['testconf']
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
188 if not module:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
189 try:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
190 with metafile.open() as f:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
191 module = imp.load_module('testconf', f, metafile.full_real_path, ('.py', 'r', imp.PY_SOURCE))
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
192 # Handle the case when f is not a true file object but imp requires one
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
193 except ValueError:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
194 # FIXME: 2.5 lacks the delete parameter
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
195 with tempfile.NamedTemporaryFile(delete=False) as f:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
196 inputdatafname = f.name
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
197 metafile.copy(inputdatafname)
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
198 with ReadDeleting(inputdatafname) as f:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 24
diff changeset
199 module = imp.load_module('testconf', f, metafile.full_real_path, ('.py', 'r', imp.PY_SOURCE))
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
200 del sys.modules['testconf']
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
201 for name in defaults_global:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
202 setattr(module, name, getattr(module, name, defaults_global[name]))
43
81f58c938ec5 Fixed the -s option
Oleg Oshmyan <chortos@inbox.lv>
parents: 38
diff changeset
203 if not options.erase:
81f58c938ec5 Fixed the -s option
Oleg Oshmyan <chortos@inbox.lv>
parents: 38
diff changeset
204 for name in defaults_noerase:
81f58c938ec5 Fixed the -s option
Oleg Oshmyan <chortos@inbox.lv>
parents: 38
diff changeset
205 setattr(module, name, getattr(module, name, defaults_noerase[name]))
79
ee8a99dcaaed Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents: 78
diff changeset
206 if hasattr(module, 'tasknames'):
ee8a99dcaaed Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents: 78
diff changeset
207 module.problems = module.tasknames
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
208 global globalconf
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
209 globalconf = module
83
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
210 try:
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
211 sys.dont_write_bytecode = dwb
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
212 except NameError:
37c4ad87583c Several small fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 82
diff changeset
213 pass
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 16
diff changeset
214 return module