annotate upreckon/upreckon-vcs @ 230:440eeeb8e1f6 2.03 2.03.2

Bumped the version number to 2.03.2
author Oleg Oshmyan <chortos@inbox.lv>
date Wed, 06 Jun 2012 20:52:58 +0100
parents fbdea5b8cc68
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
1 #! /usr/bin/env python
78
d46bd7ee3e69 Updated copyright notices
Oleg Oshmyan <chortos@inbox.lv>
parents: 70
diff changeset
2 # Copyright (c) 2009-2011 Chortos-2 <chortos@inbox.lv>
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
3
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
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
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
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
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
9
230
440eeeb8e1f6 Bumped the version number to 2.03.2
Oleg Oshmyan <chortos@inbox.lv>
parents: 224
diff changeset
10 parser = optparse.OptionParser(version='Upreckon 2.03.2 ($$REV$$)', epilog='Python 2.6 or newer is required.')
23
c1f52b5d80d6 Compatibility and bug fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 22
diff changeset
11 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
12 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
13 parser.add_option('--list-problems', action='store_true', default=False, help='just list all problem names')
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
14 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
15 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
16 parser.add_option('-k', '--skim', action='store_true', default=False, help='skip test groups as soon as one test case is failed')
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
17 parser.add_option('--no-time-limits', dest='no_maxtime', action='store_true', default=False, help='disable all time limits')
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
18
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
19 options, args = parser.parse_args()
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
20 parser.destroy()
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
21 del parser
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
22
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 141
diff changeset
23 from upreckon import config
212
1cbe2c428942 Cleaned up import statements
Oleg Oshmyan <chortos@inbox.lv>
parents: 211
diff changeset
24 import os, subprocess, sys
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
25
70
b9d5857f7b9a Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents: 66
diff changeset
26 if options.legacy:
b9d5857f7b9a Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents: 66
diff changeset
27 compat.pseudobuiltins += 'xrange',
b9d5857f7b9a Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents: 66
diff changeset
28
102
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
29 if options.list_problems:
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
30 options.pause = False
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
31
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 141
diff changeset
32 from upreckon import testcases
66
34ba0b353fc6 Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents: 64
diff changeset
33
34ba0b353fc6 Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents: 64
diff changeset
34 try:
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 141
diff changeset
35 from upreckon.testcases import pause
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
36 except ImportError:
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
37 pause = None
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
38
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
39 try:
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
40 globalconf = config.load_global()
102
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
41
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
42 # Do this check here so that if we have to warn them, we do it as early as possible
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
43 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
44 if os.name == 'posix':
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 23
diff changeset
45 globalconf.pause = 'read -s -n 1'
45
5afefe51dcdc Initial rename to Upreckon
Oleg Oshmyan <chortos@inbox.lv>
parents: 40
diff changeset
46 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
47 sys.stderr.flush()
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 23
diff changeset
48 elif os.name == 'nt':
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 23
diff changeset
49 globalconf.pause = 'pause'
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 23
diff changeset
50 else:
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 23
diff changeset
51 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
52
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 141
diff changeset
53 from upreckon.problem import *
102
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
54
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
55 # Support single-problem configurations
79
ee8a99dcaaed Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents: 78
diff changeset
56 if globalconf.problems is None:
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
57 shouldprintnames = False
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
58 globalconf.multiproblem = False
79
ee8a99dcaaed Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents: 78
diff changeset
59 globalconf.problems = os.path.curdir,
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
60 else:
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
61 globalconf.multiproblem = True
25
b500e117080e Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents: 23
diff changeset
62 shouldprintnames = True
102
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
63
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
64 if options.list_problems:
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
65 for taskname in globalconf.problems:
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
66 say(taskname)
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
67 sys.exit()
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
68
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
69 ntasks = 0
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
70 nfulltasks = 0
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
71 maxscore = 0
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
72 realscore = 0
102
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
73
202
d46bb4495766 A cosmetic correction
Oleg Oshmyan <chortos@inbox.lv>
parents: 184
diff changeset
74 for taskname in options.problems or globalconf.problems:
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
75 problem = Problem(taskname)
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
76
213
ad4362bf9858 Created a branch for the 2.03 release
Oleg Oshmyan <chortos@inbox.lv>
parents: 212
diff changeset
77 if ntasks: say()
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
78 if shouldprintnames: say(taskname)
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
79
213
ad4362bf9858 Created a branch for the 2.03 release
Oleg Oshmyan <chortos@inbox.lv>
parents: 212
diff changeset
80 real, max = problem.test()
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
81
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
82 ntasks += 1
22
f07b7a431ea6 Further 2.00 work
Oleg Oshmyan <chortos@inbox.lv>
parents: 21
diff changeset
83 nfulltasks += real == max
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
84 realscore += real
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
85 maxscore += max
102
796eb7667fb0 Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents: 91
diff changeset
86
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
87 if ntasks != 1:
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
88 say()
64
94946bc0a3a8 Grand grand -> grand
Oleg Oshmyan <chortos@inbox.lv>
parents: 50
diff changeset
89 say('Grand total: %g/%g weighted points; %d/%d problems solved fully' % (realscore, maxscore, nfulltasks, ntasks))
21
ec6f1a132109 A pretty usable version
Oleg Oshmyan <chortos@inbox.lv>
parents: 18
diff changeset
90 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
91 say('Exiting due to a keyboard interrupt.', end='', file=sys.stderr)
141
dfde0f5e0984 A couple of Win32 fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 138
diff changeset
92 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
93 try:
146
d5b6708c1955 Distutils support, reorganization and cleaning up
Oleg Oshmyan <chortos@inbox.lv>
parents: 141
diff changeset
94 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
95 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
96 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
97 except Exception:
517dd43f06f8 Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents: 102
diff changeset
98 pass
517dd43f06f8 Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents: 102
diff changeset
99 # 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
100 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
101 sys.exit(1)
16
f2279b7602d3 Initial 2.00 commit
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
102
210
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
103 try:
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
104 if options.pause:
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
105 say('Press any key to exit...')
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
106 sys.stdout.flush()
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
107
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
108 if pause:
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
109 pause()
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
110 elif callable(globalconf.pause):
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
111 globalconf.pause()
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
112 else:
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
113 with open(os.devnull, 'w') as devnull:
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
114 subprocess.call(globalconf.pause, shell=True, stdout=devnull, stderr=subprocess.STDOUT)
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
115 except KeyboardInterrupt:
8c4e92fb32d8 Keyboard interrupts now satisfy the Press any key to exit... prompt
Oleg Oshmyan <chortos@inbox.lv>
parents: 202
diff changeset
116 pass