X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=wvtest.py;h=9d3ee497ab715c8e2322c7e6a855d585f0679aee;hb=2040b6890af45318eb512b4c7f5398e040b1ffe5;hp=8a8302be10c2daec80a6768625a2183fe0930051;hpb=a69735928c9a5f155711ff500075a5b04d03493f;p=bup.git diff --git a/wvtest.py b/wvtest.py index 8a8302b..9d3ee49 100755 --- a/wvtest.py +++ b/wvtest.py @@ -1,9 +1,10 @@ #!/bin/sh """": # -*-python-*- -bup_python="$(dirname "$0")/cmd/bup-python" +bup_python="$(dirname "$0")/dev/bup-python" exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble + # # WvTest: # Copyright (C)2007-2012 Versabanq Innovations Inc. and contributors. @@ -11,6 +12,9 @@ exec "$bup_python" "$0" ${1+"$@"} # See the included file named LICENSE for license information. # You can get wvtest from: http://github.com/apenwarr/wvtest # + +from __future__ import absolute_import, print_function +from os.path import relpath import atexit import inspect import os @@ -60,8 +64,8 @@ if __name__ != '__main__': # we're imported as a module filename = os.path.basename(filename) msg = re.sub(r'\s+', ' ', str(msg)) sys.stderr.flush() - print '! %-70s %s' % ('%s:%-4d %s' % (filename, line, msg), - code) + print('! %-70s %s' % ('%s:%-4d %s' % (filename, line, msg), + code)) sys.stdout.flush() @@ -83,6 +87,14 @@ if __name__ != '__main__': # we're imported as a module _result(msg, tb, 'FAILED') return cond + def wvcheck(cond, msg, tb = None): + if tb == None: tb = _caller_stack(2) + if cond: + _result(msg, tb, 'ok') + else: + _result(msg, tb, 'FAILED') + return cond + _code_rx = re.compile(r'^\w+\((.*)\)(\s*#.*)?$') def _code(): text = _caller_stack(2)[3] @@ -144,13 +156,25 @@ if __name__ != '__main__': # we're imported as a module else: return _check(False, 'EXCEPT(%s)' % _code()) + wvstart = WVSTART + wvmsg = WVMSG + wvpass = WVPASS + wvfail = WVFAIL + wvpasseq = WVPASSEQ + wvpassne = WVPASSNE + wvpaslt = WVPASSLT + wvpassle = WVPASSLE + wvpassgt = WVPASSGT + wvpassge = WVPASSGE + wvexcept = WVEXCEPT + def wvfailure_count(): return _fails def _check_unfinished(): if _registered: for func in _registered: - print 'WARNING: not run: %r' % (func,) + print('WARNING: not run: %r' % (func,)) WVFAIL('wvtest_main() not called') if _fails: sys.exit(1) @@ -170,39 +194,17 @@ 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 = _relpath(mod.__file__, os.getcwd()).replace('.pyc', '.py') - print - print 'Testing "%s" in %s:' % (fname, relpath) + rpath = relpath(mod.__file__, os.getcwd()).replace('.pyc', '.py') + print() + print('Testing "%s" in %s:' % (fname, rpath)) sys.stdout.flush() try: _run_in_chdir(os.path.split(mod.__file__)[0], f) except Exception as e: - print - print traceback.format_exc() + print() + print(traceback.format_exc()) tb = sys.exc_info()[2] wvtest._result(e, traceback.extract_tb(tb)[1], 'EXCEPTION') @@ -211,8 +213,8 @@ def _run_registered_tests(): import wvtest as _wvtestmod while _wvtestmod._registered: t = _wvtestmod._registered.pop(0) - _runtest(t.func_name, t) - print + _runtest(t.__name__, t) + print() def wvtest_main(extra_testfiles=tuple()): @@ -220,20 +222,20 @@ def wvtest_main(extra_testfiles=tuple()): _run_registered_tests() for modname in extra_testfiles: if not os.path.exists(modname): - print 'Skipping: %s' % modname + print('Skipping: %s' % modname) continue if modname.endswith('.py'): modname = modname[:-3] - print 'Importing: %s' % modname + print('Importing: %s' % modname) path, mod = os.path.split(os.path.abspath(modname)) nicename = modname.replace(os.path.sep, '.') while nicename.startswith('.'): nicename = modname[1:] _run_in_chdir(path, __import__, nicename, None, None, []) _run_registered_tests() - print - print 'WvTest: %d tests, %d failures.' % (_wvtestmod._tests, - _wvtestmod._fails) + print() + print('WvTest: %d tests, %d failures.' % (_wvtestmod._tests, + _wvtestmod._fails)) if __name__ == '__main__':