From 8e5254a6589204c571d901613defa9f1e62254b8 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Tue, 30 Dec 2008 23:15:49 +0000 Subject: [PATCH] Allow subclassing of File and Dir nodes by having the must_be_same() method check for isinstance(), not an exact class match. git-svn-id: http://scons.tigris.org/svn/scons/trunk@3866 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Node/FS.py | 2 +- src/engine/SCons/Node/FSTests.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 4e89e8d4..f8911b00 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -582,7 +582,7 @@ class Base(SCons.Node.Node): This node, which already existed, is being looked up as the specified klass. Raise an exception if it isn't. """ - if self.__class__ is klass or klass is Entry: + if isinstance(self, klass) or klass is Entry: return raise TypeError, "Tried to lookup %s '%s' as a %s." %\ (self.__class__.__name__, self.path, klass.__name__) diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 424aa5ea..37dc465b 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -1691,6 +1691,13 @@ class DirTestCase(_tempdirTestCase): assert a[0] == 'pre', a assert a[2] == 'post', a + def test_subclass(self): + """Test looking up subclass of Dir nodes""" + class DirSubclass(SCons.Node.FS.Dir): + pass + sd = self.fs._lookup('special_dir', None, DirSubclass, create=1) + sd.must_be_same(SCons.Node.FS.Dir) + def test_get_env_scanner(self): """Test the Dir.get_env_scanner() method """ @@ -2109,6 +2116,13 @@ class EntryTestCase(_tempdirTestCase): class FileTestCase(_tempdirTestCase): + def test_subclass(self): + """Test looking up subclass of File nodes""" + class FileSubclass(SCons.Node.FS.File): + pass + sd = self.fs._lookup('special_file', None, FileSubclass, create=1) + sd.must_be_same(SCons.Node.FS.File) + def test_Dirs(self): """Test the File.Dirs() method""" fff = self.fs.File('subdir/fff') -- 2.26.2