Mercurial > ~astiob > upreckon > hgweb
comparison 1.20/test.py @ 20:5bfa23cd638d
More ZIP archive fixes
One typo and one Windows incompatibility fixed.
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Mon, 14 Jun 2010 21:02:06 +0000 |
parents | d4fc9341664e |
children |
comparison
equal
deleted
inserted
replaced
19:d4fc9341664e | 20:5bfa23cd638d |
---|---|
1 #! /usr/bin/python | 1 #! /usr/bin/python |
2 # Copyright (c) 2009, 2010 Chortos-2 <chortos@inbox.lv> | 2 # Copyright (c) 2009, 2010 Chortos-2 <chortos@inbox.lv> |
3 | 3 |
4 import os, sys, shutil, time, subprocess, filecmp, optparse, signal, tempfile, tarfile, zipfile | 4 import os, sys, shutil, time, subprocess, filecmp, optparse, signal, tempfile, tarfile, zipfile |
5 | 5 |
6 parser = optparse.OptionParser(version='test.py 1.20.2', usage='usage: %prog [options] [problem names] [[path/to/]solution-app] [test case numbers]\n\nTest case numbers can be specified in plain text or as a Python expression\nif there is only one positional argument.\n\nOnly problem names listed in testconf.py are recognized.') | 6 parser = optparse.OptionParser(version='test.py 1.20.3', usage='usage: %prog [options] [problem names] [[path/to/]solution-app] [test case numbers]\n\nTest case numbers can be specified in plain text or as a Python expression\nif there is only one positional argument.\n\nOnly problem names listed in testconf.py are recognized.') |
7 parser.add_option('-e', '--exclude', dest='exclude', action='append', help='test case number(s) to exclude, as a Python expression; multiple -e options can be supplied') | 7 parser.add_option('-e', '--exclude', dest='exclude', action='append', help='test case number(s) to exclude, as a Python expression; multiple -e options can be supplied') |
8 parser.add_option('-c', '--cleanup', dest='clean', action='store_true', default=False, help='delete the copies of input/output files and exit') | 8 parser.add_option('-c', '--cleanup', dest='clean', action='store_true', default=False, help='delete the copies of input/output files and exit') |
9 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') | 9 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') |
10 parser.add_option('-m', '--copy-io', dest='copyonly', action='store_true', default=False, help='only create a copy of the input/output files of the last test case for manual testing; to delete them, use options -cs') | 10 parser.add_option('-m', '--copy-io', dest='copyonly', action='store_true', default=False, help='only create a copy of the input/output files of the last test case for manual testing; to delete them, use options -cs') |
11 parser.add_option('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed when finished testing') | 11 parser.add_option('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed when finished testing') |
295 oldcwd = os.getcwdu() | 295 oldcwd = os.getcwdu() |
296 os.chdir('/') | 296 os.chdir('/') |
297 f = zipfile.ZipFile(oldcwd + '/tests.zip') | 297 f = zipfile.ZipFile(oldcwd + '/tests.zip') |
298 try: | 298 try: |
299 m = f.getinfo(name) | 299 m = f.getinfo(name) |
300 m.filename = target[1:] | 300 m.filename = os.path.relpath(target) |
301 f.extract(m) | 301 f.extract(m) |
302 f.close() | 302 f.close() |
303 os.chdir(oldcwd) | 303 os.chdir(oldcwd) |
304 return True | 304 return True |
305 except KeyError: | 305 except KeyError: |
306 f.close() | 306 f.close() |
307 os.chdir(oldwcd) | 307 os.chdir(oldcwd) |
308 if os.path.isfile('tests.tgz'): | 308 if os.path.isfile('tests.tgz'): |
309 f = tarfile.open('tests.tgz') | 309 f = tarfile.open('tests.tgz') |
310 try: | 310 try: |
311 m = f.getmember(name) | 311 m = f.getmember(name) |
312 m.name = target | 312 m.name = target |