Mercurial > ~astiob > upreckon > hgweb
comparison upreckon/upreckon-vcs @ 146:d5b6708c1955
Distutils support, reorganization and cleaning up
* Removed command-line options -t and -u.
* Reorganized code:
o all modules are now in package upreckon;
o TestCaseNotPassed and its descendants now live in a separate
module exceptions;
o load_problem now lives in module problem.
* Commented out mentions of command-line option -c in --help.
* Added a distutils-based setup.py.
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Sat, 28 May 2011 14:24:25 +0100 |
parents | upreckon-vcs@dfde0f5e0984 |
children | b71995909857 39f8d10dbff7 |
comparison
equal
deleted
inserted
replaced
145:d2c266c8d820 | 146:d5b6708c1955 |
---|---|
1 #! /usr/bin/env python | |
2 # Copyright (c) 2009-2011 Chortos-2 <chortos@inbox.lv> | |
3 | |
4 from __future__ import division, with_statement | |
5 import optparse | |
6 | |
7 from upreckon import compat | |
8 from upreckon.compat import * | |
9 | |
10 version = '2.01.0 ($$REV$$)' | |
11 parser = optparse.OptionParser(version='Upreckon '+version, epilog='Python 2.5 or newer is required.') | |
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') | |
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)') | |
14 parser.add_option('--list-problems', action='store_true', default=False, help='just list all problem names') | |
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') | |
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; delete the stored input/output files if the solution uses standard I/O and the -c/--cleanup option is specified') | |
18 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') | |
19 parser.add_option('-k', '--skim', action='store_true', default=False, help='skip test groups as soon as one test case is failed') | |
20 parser.add_option('--no-time-limits', dest='no_maxtime', action='store_true', default=False, help='disable all time limits') | |
21 | |
22 options, args = parser.parse_args() | |
23 parser.destroy() | |
24 del parser | |
25 | |
26 from upreckon import config | |
27 import itertools, os, subprocess, sys, time | |
28 | |
29 if options.legacy: | |
30 compat.pseudobuiltins += 'xrange', | |
31 | |
32 if options.list_problems: | |
33 options.pause = False | |
34 | |
35 from upreckon import testcases | |
36 | |
37 try: | |
38 from upreckon.testcases import pause | |
39 except ImportError: | |
40 pause = None | |
41 | |
42 try: | |
43 globalconf = config.load_global() | |
44 | |
45 # Do this check here so that if we have to warn them, we do it as early as possible | |
46 if options.pause and not pause and not hasattr(globalconf, 'pause'): | |
47 if os.name == 'posix': | |
48 globalconf.pause = 'read -s -n 1' | |
49 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) | |
50 sys.stderr.flush() | |
51 elif os.name == 'nt': | |
52 globalconf.pause = 'pause' | |
53 else: | |
54 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.') | |
55 | |
56 from upreckon.problem import * | |
57 | |
58 # Support single-problem configurations | |
59 if globalconf.problems is None: | |
60 shouldprintnames = False | |
61 globalconf.multiproblem = False | |
62 globalconf.problems = os.path.curdir, | |
63 else: | |
64 globalconf.multiproblem = True | |
65 shouldprintnames = True | |
66 | |
67 if options.list_problems: | |
68 for taskname in globalconf.problems: | |
69 say(taskname) | |
70 sys.exit() | |
71 | |
72 ntasks = 0 | |
73 nfulltasks = 0 | |
74 maxscore = 0 | |
75 realscore = 0 | |
76 | |
77 for taskname in (globalconf.problems if not options.problems else options.problems): | |
78 problem = Problem(taskname) | |
79 | |
80 if ntasks and not options.copyonly: say() | |
81 if shouldprintnames: say(taskname) | |
82 | |
83 if options.copyonly: | |
84 problem.copytestdata() | |
85 else: | |
86 real, max = problem.test() | |
87 | |
88 ntasks += 1 | |
89 nfulltasks += real == max | |
90 realscore += real | |
91 maxscore += max | |
92 | |
93 if options.copyonly: | |
94 sys.exit() | |
95 | |
96 if ntasks != 1: | |
97 say() | |
98 say('Grand total: %g/%g weighted points; %d/%d problems solved fully' % (realscore, maxscore, nfulltasks, ntasks)) | |
99 except KeyboardInterrupt: | |
100 say('Exiting due to a keyboard interrupt.', end='', file=sys.stderr) | |
101 sys.stderr.flush() | |
102 try: | |
103 import signal | |
104 signal.signal(signal.SIGINT, signal.SIG_DFL) | |
105 os.kill(os.getpid(), signal.SIGINT) | |
106 except Exception: | |
107 pass | |
108 # Do this even if we got no exceptions, just in case | |
109 say(file=sys.stderr) | |
110 sys.exit(1) | |
111 | |
112 if options.pause: | |
113 say('Press any key to exit...') | |
114 sys.stdout.flush() | |
115 | |
116 if pause: | |
117 pause() | |
118 elif callable(globalconf.pause): | |
119 globalconf.pause() | |
120 else: | |
121 with open(os.devnull, 'w') as devnull: | |
122 subprocess.call(globalconf.pause, shell=True, stdout=devnull, stderr=subprocess.STDOUT) |