# HG changeset patch # User Oleg Oshmyan # Date 1307065142 -3600 # Node ID 006dce02752cbf877d3da44c49d3fc370a4c05a7 # Parent a1286da36d294b43432315f31d64f2e4efd69d6a Added the testee configuration variable and the config.nativize_path function The testee configuration variable stores the string or iterable of strings to pass to subprocess.Popen except that the first/only string always follows the POSIX pathname format or, if the native format is really needed, is prefixed by slash-slash-colon (the same format is used in Boost.Filesystem). config.nativize_path is now a part of the public API of the config module. It converts a path in the format described above into the native format and can be used in testconf if it needs to use paths other than testee[0]. diff -r a1286da36d29 -r 006dce02752c upreckon/config.py --- a/upreckon/config.py Thu Jun 02 14:25:23 2011 +0100 +++ b/upreckon/config.py Fri Jun 03 02:39:02 2011 +0100 @@ -14,9 +14,9 @@ else: zipimport = None -import imp, os, sys, tempfile +import imp, os, posixpath, sys, tempfile -__all__ = 'load_problem', 'load_global', 'globalconf' +__all__ = 'load_problem', 'load_global', 'globalconf', 'nativize_path' defaults_problem = {'kind': 'batch', 'usegroups': False, @@ -82,6 +82,22 @@ self.file.close() os.remove(self.name) +def nativize_path(portable_path): + if portable_path.startswith('//:'): + return portable_path[3:] + comps = portable_path.split('/') + for i, comp in enumerate(comps): + if comp == '..': + comps[i] = os.path.pardir + elif comp == '.': + comps[i] = os.path.curdir + native_path = os.path.join(*comps) + if posixpath.isabs(portable_path) != os.path.isabs(native_path): + native_path = os.path.sep + native_path + if posixpath.isabs(portable_path) != os.path.isabs(native_path): + raise ValueError('cannot make native path relative/absolute') + return native_path + def load_problem(problem_name): global builtins try: @@ -89,7 +105,7 @@ sys.dont_write_bytecode = True except AttributeError: pass - metafile = files.File('/'.join((problem_name, 'testconf.py')), True, 'configuration') + metafile = files.File(problem_name + '/testconf.py', True, 'configuration') module = None with CompatBuiltins() as builtins: if zipimport and isinstance(metafile.archive, files.ZipArchive): @@ -134,7 +150,13 @@ module.dummyinname = getattr(module, 'testcaseinname', module.dummyinname) if not module.dummyoutname: module.dummyoutname = getattr(module, 'testcaseoutname', module.dummyoutname) - if not hasattr(module, 'path'): + if hasattr(module, 'testee'): + if isinstance(module.testee, basestring): + module.path = nativize_path(module.testee) + else: + testee = tuple(module.testee) + module.path = (nativize_path(testee[0]),) + testee[1:] + elif not hasattr(module, 'path'): if hasattr(module, 'name'): module.path = module.name elif sys.platform != 'win32':