diff options
author | Steven Knight <knight@baldmt.com> | 2008-12-29 07:24:44 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2008-12-29 07:24:44 (GMT) |
commit | d0259ae0e1a37f431b21c8a7116b4206c127f8b6 (patch) | |
tree | ac603ddf6339b5c1f187d7b045da5fd5476c617c | |
parent | f6086e2bc3dd2e2d2237cdc94aa92b42658c8139 (diff) | |
download | SCons-d0259ae0e1a37f431b21c8a7116b4206c127f8b6.zip SCons-d0259ae0e1a37f431b21c8a7116b4206c127f8b6.tar.gz SCons-d0259ae0e1a37f431b21c8a7116b4206c127f8b6.tar.bz2 |
Update to latest Test{Cmd,Common}.py, including fixes for working
with other modules that use atexit, a zip() in earlier Python
versions that don't have it built in, and better error message
reported when we can't compile a regular expression.
-rw-r--r-- | QMTest/TestCmd.py | 53 | ||||
-rw-r--r-- | QMTest/TestCommon.py | 4 |
2 files changed, 49 insertions, 8 deletions
diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index ce77a02..8b70e4c 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -181,8 +181,8 @@ version. # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. __author__ = "Steven Knight <knight at baldmt dot com>" -__revision__ = "TestCmd.py 0.32.D001 2008/10/30 23:00:04 knight" -__version__ = "0.32" +__revision__ = "TestCmd.py 0.34.D001 2008/12/28 23:12:34 knight" +__version__ = "0.34" import errno import os @@ -239,6 +239,8 @@ re_space = re.compile('\s') _Cleanup = [] +_chain_to_exitfunc = None + def _clean(): global _Cleanup cleanlist = filter(None, _Cleanup) @@ -246,8 +248,29 @@ def _clean(): cleanlist.reverse() for test in cleanlist: test.cleanup() + if _chain_to_exitfunc: + _chain_to_exitfunc() + +try: + import atexit +except ImportError: + # TODO(1.5): atexit requires python 2.0, so chain sys.exitfunc + try: + _chain_to_exitfunc = sys.exitfunc + except AttributeError: + pass + sys.exitfunc = _clean +else: + atexit.register(_clean) -sys.exitfunc = _clean +try: + zip +except NameError: + def zip(*lists): + result = [] + for i in xrange(min(map(len, lists))): + result.append(tuple(map(lambda l, i=i: l[i], lists))) + return result class Collector: def __init__(self, top): @@ -365,7 +388,13 @@ def match_re(lines = None, res = None): if len(lines) != len(res): return for i in range(len(lines)): - if not re.compile("^" + res[i] + "$").search(lines[i]): + s = "^" + res[i] + "$" + try: + expr = re.compile(s) + except re.error, e: + msg = "Regular expression error in %s: %s" + raise re.error, msg % (repr(s), e[0]) + if not expr.search(lines[i]): return return 1 @@ -376,7 +405,13 @@ def match_re_dotall(lines = None, res = None): lines = string.join(lines, "\n") if not type(res) is type(""): res = string.join(res, "\n") - if re.compile("^" + res + "$", re.DOTALL).match(lines): + s = "^" + res + "$" + try: + expr = re.compile(s, re.DOTALL) + except re.error, e: + msg = "Regular expression error in %s: %s" + raise re.error, msg % (repr(s), e[0]) + if expr.match(lines): return 1 def diff_re(a, b, fromfile='', tofile='', @@ -396,7 +431,13 @@ def diff_re(a, b, fromfile='', tofile='', b = b + ['']*diff i = 0 for aline, bline in zip(a, b): - if not re.compile("^" + aline + "$").search(bline): + s = "^" + aline + "$" + try: + expr = re.compile(s) + except re.error, e: + msg = "Regular expression error in %s: %s" + raise re.error, msg % (repr(s), e[0]) + if not expr.search(bline): result.append("%sc%s" % (i+1, i+1)) result.append('< ' + repr(a[i])) result.append('---') diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py index 661c86c..fe1e680 100644 --- a/QMTest/TestCommon.py +++ b/QMTest/TestCommon.py @@ -85,8 +85,8 @@ The TestCommon module also provides the following variables # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. __author__ = "Steven Knight <knight at baldmt dot com>" -__revision__ = "TestCommon.py 0.32.D001 2008/10/30 23:00:04 knight" -__version__ = "0.32" +__revision__ = "TestCommon.py 0.34.D001 2008/12/28 23:12:34 knight" +__version__ = "0.34" import copy import os |