Mercurial > ~astiob > upreckon > hgweb
comparison 2.00/test-svn.py @ 25:b500e117080e
Bug fixes and overhead reduction
Added the --problem/-p option. (WARNING: not the same as the -p option of test.py 1.x.) The problem names supplied are not validated.
Added zip_longest to compat.py.
Experimental: problem names are now _always_ printed for multi-problem sets.
Overhead: Escape presses are now checked only once every .15 seconds (at least kbhit() on Windows is very slow).
Overhead: sleep(0) is now called in the time-control-and-Escape-watching loop (at least on Windows, it immediately transfers control to some waiting thread).
Bug fix: compat.py now overwrites built-ins only while including testconfs (--help was broken in Python 2).
Bug fix: ReadDeleting in config.py now closes the file it opens (especially important on Windows, where open files cannot be deleted).
Bug fix: added callable to compat.py (it is absent from Python 3).
Bug fix: the default (built-in) output validator now properly handles unwanted trailing data.
Bug fix: testconfs in custom archives no more raise NameError.
Bug fix: if a validator program cannot be launched, CannotStartValidator is now raised instead of the fatal OSError.
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Thu, 23 Sep 2010 23:05:58 +0000 |
parents | c1f52b5d80d6 |
children | 5bbb68833868 |
comparison
equal
deleted
inserted
replaced
24:c23d81f4a1a3 | 25:b500e117080e |
---|---|
13 # $Rev$ | 13 # $Rev$ |
14 version = '2.00.0 (SVN r$$REV$$)' | 14 version = '2.00.0 (SVN r$$REV$$)' |
15 parser = optparse.OptionParser(version='test.py '+version, epilog='Python 2.5 or newer is required, unless you have a custom build of Python.') | 15 parser = optparse.OptionParser(version='test.py '+version, epilog='Python 2.5 or newer is required, unless you have a custom build of Python.') |
16 parser.add_option('-1', dest='legacy', action='store_true', default=False, help='handle configuration files in a way more compatible with test.py 1.x') | 16 parser.add_option('-1', dest='legacy', action='store_true', default=False, help='handle configuration files in a way more compatible with test.py 1.x') |
17 parser.add_option('-u', '--update', dest='update', action='store_true', default=False, help='check for an updated version of test.py') | 17 parser.add_option('-u', '--update', dest='update', action='store_true', default=False, help='check for an updated version of test.py') |
18 parser.add_option('-p', '--problem', dest='problems', metavar='PROBLEM', action='append', help='test only the PROBLEM (this option can be specified more than once with different problem names, all of which will be tested)') | |
18 parser.add_option('-m', '--copy-io', dest='copyonly', action='store_true', default=False, help='create a copy of the input/output files of the last test case for manual testing and exit') | 19 parser.add_option('-m', '--copy-io', dest='copyonly', action='store_true', default=False, help='create a copy of the input/output files of the last test case for manual testing and exit') |
19 parser.add_option('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed after finishing testing') | 20 parser.add_option('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed after finishing testing') |
20 parser.add_option('-s', '--save-io', dest='erase', action='store_false', default=True, help='do not delete the copies of input/output files after the last test case; create copies of input files and store output in files even if the solution uses standard I/O; delete the stored input/output files if the solution uses standard I/O and the -c/--cleanup option is specified') | 21 parser.add_option('-s', '--save-io', dest='erase', action='store_false', default=True, help='do not delete the copies of input/output files after the last test case; create copies of input files and store output in files even if the solution uses standard I/O; delete the stored input/output files if the solution uses standard I/O and the -c/--cleanup option is specified') |
21 parser.add_option('-t', '--detect-time', dest='autotime', action='store_true', default=False, help='spend a second detecting the most precise time measurement function') | 22 parser.add_option('-t', '--detect-time', dest='autotime', action='store_true', default=False, help='spend a second detecting the most precise time measurement function') |
22 parser.add_option('--no-time-limits', dest='no_maxtime', action='store_true', default=False, help='disable all time limits') | 23 parser.add_option('--no-time-limits', dest='no_maxtime', action='store_true', default=False, help='disable all time limits') |
87 try: | 88 try: |
88 globalconf = config.load_global() | 89 globalconf = config.load_global() |
89 | 90 |
90 # Do this check here so that if we have to warn them, we do it as early as possible | 91 # Do this check here so that if we have to warn them, we do it as early as possible |
91 if options.pause and not pause and not hasattr(globalconf, 'pause'): | 92 if options.pause and not pause and not hasattr(globalconf, 'pause'): |
92 # testcases.pause will be sure to import msvcrt if it can | 93 if os.name == 'posix': |
93 #try: | 94 globalconf.pause = 'read -s -n 1' |
94 # # If we have getch, we don't need globalconf.pause | 95 say('Warning: configuration variable pause is not defined; it was devised automatically but the choice might be incorrect, so test.py might exit immediately after the testing is completed.', file=sys.stderr) |
95 # import msvcrt | 96 sys.stderr.flush() |
96 # msvcrt.getch.__call__ | 97 elif os.name == 'nt': |
97 #except Exception: | 98 globalconf.pause = 'pause' |
98 if os.name == 'posix': | 99 else: |
99 globalconf.pause = 'read -s -n 1' | 100 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.') |
100 say('Warning: configuration variable pause is not defined; it was devised automatically but the choice might be incorrect, so test.py might exit immediately after the testing is completed.', file=sys.stderr) | |
101 sys.stderr.flush() | |
102 elif os.name == 'nt': | |
103 globalconf.pause = 'pause' | |
104 else: | |
105 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.') | |
106 | 101 |
107 try: | 102 try: |
108 from problem import * | 103 from problem import * |
109 except ImportError: | 104 except ImportError: |
110 import_error(sys.exc_info()[1]) | 105 import_error(sys.exc_info()[1]) |
114 shouldprintnames = False | 109 shouldprintnames = False |
115 globalconf.multiproblem = False | 110 globalconf.multiproblem = False |
116 globalconf.tasknames = os.path.curdir, | 111 globalconf.tasknames = os.path.curdir, |
117 else: | 112 else: |
118 globalconf.multiproblem = True | 113 globalconf.multiproblem = True |
119 try: | 114 # TODO: erase the commented part? if it has a tasknames variable, it is by definition multi-problem |
120 shouldprintnames = len(globalconf.tasknames) > 1 | 115 shouldprintnames = True |
121 except Exception: | 116 # try: |
122 # Try to retrieve the first two problem names and cache them on success | 117 # shouldprintnames = len(globalconf.tasknames) > 1 |
123 globalconf.tasknames = iter(globalconf.tasknames) | 118 # except Exception: |
124 try: | 119 # # Try to retrieve the first two problem names and cache them on success |
125 try: | 120 # globalconf.tasknames = iter(globalconf.tasknames) |
126 first = next(globalconf.tasknames) | 121 # try: |
127 except NameError: | 122 # try: |
128 # Python 2.5 lacks the next() built-in | 123 # first = next(globalconf.tasknames) |
129 first = globalconf.tasknames.next() | 124 # except NameError: |
130 except StopIteration: | 125 # # Python 2.5 lacks the next() built-in |
131 globalconf.tasknames = () | 126 # first = globalconf.tasknames.next() |
132 shouldprintnames = False | 127 # except StopIteration: |
133 else: | 128 # globalconf.tasknames = () |
134 try: | 129 # shouldprintnames = False |
135 try: | 130 # else: |
136 second = next(globalconf.tasknames) | 131 # try: |
137 except NameError: | 132 # try: |
138 second = globalconf.tasknames.next() | 133 # second = next(globalconf.tasknames) |
139 except StopIteration: | 134 # except NameError: |
140 globalconf.tasknames = first, | 135 # second = globalconf.tasknames.next() |
141 shouldprintnames = False | 136 # except StopIteration: |
142 else: | 137 # globalconf.tasknames = first, |
143 globalconf.tasknames = itertools.chain((first, second), globalconf.tasknames) | 138 # shouldprintnames = False |
144 shouldprintnames = True | 139 # else: |
140 # globalconf.tasknames = itertools.chain((first, second), globalconf.tasknames) | |
141 # shouldprintnames = True | |
145 | 142 |
146 ntasks = 0 | 143 ntasks = 0 |
147 nfulltasks = 0 | 144 nfulltasks = 0 |
148 maxscore = 0 | 145 maxscore = 0 |
149 realscore = 0 | 146 realscore = 0 |
150 | 147 |
151 for taskname in globalconf.tasknames: | 148 for taskname in (globalconf.tasknames if not options.problems else options.problems): |
152 problem = Problem(taskname) | 149 problem = Problem(taskname) |
153 | 150 |
154 if ntasks and not options.copyonly: say() | 151 if ntasks and not options.copyonly: say() |
155 if shouldprintnames: say(taskname) | 152 if shouldprintnames: say(taskname) |
156 | 153 |
175 | 172 |
176 if options.pause: | 173 if options.pause: |
177 say('Press any key to exit...') | 174 say('Press any key to exit...') |
178 sys.stdout.flush() | 175 sys.stdout.flush() |
179 | 176 |
180 #try: | |
181 # import msvcrt | |
182 # msvcrt.getch() | |
183 #except Exception: | |
184 if pause: | 177 if pause: |
185 pause() | 178 pause() |
186 elif callable(globalconf.pause): | 179 elif callable(globalconf.pause): |
187 globalconf.pause() | 180 globalconf.pause() |
188 else: | 181 else: |