Mercurial > ~astiob > upreckon > hgweb
annotate upreckon/upreckon-vcs @ 162:b71995909857 2.01
Bumped the version number to 2.01.1 and slightly cleaned up upreckon-vcs
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Fri, 10 Jun 2011 21:31:56 +0100 |
parents | d5b6708c1955 |
children | e56d43b40884 |
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 | |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
141
diff
changeset
|
5 import optparse |
21 | 6 |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
141
diff
changeset
|
7 from upreckon import compat |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
141
diff
changeset
|
8 from upreckon.compat import * |
16 | 9 |
162
b71995909857
Bumped the version number to 2.01.1 and slightly cleaned up upreckon-vcs
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
10 version = '2.01.1 ($$REV$$)' |
b71995909857
Bumped the version number to 2.01.1 and slightly cleaned up upreckon-vcs
Oleg Oshmyan <chortos@inbox.lv>
parents:
146
diff
changeset
|
11 parser = optparse.OptionParser(version='Upreckon '+version, epilog='Python 2.6 or newer is required.') |
23 | 12 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') |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
13 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)') |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
14 parser.add_option('--list-problems', action='store_true', default=False, help='just list all problem names') |
16 | 15 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') |
16 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') | |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
141
diff
changeset
|
17 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') |
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
87
diff
changeset
|
18 parser.add_option('-k', '--skim', action='store_true', default=False, help='skip test groups as soon as one test case is failed') |
21 | 19 parser.add_option('--no-time-limits', dest='no_maxtime', action='store_true', default=False, help='disable all time limits') |
16 | 20 |
21 options, args = parser.parse_args() | |
22 parser.destroy() | |
23 del parser | |
24 | |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
141
diff
changeset
|
25 from upreckon import config |
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
141
diff
changeset
|
26 import itertools, os, subprocess, sys, time |
16 | 27 |
70
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
28 if options.legacy: |
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
29 compat.pseudobuiltins += 'xrange', |
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
30 |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
31 if options.list_problems: |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
32 options.pause = False |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
33 |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
141
diff
changeset
|
34 from upreckon import testcases |
66
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
35 |
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
36 try: |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
141
diff
changeset
|
37 from upreckon.testcases import pause |
22 | 38 except ImportError: |
39 pause = None | |
40 | |
41 try: | |
21 | 42 globalconf = config.load_global() |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
43 |
21 | 44 # Do this check here so that if we have to warn them, we do it as early as possible |
22 | 45 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
|
46 if os.name == 'posix': |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
47 globalconf.pause = 'read -s -n 1' |
45 | 48 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
|
49 sys.stderr.flush() |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
50 elif os.name == 'nt': |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
51 globalconf.pause = 'pause' |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
52 else: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
53 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.') |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
54 |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
141
diff
changeset
|
55 from upreckon.problem import * |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
56 |
21 | 57 # Support single-problem configurations |
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
58 if globalconf.problems is None: |
21 | 59 shouldprintnames = False |
60 globalconf.multiproblem = False | |
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
61 globalconf.problems = os.path.curdir, |
16 | 62 else: |
21 | 63 globalconf.multiproblem = True |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
64 shouldprintnames = True |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
65 |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
66 if options.list_problems: |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
67 for taskname in globalconf.problems: |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
68 say(taskname) |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
69 sys.exit() |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
70 |
21 | 71 ntasks = 0 |
72 nfulltasks = 0 | |
73 maxscore = 0 | |
74 realscore = 0 | |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
75 |
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
76 for taskname in (globalconf.problems if not options.problems else options.problems): |
21 | 77 problem = Problem(taskname) |
78 | |
22 | 79 if ntasks and not options.copyonly: say() |
21 | 80 if shouldprintnames: say(taskname) |
81 | |
82 if options.copyonly: | |
83 problem.copytestdata() | |
84 else: | |
85 real, max = problem.test() | |
86 | |
87 ntasks += 1 | |
22 | 88 nfulltasks += real == max |
21 | 89 realscore += real |
90 maxscore += max | |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
91 |
21 | 92 if options.copyonly: |
93 sys.exit() | |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
94 |
21 | 95 if ntasks != 1: |
96 say() | |
64 | 97 say('Grand total: %g/%g weighted points; %d/%d problems solved fully' % (realscore, maxscore, nfulltasks, ntasks)) |
21 | 98 except KeyboardInterrupt: |
138
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
99 say('Exiting due to a keyboard interrupt.', end='', file=sys.stderr) |
141 | 100 sys.stderr.flush() |
138
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
101 try: |
146
d5b6708c1955
Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents:
141
diff
changeset
|
102 import signal |
138
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
103 signal.signal(signal.SIGINT, signal.SIG_DFL) |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
104 os.kill(os.getpid(), signal.SIGINT) |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
105 except Exception: |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
106 pass |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
107 # Do this even if we got no exceptions, just in case |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
108 say(file=sys.stderr) |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
109 sys.exit(1) |
16 | 110 |
111 if options.pause: | |
21 | 112 say('Press any key to exit...') |
16 | 113 sys.stdout.flush() |
114 | |
22 | 115 if pause: |
116 pause() | |
117 elif callable(globalconf.pause): | |
118 globalconf.pause() | |
119 else: | |
120 with open(os.devnull, 'w') as devnull: | |
83 | 121 subprocess.call(globalconf.pause, shell=True, stdout=devnull, stderr=subprocess.STDOUT) |