Mercurial > ~astiob > upreckon > hgweb
changeset 2:bddcc05aba59
Finished path portability improvements
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Fri, 22 Jan 2010 19:48:24 +0000 |
parents | 43ec211e2c59 |
children | cd4304ff1d1b |
files | test.py |
diffstat | 1 files changed, 46 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/test.py Fri Jan 22 19:27:20 2010 +0000 +++ b/test.py Fri Jan 22 19:48:24 2010 +0000 @@ -3,7 +3,7 @@ import os, sys, shutil, time, subprocess, filecmp, optparse, signal, tempfile, tarfile, zipfile -parser = optparse.OptionParser(version='test.py 1.20.0', 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.') +parser = optparse.OptionParser(version='test.py 1.21.0 (SVN)', usage='usage: %prog [options] [problem names] [[path' + os.path.sep + 'to' + os.path.sep + ']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.') 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') parser.add_option('-c', '--cleanup', dest='clean', action='store_true', default=False, help='delete the copies of input/output files and exit') 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') @@ -19,7 +19,7 @@ globals1 = set(globals()) # Initialize some configuration variables with default values -tasknames = (os.curdir,) +tasknames = (os.path.curdir,) maxtime = 0 tests = () dummies = () @@ -88,7 +88,7 @@ except IOError, error: exc_info = sys.exc_info()[2] try: - execfile('tests/testconf.py') + execfile(os.path.join('tests', 'testconf.py')) except IOError: if not exectestconf_helper('testconf.py'): raise IOError, (error.errno, 'The configuration file is missing', error.filename), exc_info @@ -115,7 +115,7 @@ scoremaxoveralltasks = 0 ntasks = 0 nfulltasks = 0 -cwd = '' # At any time this is either '' or taskname + '/' +cwd = '' # At any time this is either '' or taskname if options.autotime: c = time.clock() @@ -185,15 +185,15 @@ return False def existstestcase(name): - if os.path.isfile('tests/' + taskname + '/' + name) or os.path.isfile('tests/' + name): + if os.path.isfile(os.path.join('tests', taskname, name)) or os.path.isfile(os.path.join('tests', name)): return True - if cwd and (os.path.isfile(oldcwd + '/tests/' + cwd + name) or os.path.isfile(oldcwd + '/tests/' + name)): + if cwd and (os.path.isfile(os.path.join(oldcwd, 'tests', cwd, name)) or os.path.isfile(os.path.join(oldcwd, 'tests', name))): return True - if existstestcase_helper(taskname + '/' + name) or existstestcase_helper(name): + if existstestcase_helper(os.path.join(taskname, name)) or existstestcase_helper(name): return True if cwd: os.chdir(oldcwd) - if existstestcase_helper(cwd + name) or existstestcase_helper(name): + if existstestcase_helper(os.path.join(cwd, name)) or existstestcase_helper(name): os.chdir(cwd) return True os.chdir(cwd) @@ -246,22 +246,22 @@ return None def opentestcase(name): - if os.path.isfile('tests/' + taskname + '/' + name): - return open('tests/' + taskname + '/' + name, 'rU') - elif os.path.isfile('tests/' + name): - return open('tests/' + name, 'rU') - f = opentestcase_helper(taskname + '/' + name) + if os.path.isfile(os.path.join('tests', taskname, name)): + return open(os.path.join('tests', taskname, name), 'rU') + elif os.path.isfile(os.path.join('tests', name)): + return open(os.path.join('tests', name), 'rU') + f = opentestcase_helper(os.path.join(taskname, name)) if not f: f = opentestcase_helper(name) if f: return f if cwd: - if os.path.isfile(oldcwd + '/tests/' + cwd + name): - return open(oldcwd + '/tests/' + cwd + name, 'rU') - elif os.path.isfile(oldcwd + '/tests/' + name): - return open(oldcwd + '/tests/' + name, 'rU') + if os.path.isfile(os.path.join(oldcwd, 'tests', cwd, name): + return open(os.path.join(oldcwd, 'tests', cwd, name), 'rU') + elif os.path.isfile(os.path.join(oldcwd, 'tests', name)): + return open(os.path.join(oldcwd, 'tests', name), 'rU') os.chdir(oldcwd) - f = opentestcase_helper(cwd + name) + f = opentestcase_helper(os.path.join(cwd, name)) if not f: f = opentestcase_helper(name) os.chdir(cwd) @@ -281,7 +281,7 @@ except KeyError: f.close() if os.path.isfile('tests.zip'): - if not target.startswith('/'): + if not os.path.isabs(target): f = zipfile.ZipFile('tests.zip') m = f.getinfo(name) try: @@ -293,8 +293,8 @@ f.close() else: oldcwd = os.getcwdu() - os.chdir('/') - f = zipfile.ZipFile(oldcwd + '/tests.zip') + os.chdir('/') # FIXME: portability? + f = zipfile.ZipFile(os.path.join(oldcwd, 'tests.zip')) try: m = f.getinfo(name) m.filename = target[1:] @@ -348,23 +348,23 @@ return False def copytestcase(name, target): - if os.path.isfile('tests/' + taskname + '/' + name): - shutil.copyfile('tests/' + taskname + '/' + name, target) + if os.path.isfile(os.path.join('tests', taskname, name)): + shutil.copyfile(os.path.join('tests', taskname, name), target) return - elif os.path.isfile('tests/' + name): - shutil.copyfile('tests/' + name, target) + elif os.path.isfile(os.path.join('tests', name)): + shutil.copyfile(os.path.join('tests', name), target) return - if copytestcase_helper(taskname + '/' + name, target) or copytestcase_helper(name, target): + if copytestcase_helper(os.path.join(taskname, name), target) or copytestcase_helper(name, target): return if cwd: - if os.path.isfile(oldcwd + '/tests/' + cwd + name): - shutil.copyfile(oldcwd + '/tests/' + cwd + name, target) + if os.path.isfile(os.path.join(oldcwd, 'tests', cwd, name)): + shutil.copyfile(os.path.join(oldcwd, 'tests', cwd, name), target) return - elif os.path.isfile(oldcwd + '/tests/' + name): - shutil.copyfile(oldcwd + '/tests/' + name, target) + elif os.path.isfile(os.path.join(oldcwd, 'tests', name)): + shutil.copyfile(os.path.join(oldcwd, 'tests', name), target) return os.chdir(oldcwd) - if copytestcase_helper(cwd + name, target) or copytestcase_helper(name, target): + if copytestcase_helper(os.path.join(cwd, name), target) or copytestcase_helper(name, target): os.chdir(cwd) return os.chdir(cwd) @@ -377,32 +377,32 @@ if os.path.isdir(taskname): os.chdir(taskname) if taskname != : - cwd = taskname + '/' + cwd = taskname try: execfile('testconf.py', globals()) return except IOError: pass if not cwd: - if os.path.isfile('tests/' + taskname + '/testconf.py'): - execfile('tests/' + taskname + '/testconf.py', globals()) + if os.path.isfile(os.path.join('tests', taskname, 'testconf.py')): + execfile(os.path.join('tests', taskname, 'testconf.py'), globals()) return - if os.path.isfile('tests/testconf.py'): - execfile('tests/testconf.py', globals()) + if os.path.isfile(os.path.join('tests', 'testconf.py')): + execfile(os.path.join('tests', 'testconf.py'), globals()) return - if exectestconf_helper(taskname + '/testconf.py') or exectestconf_helper('testconf.py'): + if exectestconf_helper(os.path.join(taskname, 'testconf.py')) or exectestconf_helper('testconf.py'): return if cwd: os.chdir(oldcwd) - if os.path.isfile('tests/' + cwd + 'testconf.py'): - execfile('tests/' + cwd + 'testconf.py', globals()) + if os.path.isfile(os.path.join('tests', cwd, 'testconf.py')): + execfile(os.path.join('tests', cwd, 'testconf.py'), globals()) os.chdir(cwd) return - if os.path.isfile('tests/testconf.py'): - execfile('tests/testconf.py', globals()) + if os.path.isfile(os.path.join('tests', 'testconf.py')): + execfile(os.path.join('tests', 'testconf.py'), globals()) os.chdir(cwd) return - if exectestconf_helper(cwd + 'testconf.py') or exectestconf_helper('testconf.py'): + if exectestconf_helper(os.path.join(cwd, 'testconf.py')) or exectestconf_helper('testconf.py'): os.chdir(cwd) return if os.path.isfile('testconf.py'): @@ -429,7 +429,7 @@ if len(tasknames) > 1: print taskname except Exception: - if taskname != os.curdir or ntasks: + if taskname != os.path.curdir or ntasks: print taskname try: del inname @@ -439,8 +439,8 @@ try: del ansname except NameError: pass - if not namedefined and taskname != os.curdir: - name = os.path + os.sep + taskname + if not namedefined and taskname != os.path.curdir: + name = os.path.join(os.path.curdir, taskname) for k in shared: g[k] = shared[k] @@ -603,7 +603,7 @@ # Windows doesn't like paths beginning with .\ and not ending with an extension name = os.path.normcase(name) - if name.startswith('.\\'): + if os.name == 'nt' and name.startswith('.\\'): name = name[2:] newpointmap = {}