Mercurial > ~astiob > upreckon > hgweb
annotate upreckon-vcs @ 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 | 179bad0d29f4 |
children | c62c9bfd614a |
rev | line source |
---|---|
21 | 1 #! /usr/bin/env python |
78 | 2 # Copyright (c) 2009-2011 Chortos-2 <chortos@inbox.lv> |
16 | 3 |
4 from __future__ import division, with_statement | |
5 import optparse, sys, compat | |
21 | 6 |
7 def import_error(e): | |
45 | 8 say('Error: your installation of Upreckon is incomplete;', str(e).lower() + '.', file=sys.stderr) |
21 | 9 sys.exit(3) |
10 | |
11 from compat import * | |
16 | 12 |
33
f90bd2d1a12b
Converted revision reporting from SVN to hg.
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
13 version = '2.00.0 ($$REV$$)' |
45 | 14 parser = optparse.OptionParser(version='Upreckon '+version, epilog='Python 2.5 or newer is required.') |
23 | 15 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') |
45 | 16 parser.add_option('-u', '--update', dest='update', action='store_true', default=False, help='update the installed Upreckon to the latest publicly available version') |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
17 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)') |
16 | 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('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed after finishing testing') | |
21 | 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('-t', '--detect-time', dest='autotime', action='store_true', default=False, help='spend a second detecting the most precise time measurement function') | |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
87
diff
changeset
|
22 parser.add_option('-k', '--skim', action='store_true', default=False, help='skip test groups as soon as one test case is failed') |
21 | 23 parser.add_option('--no-time-limits', dest='no_maxtime', action='store_true', default=False, help='disable all time limits') |
16 | 24 |
25 options, args = parser.parse_args() | |
26 parser.destroy() | |
27 del parser | |
28 | |
29 if options.update: | |
30 try: | |
31 urllib, urlread = compat.import_urllib() | |
32 except ImportError: | |
33 sys.exit('Error: the urllib Python module is missing. Without it, an automatic update is impossible.') | |
34 | |
35 latesttext = urlread('http://chortos.selfip.net/~astiob/test.py/version.txt') | |
36 latest = latesttext.split('.') | |
37 installed = version.split('.') | |
38 update = None | |
39 | |
40 if latest[0] > installed[0]: | |
41 update = 'major' | |
42 elif latest[0] == installed[0]: | |
43 if latest[1] > installed[1]: | |
44 update = 'feature' | |
45 elif latest[1] == installed[1]: | |
46 if latest[2] > installed[2]: | |
47 update = 'bug-fixing' | |
48 elif latest[2] == installed[2]: | |
87
179bad0d29f4
--update now includes version numbers in all messages it prints
Oleg Oshmyan <chortos@inbox.lv>
parents:
85
diff
changeset
|
49 say('You are using the latest publicly available version of Upreckon (%s).' % latesttext) |
16 | 50 sys.exit() |
51 | |
52 if not update: | |
87
179bad0d29f4
--update now includes version numbers in all messages it prints
Oleg Oshmyan <chortos@inbox.lv>
parents:
85
diff
changeset
|
53 say('Your copy of Upreckon is newer (%s) than the publicly available version (%s).' % (version, latesttext)) |
16 | 54 sys.exit() |
55 | |
87
179bad0d29f4
--update now includes version numbers in all messages it prints
Oleg Oshmyan <chortos@inbox.lv>
parents:
85
diff
changeset
|
56 say('A %s update to Upreckon is available (%s). Downloading...' % (update, latesttext)) |
16 | 57 sys.stdout.flush() |
45 | 58 # FIXME: need to update all files! |
16 | 59 urllib.urlretrieve('http://chortos.selfip.net/~astiob/test.py/test.py', sys.argv[0]) |
87
179bad0d29f4
--update now includes version numbers in all messages it prints
Oleg Oshmyan <chortos@inbox.lv>
parents:
85
diff
changeset
|
60 say('Downloaded and installed. Now you are using Upreckon %s.' % latesttext) |
16 | 61 sys.exit() |
62 | |
22 | 63 import config, itertools, os, subprocess, sys, time |
16 | 64 |
70
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
65 if options.legacy: |
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
66 compat.pseudobuiltins += 'xrange', |
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
67 |
16 | 68 try: |
66
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
69 import testcases |
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
70 except ImportError: |
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
71 import_error(sys.exc_info()[1]) |
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
72 |
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
73 try: |
22 | 74 from testcases import pause |
75 except ImportError: | |
76 pause = None | |
77 | |
78 try: | |
21 | 79 globalconf = config.load_global() |
16 | 80 |
21 | 81 # Do this check here so that if we have to warn them, we do it as early as possible |
22 | 82 if options.pause and not pause and not hasattr(globalconf, 'pause'): |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
83 if os.name == 'posix': |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
84 globalconf.pause = 'read -s -n 1' |
45 | 85 say('Warning: configuration variable pause is not defined; it was devised automatically but the choice might be incorrect, so Upreckon might exit immediately after the testing is completed.', file=sys.stderr) |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
86 sys.stderr.flush() |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
87 elif os.name == 'nt': |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
88 globalconf.pause = 'pause' |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
89 else: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
90 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.') |
16 | 91 |
21 | 92 try: |
93 from problem import * | |
94 except ImportError: | |
95 import_error(sys.exc_info()[1]) | |
16 | 96 |
21 | 97 # Support single-problem configurations |
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
98 if globalconf.problems is None: |
21 | 99 shouldprintnames = False |
100 globalconf.multiproblem = False | |
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
101 globalconf.problems = os.path.curdir, |
16 | 102 else: |
21 | 103 globalconf.multiproblem = True |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
104 shouldprintnames = True |
16 | 105 |
21 | 106 ntasks = 0 |
107 nfulltasks = 0 | |
108 maxscore = 0 | |
109 realscore = 0 | |
16 | 110 |
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
111 for taskname in (globalconf.problems if not options.problems else options.problems): |
21 | 112 problem = Problem(taskname) |
113 | |
22 | 114 if ntasks and not options.copyonly: say() |
21 | 115 if shouldprintnames: say(taskname) |
116 | |
117 if options.copyonly: | |
118 problem.copytestdata() | |
119 else: | |
120 real, max = problem.test() | |
121 | |
122 ntasks += 1 | |
22 | 123 nfulltasks += real == max |
21 | 124 realscore += real |
125 maxscore += max | |
126 | |
127 if options.copyonly: | |
128 sys.exit() | |
129 | |
130 if ntasks != 1: | |
131 say() | |
64 | 132 say('Grand total: %g/%g weighted points; %d/%d problems solved fully' % (realscore, maxscore, nfulltasks, ntasks)) |
21 | 133 except KeyboardInterrupt: |
134 sys.exit('Exiting due to a keyboard interrupt.') | |
16 | 135 |
136 if options.pause: | |
21 | 137 say('Press any key to exit...') |
16 | 138 sys.stdout.flush() |
139 | |
22 | 140 if pause: |
141 pause() | |
142 elif callable(globalconf.pause): | |
143 globalconf.pause() | |
144 else: | |
145 with open(os.devnull, 'w') as devnull: | |
83 | 146 subprocess.call(globalconf.pause, shell=True, stdout=devnull, stderr=subprocess.STDOUT) |