+ func(*args, **kwargs)
+ except etype, e:
+ return _check(True, 'EXCEPT(%s)' % _code())
+ except:
+ _check(False, 'EXCEPT(%s)' % _code())
+ raise
+ else:
+ return _check(False, 'EXCEPT(%s)' % _code())
+
+ def wvfailure_count():
+ return _fails
+
+ def _check_unfinished():
+ if _registered:
+ for func in _registered:
+ print 'WARNING: not run: %r' % (func,)
+ WVFAIL('wvtest_main() not called')
+ if _fails:
+ sys.exit(1)
+
+ atexit.register(_check_unfinished)
+
+
+def _run_in_chdir(path, func, *args, **kwargs):
+ oldwd = os.getcwd()
+ oldpath = sys.path
+ try:
+ os.chdir(path)
+ sys.path += [path, os.path.split(path)[0]]
+ return func(*args, **kwargs)
+ finally:
+ os.chdir(oldwd)
+ 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)
+ sys.stdout.flush()
+ try:
+ _run_in_chdir(os.path.split(mod.__file__)[0], f)
+ except Exception, e:
+ print
+ print traceback.format_exc()
+ tb = sys.exc_info()[2]
+ wvtest._result(e, traceback.extract_tb(tb)[1], 'EXCEPTION')
+
+
+def _run_registered_tests():
+ import wvtest as _wvtestmod
+ while _wvtestmod._registered:
+ t = _wvtestmod._registered.pop(0)
+ _runtest(t.func_name, t)
+ print
+
+
+def wvtest_main(extra_testfiles=[]):
+ import wvtest as _wvtestmod
+ _run_registered_tests()
+ for modname in extra_testfiles: