Mercurial > ~astiob > upreckon > hgweb
annotate upreckon/config.py @ 232:f94f9724c543
Switched from str to bytes for external validator output
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Fri, 29 Jun 2012 03:32:49 +0300 |
parents | 715e3525a904 |
children |
rev | line source |
---|---|
228
715e3525a904
Fixed crashing on testconfs inside archives on Python 3
Oleg Oshmyan <chortos@inbox.lv>
parents:
222
diff
changeset
|
1 # Copyright (c) 2010-2012 Chortos-2 <chortos@inbox.lv> |
16 | 2 |
21 | 3 from __future__ import division, with_statement |
4 | |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
107
diff
changeset
|
5 from .compat import * |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
107
diff
changeset
|
6 from . import files |
151
6261eea8a975
Positional cmdline arguments now override testconf.tests and disable groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
150
diff
changeset
|
7 from __main__ import options, args |
21 | 8 |
9 if files.ZipArchive: | |
10 try: | |
11 import zipimport | |
12 except ImportError: | |
13 zipimport = None | |
14 else: | |
15 zipimport = None | |
16 | |
150
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
17 import imp, os, posixpath, sys, tempfile |
21 | 18 |
150
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
19 __all__ = 'load_problem', 'load_global', 'globalconf', 'nativize_path' |
21 | 20 |
74 | 21 defaults_problem = {'kind': 'batch', |
22 'usegroups': False, | |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
79
diff
changeset
|
23 'maxcputime': None, |
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
79
diff
changeset
|
24 'maxwalltime': None, |
21 | 25 'maxmemory': None, |
199
1de2ea435d93
The default match mode is now 'literal'
Oleg Oshmyan <chortos@inbox.lv>
parents:
193
diff
changeset
|
26 'match': 'literal', |
96
c3afa2b0c14c
Fixed a typo (did not affect anything)
Oleg Oshmyan <chortos@inbox.lv>
parents:
92
diff
changeset
|
27 'dummies': (), |
21 | 28 'testsexcluded': (), |
29 'padtests': 0, | |
30 'paddummies': 0, | |
31 'taskweight': 100, | |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
32 'groupweight': {}, |
21 | 33 'pointmap': {}, |
34 'stdio': False, | |
174
e0b2fbd7ebe0
Improved built-in output validator; added conf. var. binary
Oleg Oshmyan <chortos@inbox.lv>
parents:
164
diff
changeset
|
35 'binary': False, |
21 | 36 'dummyinname': '', |
37 'dummyoutname': '', | |
38 'tester': None, | |
39 'maxexitcode': 0, | |
205
166a23999bf7
Added confvar okexitcodemask; changed the validator protocol
Oleg Oshmyan <chortos@inbox.lv>
parents:
203
diff
changeset
|
40 'okexitcodeflag': 0, |
21 | 41 'inname': '', |
200
fa81289ee407
force_zero_exitcode is now a problem-specific configuration variable
Oleg Oshmyan <chortos@inbox.lv>
parents:
199
diff
changeset
|
42 'ansname': '', |
fa81289ee407
force_zero_exitcode is now a problem-specific configuration variable
Oleg Oshmyan <chortos@inbox.lv>
parents:
199
diff
changeset
|
43 'force_zero_exitcode': True} |
fa81289ee407
force_zero_exitcode is now a problem-specific configuration variable
Oleg Oshmyan <chortos@inbox.lv>
parents:
199
diff
changeset
|
44 defaults_global = {'problems': None} |
43 | 45 defaults_noerase = {'inname': '%.in', |
46 'outname': '%.out', | |
47 'ansname': '%.ans'} | |
21 | 48 patterns = ('inname', 'outname', 'ansname', 'testcaseinname', |
49 'testcaseoutname', 'dummyinname', 'dummyoutname') | |
50 | |
51 class Config(object): | |
52 __slots__ = 'modules', '__dict__' | |
53 | |
54 def __init__(self, *modules): | |
55 self.modules = modules | |
56 | |
57 def __getattr__(self, name): | |
58 for module in self.modules: | |
59 try: | |
60 return getattr(module, name) | |
61 except AttributeError: | |
62 pass | |
63 # TODO: provide a message | |
64 raise AttributeError(name) | |
16 | 65 |
22 | 66 # A helper context manager |
67 class ReadDeleting(object): | |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
68 __slots__ = 'name', 'file' |
22 | 69 |
70 def __init__(self, name): | |
71 self.name = name | |
72 | |
73 def __enter__(self): | |
74 try: | |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
75 self.file = open(self.name, 'rU') |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
76 return self.file |
22 | 77 except: |
78 try: | |
79 self.__exit__(None, None, None) | |
80 except: | |
81 pass | |
82 raise | |
83 | |
84 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
|
85 self.file.close() |
22 | 86 os.remove(self.name) |
87 | |
150
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
88 def nativize_path(portable_path): |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
89 if portable_path.startswith('//:'): |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
90 return portable_path[3:] |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
91 comps = portable_path.split('/') |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
92 for i, comp in enumerate(comps): |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
93 if comp == '..': |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
94 comps[i] = os.path.pardir |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
95 elif comp == '.': |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
96 comps[i] = os.path.curdir |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
97 native_path = os.path.join(*comps) |
156
2db236d25ecd
Improved the nativization of absolute paths by config.nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
152
diff
changeset
|
98 if posixpath.isabs(portable_path) and not os.path.isabs(native_path): |
2db236d25ecd
Improved the nativization of absolute paths by config.nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
152
diff
changeset
|
99 abspath = os.path.abspath(native_path) |
2db236d25ecd
Improved the nativization of absolute paths by config.nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
152
diff
changeset
|
100 parent = os.path.dirname(abspath) |
2db236d25ecd
Improved the nativization of absolute paths by config.nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
152
diff
changeset
|
101 while parent != abspath: |
2db236d25ecd
Improved the nativization of absolute paths by config.nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
152
diff
changeset
|
102 abspath, parent = parent, os.path.dirname(parent) |
2db236d25ecd
Improved the nativization of absolute paths by config.nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
152
diff
changeset
|
103 native_path = os.path.join(parent, native_path) |
2db236d25ecd
Improved the nativization of absolute paths by config.nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
152
diff
changeset
|
104 elif not posixpath.isabs(portable_path) and os.path.isabs(native_path): |
150
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
105 native_path = os.path.sep + native_path |
156
2db236d25ecd
Improved the nativization of absolute paths by config.nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
152
diff
changeset
|
106 if posixpath.isabs(portable_path) != os.path.isabs(native_path): |
2db236d25ecd
Improved the nativization of absolute paths by config.nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
152
diff
changeset
|
107 raise ValueError('cannot make native path relative/absolute') |
150
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
108 return native_path |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
109 |
21 | 110 def load_problem(problem_name): |
70
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
60
diff
changeset
|
111 global builtins |
83 | 112 try: |
113 dwb = sys.dont_write_bytecode | |
114 sys.dont_write_bytecode = True | |
115 except AttributeError: | |
116 pass | |
208 | 117 metafile = files.File.from_virtual_path(problem_name + '/testconf.py', True, 'configuration') |
21 | 118 module = None |
70
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
60
diff
changeset
|
119 with CompatBuiltins() as builtins: |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
120 if zipimport and isinstance(metafile.archive, files.ZipArchive): |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
121 try: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
122 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
|
123 except zipimport.ZipImportError: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
124 pass |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
125 else: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
126 del sys.modules['testconf'] |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
127 if not module: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
128 try: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
129 with metafile.open() as f: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
130 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
|
131 # Handle the case when f is not a true file object but imp requires one |
228
715e3525a904
Fixed crashing on testconfs inside archives on Python 3
Oleg Oshmyan <chortos@inbox.lv>
parents:
222
diff
changeset
|
132 # TypeError on Python 3, ValueError on Python 2 |
715e3525a904
Fixed crashing on testconfs inside archives on Python 3
Oleg Oshmyan <chortos@inbox.lv>
parents:
222
diff
changeset
|
133 except (TypeError, ValueError): |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
134 # FIXME: 2.5 lacks the delete parameter |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
135 with tempfile.NamedTemporaryFile(delete=False) as f: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
136 inputdatafname = f.name |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
137 metafile.copy(inputdatafname) |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
138 with ReadDeleting(inputdatafname) as f: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
139 module = imp.load_module('testconf', f, metafile.full_real_path, ('.py', 'r', imp.PY_SOURCE)) |
21 | 140 del sys.modules['testconf'] |
107
6589511f5418
Fixed mishandling of some variables in multi-problem legacy configurations
Oleg Oshmyan <chortos@inbox.lv>
parents:
96
diff
changeset
|
141 module = Config(module, globalconf) |
21 | 142 if hasattr(module, 'padwithzeroestolength'): |
143 if not hasattr(module, 'padtests'): | |
144 try: | |
145 module.padtests = module.padwithzeroestolength[0] | |
146 except TypeError: | |
147 module.padtests = module.padwithzeroestolength | |
148 if not hasattr(module, 'paddummies'): | |
149 try: | |
150 module.paddummies = module.padwithzeroestolength[1] | |
151 except TypeError: | |
152 module.paddummies = module.padwithzeroestolength | |
92
17041a71bc02
maxtime is now auto-converted to maxcputime
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
153 if (not hasattr(module, 'maxcputime') and |
17041a71bc02
maxtime is now auto-converted to maxcputime
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
154 not hasattr(module, 'maxwalltime') and |
17041a71bc02
maxtime is now auto-converted to maxcputime
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
155 hasattr(module, 'maxtime')): |
17041a71bc02
maxtime is now auto-converted to maxcputime
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
156 module.maxcputime = module.maxtime |
21 | 157 for name in defaults_problem: |
107
6589511f5418
Fixed mishandling of some variables in multi-problem legacy configurations
Oleg Oshmyan <chortos@inbox.lv>
parents:
96
diff
changeset
|
158 setattr(module, name, getattr(module, name, defaults_problem[name])) |
27 | 159 if not module.dummyinname: |
160 module.dummyinname = getattr(module, 'testcaseinname', module.dummyinname) | |
161 if not module.dummyoutname: | |
162 module.dummyoutname = getattr(module, 'testcaseoutname', module.dummyoutname) | |
150
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
163 if hasattr(module, 'testee'): |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
164 if isinstance(module.testee, basestring): |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
165 module.path = nativize_path(module.testee) |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
166 else: |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
167 testee = tuple(module.testee) |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
168 module.path = (nativize_path(testee[0]),) + testee[1:] |
006dce02752c
Added the testee configuration variable and the config.nativize_path function
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
169 elif not hasattr(module, 'path'): |
21 | 170 if hasattr(module, 'name'): |
171 module.path = module.name | |
172 elif sys.platform != 'win32': | |
173 module.path = os.path.join(os.path.curdir, problem_name) | |
174 else: | |
175 module.path = problem_name | |
164
b375daa74371
The first/only item of testconf.tester is now passed through nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
156
diff
changeset
|
176 if module.tester: |
b375daa74371
The first/only item of testconf.tester is now passed through nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
156
diff
changeset
|
177 if isinstance(module.tester, basestring): |
b375daa74371
The first/only item of testconf.tester is now passed through nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
156
diff
changeset
|
178 module.tester = nativize_path(module.tester) |
175
35d59ba0e27c
Fixed crashing on callable values of the tester conf. var.
Oleg Oshmyan <chortos@inbox.lv>
parents:
174
diff
changeset
|
179 elif not callable(module.tester): |
164
b375daa74371
The first/only item of testconf.tester is now passed through nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
156
diff
changeset
|
180 tester = tuple(module.tester) |
b375daa74371
The first/only item of testconf.tester is now passed through nativize_path
Oleg Oshmyan <chortos@inbox.lv>
parents:
156
diff
changeset
|
181 module.tester = (nativize_path(tester[0]),) + tester[1:] |
203
dd1f715398f0
Fixed mapping (dict) values of taskweight
Oleg Oshmyan <chortos@inbox.lv>
parents:
201
diff
changeset
|
182 if not isinstance(module.taskweight, dict): |
dd1f715398f0
Fixed mapping (dict) values of taskweight
Oleg Oshmyan <chortos@inbox.lv>
parents:
201
diff
changeset
|
183 try: |
dd1f715398f0
Fixed mapping (dict) values of taskweight
Oleg Oshmyan <chortos@inbox.lv>
parents:
201
diff
changeset
|
184 module.taskweight = dict(zip(module.problems, module.taskweight)) |
dd1f715398f0
Fixed mapping (dict) values of taskweight
Oleg Oshmyan <chortos@inbox.lv>
parents:
201
diff
changeset
|
185 except TypeError: |
dd1f715398f0
Fixed mapping (dict) values of taskweight
Oleg Oshmyan <chortos@inbox.lv>
parents:
201
diff
changeset
|
186 pass |
201
32650f4a2177
taskweight can now be an iterable or a mapping
Oleg Oshmyan <chortos@inbox.lv>
parents:
200
diff
changeset
|
187 try: |
32650f4a2177
taskweight can now be an iterable or a mapping
Oleg Oshmyan <chortos@inbox.lv>
parents:
200
diff
changeset
|
188 module.taskweight = module.taskweight[problem_name] |
32650f4a2177
taskweight can now be an iterable or a mapping
Oleg Oshmyan <chortos@inbox.lv>
parents:
200
diff
changeset
|
189 except KeyError: |
32650f4a2177
taskweight can now be an iterable or a mapping
Oleg Oshmyan <chortos@inbox.lv>
parents:
200
diff
changeset
|
190 module.taskweight = defaults_problem['taskweight'] |
32650f4a2177
taskweight can now be an iterable or a mapping
Oleg Oshmyan <chortos@inbox.lv>
parents:
200
diff
changeset
|
191 except TypeError: |
32650f4a2177
taskweight can now be an iterable or a mapping
Oleg Oshmyan <chortos@inbox.lv>
parents:
200
diff
changeset
|
192 pass |
76
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
193 for name in 'pointmap', 'groupweight': |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
194 oldmap = getattr(module, name) |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
195 if isinstance(oldmap, dict): |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
196 newmap = {} |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
197 for key in oldmap: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
198 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
|
199 newmap[key] = oldmap[key] |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
200 else: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
201 try: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
202 for k in key: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
203 newmap[k] = oldmap[key] |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
204 except TypeError: |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
205 newmap[key] = oldmap[key] |
0e5ae28e0b2b
Points are now weighted on a test context basis
Oleg Oshmyan <chortos@inbox.lv>
parents:
74
diff
changeset
|
206 setattr(module, name, newmap) |
21 | 207 if options.no_maxtime: |
82
06356af50bf9
Finished testcases reorganization and CPU time limit implementation
Oleg Oshmyan <chortos@inbox.lv>
parents:
79
diff
changeset
|
208 module.maxcputime = module.maxwalltime = 0 |
151
6261eea8a975
Positional cmdline arguments now override testconf.tests and disable groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
150
diff
changeset
|
209 if args: |
6261eea8a975
Positional cmdline arguments now override testconf.tests and disable groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
150
diff
changeset
|
210 module.usegroups = False |
222
d66d5823bb1a
Made positional argument presence force match='literal'
Oleg Oshmyan <chortos@inbox.lv>
parents:
208
diff
changeset
|
211 module.match = 'literal' |
151
6261eea8a975
Positional cmdline arguments now override testconf.tests and disable groups
Oleg Oshmyan <chortos@inbox.lv>
parents:
150
diff
changeset
|
212 module.tests = args |
152
7951219d9866
Dummies are no longer tested when positional cmdline arguments are given
Oleg Oshmyan <chortos@inbox.lv>
parents:
151
diff
changeset
|
213 module.dummies = () |
83 | 214 try: |
215 sys.dont_write_bytecode = dwb | |
216 except NameError: | |
217 pass | |
24
c23d81f4a1a3
Score returned by TestCase.__call__() is now normalized to 0..1
Oleg Oshmyan <chortos@inbox.lv>
parents:
22
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 return module |
21 | 222 |
223 def load_global(): | |
70
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
60
diff
changeset
|
224 global builtins |
83 | 225 try: |
226 dwb = sys.dont_write_bytecode | |
227 sys.dont_write_bytecode = True | |
228 except AttributeError: | |
229 pass | |
208 | 230 metafile = files.File.from_virtual_path('testconf.py', True, 'configuration') |
21 | 231 module = None |
70
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
60
diff
changeset
|
232 with CompatBuiltins() as builtins: |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
233 if zipimport and isinstance(metafile.archive, files.ZipArchive): |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
234 try: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
235 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
|
236 except zipimport.ZipImportError: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
237 pass |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
238 else: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
239 del sys.modules['testconf'] |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
240 if not module: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
241 try: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
242 with metafile.open() as f: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
243 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
|
244 # Handle the case when f is not a true file object but imp requires one |
228
715e3525a904
Fixed crashing on testconfs inside archives on Python 3
Oleg Oshmyan <chortos@inbox.lv>
parents:
222
diff
changeset
|
245 # TypeError on Python 3, ValueError on Python 2 |
715e3525a904
Fixed crashing on testconfs inside archives on Python 3
Oleg Oshmyan <chortos@inbox.lv>
parents:
222
diff
changeset
|
246 except (TypeError, ValueError): |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
247 # FIXME: 2.5 lacks the delete parameter |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
248 with tempfile.NamedTemporaryFile(delete=False) as f: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
249 inputdatafname = f.name |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
250 metafile.copy(inputdatafname) |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
251 with ReadDeleting(inputdatafname) as f: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
24
diff
changeset
|
252 module = imp.load_module('testconf', f, metafile.full_real_path, ('.py', 'r', imp.PY_SOURCE)) |
21 | 253 del sys.modules['testconf'] |
254 for name in defaults_global: | |
255 setattr(module, name, getattr(module, name, defaults_global[name])) | |
43 | 256 if not options.erase: |
257 for name in defaults_noerase: | |
258 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
|
259 if hasattr(module, 'tasknames'): |
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
260 module.problems = module.tasknames |
207
946e8c09ba12
Fixed single-problem configurations (regression in 32650f4a2177)
Oleg Oshmyan <chortos@inbox.lv>
parents:
205
diff
changeset
|
261 if module.problems is not None: |
946e8c09ba12
Fixed single-problem configurations (regression in 32650f4a2177)
Oleg Oshmyan <chortos@inbox.lv>
parents:
205
diff
changeset
|
262 # Iterable and mapping taskweights cause re-iteration over problems |
946e8c09ba12
Fixed single-problem configurations (regression in 32650f4a2177)
Oleg Oshmyan <chortos@inbox.lv>
parents:
205
diff
changeset
|
263 try: |
946e8c09ba12
Fixed single-problem configurations (regression in 32650f4a2177)
Oleg Oshmyan <chortos@inbox.lv>
parents:
205
diff
changeset
|
264 len(module.problems) |
946e8c09ba12
Fixed single-problem configurations (regression in 32650f4a2177)
Oleg Oshmyan <chortos@inbox.lv>
parents:
205
diff
changeset
|
265 except Exception: |
946e8c09ba12
Fixed single-problem configurations (regression in 32650f4a2177)
Oleg Oshmyan <chortos@inbox.lv>
parents:
205
diff
changeset
|
266 module.problems = tuple(module.problems) |
21 | 267 global globalconf |
268 globalconf = module | |
83 | 269 try: |
270 sys.dont_write_bytecode = dwb | |
271 except NameError: | |
272 pass | |
21 | 273 return module |