From: stevenknight Date: Sun, 9 Nov 2003 03:11:32 +0000 (+0000) Subject: Don't swallow the AttributeError for an expansion like .bak. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c0768649cd1cb182ee64c012fb0c949445d04376;p=scons.git Don't swallow the AttributeError for an expansion like .bak. git-svn-id: http://scons.tigris.org/svn/scons/trunk@840 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 4021c834..c30d6c8c 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -8,6 +8,18 @@ +RELEASE 0.95 - XXX + + From Steven Knight: + + - Fix EnsureSConsVersion() so it checks against the SCons version, + not the Python version, on Pythons with sys.version_info. + + - Don't swallow the AttributeError when someone uses an expansion like + $TARGET.bak, so we can supply a more informative error message. + + + RELEASE 0.94 - Fri, 07 Nov 2003 05:29:48 -0600 From Hartmut Goebel: diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index cffa2b5d..bce5364d 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -290,7 +290,13 @@ class EntryProxy(SCons.Util.Proxy): try: return self.dictSpecialAttrs[name](self) except KeyError: - return SCons.Util.Proxy.__getattr__(self, name) + try: + attr = SCons.Util.Proxy.__getattr__(self, name) + except AttributeError: + entry = self.get() + classname = string.split(str(entry.__class__), '.')[-1] + raise AttributeError, "%s instance '%s' has no attribute '%s'" % (classname, entry.name, name) + return attr class Base(SCons.Node.Node): """A generic class for file system entries. This class is for diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 2237959e..54c6523b 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -1716,6 +1716,32 @@ class SpecialAttrTestCase(unittest.TestCase): assert f.posix.for_signature() == 'baz.blat_posix', \ f.posix.for_signature() + # Check that attempts to access non-existent attributes of the + # subst proxy generate the right exceptions and messages. + caught = None + try: + fs.Dir('ddd').get_subst_proxy().no_such_attr + except AttributeError, e: + assert str(e) == "Dir instance 'ddd' has no attribute 'no_such_attr'", e + caught = 1 + assert caught, "did not catch expected AttributeError" + + caught = None + try: + fs.Entry('eee').get_subst_proxy().no_such_attr + except AttributeError, e: + assert str(e) == "Entry instance 'eee' has no attribute 'no_such_attr'", e + caught = 1 + assert caught, "did not catch expected AttributeError" + + caught = None + try: + fs.File('fff').get_subst_proxy().no_such_attr + except AttributeError, e: + assert str(e) == "File instance 'fff' has no attribute 'no_such_attr'", e + caught = 1 + assert caught, "did not catch expected AttributeError" + fs.BuildDir('foo', 'baz') assert str(f.srcpath) == os.path.normpath('baz/bar/baz.blat'), str(f.srcpath) diff --git a/src/engine/SCons/Sig/MD5.py b/src/engine/SCons/Sig/MD5.py index c50dbb7f..21cb24c0 100644 --- a/src/engine/SCons/Sig/MD5.py +++ b/src/engine/SCons/Sig/MD5.py @@ -79,10 +79,10 @@ def signature(obj): """Generate a signature for an object """ try: - contents = str(obj.get_contents()) + gc = obj.get_contents except AttributeError: raise AttributeError, "unable to fetch contents of '%s'" % str(obj) - return hexdigest(md5.new(contents).digest()) + return hexdigest(md5.new(str(gc())).digest()) def to_string(signature): """Convert a signature to a string""" diff --git a/src/engine/SCons/Sig/MD5Tests.py b/src/engine/SCons/Sig/MD5Tests.py index 6285e87e..67bdfc9b 100644 --- a/src/engine/SCons/Sig/MD5Tests.py +++ b/src/engine/SCons/Sig/MD5Tests.py @@ -88,6 +88,19 @@ class MD5TestCase(unittest.TestCase): else: raise AttributeError, "unexpected get_contents() attribute" + # Make sure we don't eat AttributeErrors raised internally + # by the get_contents() method (or anything it calls). + caught = None + try: + class xxx: + def get_contents(self): + raise AttributeError, "internal AttributeError" + signature(xxx()) + except AttributeError, e: + assert str(e) == "internal AttributeError", e + caught = 1 + assert caught, "did not catch expected AttributeError" + def test_to_string(self): assert '698d51a19d8a121ce581499d7b701668' == to_string('698d51a19d8a121ce581499d7b701668')