diff options
| author | Johnny Chen <johnny.chen@apple.com> | 2010-08-05 23:42:46 +0000 |
|---|---|---|
| committer | Johnny Chen <johnny.chen@apple.com> | 2010-08-05 23:42:46 +0000 |
| commit | 73258830f391047d9ee9ae4a07fd8ced4d7cf0a9 (patch) | |
| tree | 70373b8e3fddf27ccbabb93bb587ab7debb65f29 /lldb/test/unittest2/compatibility.py | |
| parent | 755aceb5d0df842b5132052d474c361b5605aedb (diff) | |
| download | bcm5719-llvm-73258830f391047d9ee9ae4a07fd8ced4d7cf0a9.tar.gz bcm5719-llvm-73258830f391047d9ee9ae4a07fd8ced4d7cf0a9.zip | |
o Added unittest2 which has added the new features in unittest for Python 2.7
backported to Python 2.3+. Some of the features desired include better
verbose reporting in unittest2.TextTestRunner and decorator support for
skipping tests and expected failures.
http://pypi.python.org/pypi/unittest2
o Modified the existing .py tests to use unittest2 and decorated
TestSTL.test_step_into_stl(), which is known to always fail currently, with
@unittest2.expectedFailure.
llvm-svn: 110397
Diffstat (limited to 'lldb/test/unittest2/compatibility.py')
| -rw-r--r-- | lldb/test/unittest2/compatibility.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/lldb/test/unittest2/compatibility.py b/lldb/test/unittest2/compatibility.py new file mode 100644 index 00000000000..b8f15dd1428 --- /dev/null +++ b/lldb/test/unittest2/compatibility.py @@ -0,0 +1,64 @@ +import os +import sys + +try: + from functools import wraps +except ImportError: + # only needed for Python 2.4 + def wraps(_): + def _wraps(func): + return func + return _wraps + +__unittest = True + +def _relpath_nt(path, start=os.path.curdir): + """Return a relative version of a path""" + + 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) + if start_list[0].lower() != path_list[0].lower(): + unc_path, rest = os.path.splitunc(path) + unc_start, rest = os.path.splitunc(start) + if bool(unc_path) ^ bool(unc_start): + raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)" + % (path, start)) + else: + raise ValueError("path is on drive %s, start on drive %s" + % (path_list[0], start_list[0])) + # Work out how much of the filepath is shared by start and path. + for i in range(min(len(start_list), len(path_list))): + if start_list[i].lower() != path_list[i].lower(): + break + else: + i += 1 + + rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:] + if not rel_list: + return os.path.curdir + return os.path.join(*rel_list) + +# default to posixpath definition +def _relpath_posix(path, start=os.path.curdir): + """Return a relative version of a path""" + + 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 os.path.curdir + return os.path.join(*rel_list) + +if os.path is sys.modules.get('ntpath'): + relpath = _relpath_nt +else: + relpath = _relpath_posix |

