Mercurial > ~astiob > upreckon > hgweb
comparison upreckon-vcs @ 102:796eb7667fb0
Added the --list-problems command-line option
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Fri, 01 Apr 2011 23:58:46 +0300 |
parents | c62c9bfd614a |
children | 517dd43f06f8 |
comparison
equal
deleted
inserted
replaced
101:b92333120c67 | 102:796eb7667fb0 |
---|---|
4 from __future__ import division, with_statement | 4 from __future__ import division, with_statement |
5 import optparse, sys, compat | 5 import optparse, sys, compat |
6 | 6 |
7 from compat import * | 7 from compat import * |
8 | 8 |
9 version = '2.00.0 ($$REV$$)' | 9 version = '2.01.0 ($$REV$$)' |
10 parser = optparse.OptionParser(version='Upreckon '+version, epilog='Python 2.5 or newer is required.') | 10 parser = optparse.OptionParser(version='Upreckon '+version, epilog='Python 2.5 or newer is required.') |
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') | 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') |
12 parser.add_option('-u', '--update', dest='update', action='store_true', default=False, help='update the installed Upreckon to the latest publicly available version') | 12 parser.add_option('-u', '--update', dest='update', action='store_true', default=False, help='update the installed Upreckon to the latest publicly available version') |
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)') | 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') | |
14 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') | 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') |
15 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') | 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') |
16 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') | 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') |
17 parser.add_option('-t', '--detect-time', dest='autotime', action='store_true', default=False, help='spend a second detecting the most precise time measurement function') | 18 parser.add_option('-t', '--detect-time', dest='autotime', action='store_true', default=False, help='spend a second detecting the most precise time measurement function') |
18 parser.add_option('-k', '--skim', action='store_true', default=False, help='skip test groups as soon as one test case is failed') | 19 parser.add_option('-k', '--skim', action='store_true', default=False, help='skip test groups as soon as one test case is failed') |
59 import config, itertools, os, subprocess, sys, time | 60 import config, itertools, os, subprocess, sys, time |
60 | 61 |
61 if options.legacy: | 62 if options.legacy: |
62 compat.pseudobuiltins += 'xrange', | 63 compat.pseudobuiltins += 'xrange', |
63 | 64 |
65 if options.list_problems: | |
66 options.pause = False | |
67 | |
64 import testcases | 68 import testcases |
65 | 69 |
66 try: | 70 try: |
67 from testcases import pause | 71 from testcases import pause |
68 except ImportError: | 72 except ImportError: |
69 pause = None | 73 pause = None |
70 | 74 |
71 try: | 75 try: |
72 globalconf = config.load_global() | 76 globalconf = config.load_global() |
73 | 77 |
74 # Do this check here so that if we have to warn them, we do it as early as possible | 78 # Do this check here so that if we have to warn them, we do it as early as possible |
75 if options.pause and not pause and not hasattr(globalconf, 'pause'): | 79 if options.pause and not pause and not hasattr(globalconf, 'pause'): |
76 if os.name == 'posix': | 80 if os.name == 'posix': |
77 globalconf.pause = 'read -s -n 1' | 81 globalconf.pause = 'read -s -n 1' |
78 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) | 82 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) |
79 sys.stderr.flush() | 83 sys.stderr.flush() |
80 elif os.name == 'nt': | 84 elif os.name == 'nt': |
81 globalconf.pause = 'pause' | 85 globalconf.pause = 'pause' |
82 else: | 86 else: |
83 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.') | 87 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.') |
84 | 88 |
85 from problem import * | 89 from problem import * |
86 | 90 |
87 # Support single-problem configurations | 91 # Support single-problem configurations |
88 if globalconf.problems is None: | 92 if globalconf.problems is None: |
89 shouldprintnames = False | 93 shouldprintnames = False |
90 globalconf.multiproblem = False | 94 globalconf.multiproblem = False |
91 globalconf.problems = os.path.curdir, | 95 globalconf.problems = os.path.curdir, |
92 else: | 96 else: |
93 globalconf.multiproblem = True | 97 globalconf.multiproblem = True |
94 shouldprintnames = True | 98 shouldprintnames = True |
95 | 99 |
100 if options.list_problems: | |
101 for taskname in globalconf.problems: | |
102 say(taskname) | |
103 sys.exit() | |
104 | |
96 ntasks = 0 | 105 ntasks = 0 |
97 nfulltasks = 0 | 106 nfulltasks = 0 |
98 maxscore = 0 | 107 maxscore = 0 |
99 realscore = 0 | 108 realscore = 0 |
100 | 109 |
101 for taskname in (globalconf.problems if not options.problems else options.problems): | 110 for taskname in (globalconf.problems if not options.problems else options.problems): |
102 problem = Problem(taskname) | 111 problem = Problem(taskname) |
103 | 112 |
104 if ntasks and not options.copyonly: say() | 113 if ntasks and not options.copyonly: say() |
105 if shouldprintnames: say(taskname) | 114 if shouldprintnames: say(taskname) |
111 | 120 |
112 ntasks += 1 | 121 ntasks += 1 |
113 nfulltasks += real == max | 122 nfulltasks += real == max |
114 realscore += real | 123 realscore += real |
115 maxscore += max | 124 maxscore += max |
116 | 125 |
117 if options.copyonly: | 126 if options.copyonly: |
118 sys.exit() | 127 sys.exit() |
119 | 128 |
120 if ntasks != 1: | 129 if ntasks != 1: |
121 say() | 130 say() |
122 say('Grand total: %g/%g weighted points; %d/%d problems solved fully' % (realscore, maxscore, nfulltasks, ntasks)) | 131 say('Grand total: %g/%g weighted points; %d/%d problems solved fully' % (realscore, maxscore, nfulltasks, ntasks)) |
123 except KeyboardInterrupt: | 132 except KeyboardInterrupt: |
124 sys.exit('Exiting due to a keyboard interrupt.') | 133 sys.exit('Exiting due to a keyboard interrupt.') |