X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=wvtest.py;h=27749e348834ee354e58c59189e4a23cee93937b;hb=80a4ba9a5fdc430656f62cd11f1c3785c156f832;hp=4c4b4b99d0469e668c8241f8007230ac41a6a3f5;hpb=ac2d5af359adbc9b16da830239a4eee53b691c02;p=bup.git diff --git a/wvtest.py b/wvtest.py index 4c4b4b9..27749e3 100755 --- a/wvtest.py +++ b/wvtest.py @@ -149,9 +149,31 @@ def _run_in_chdir(path, func, *args, **kwargs): sys.path = oldpath +if sys.version_info >= (2,6,0): + _relpath = os.path.relpath; +else: + # Implementation for Python 2.5, taken from CPython (tag v2.6, + # file Lib/posixpath.py, hg-commit 95fff5a6a276). Update + # ./LICENSE When this code is eventually removed. + def _relpath(path, start=os.path.curdir): + if not path: + raise ValueError("no path specified") + + start_list = os.path.abspath(start).split(os.path.sep) + path_list = os.path.abspath(path).split(os.path.sep) + + # Work out how much of the filepath is shared by start and path. + i = len(os.path.commonprefix([start_list, path_list])) + + rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:] + if not rel_list: + return curdir + return os.path.join(*rel_list) + + def _runtest(fname, f): mod = inspect.getmodule(f) - relpath = os.path.relpath(mod.__file__, os.getcwd()).replace('.pyc', '.py') + relpath = _relpath(mod.__file__, os.getcwd()).replace('.pyc', '.py') print print 'Testing "%s" in %s:' % (fname, relpath) sys.stdout.flush()