Allow subclassing of File and Dir nodes by having the must_be_same()
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 30 Dec 2008 23:15:49 +0000 (23:15 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 30 Dec 2008 23:15:49 +0000 (23:15 +0000)
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
src/engine/SCons/Node/FSTests.py

index 4e89e8d40eea325fced1ac1baf505882fc276c93..f8911b00ed0eedebf43f6c619f3c14fa4865f3fd 100644 (file)
@@ -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__)
index 424aa5eafe21e5cdddb45061338de10002568ef0..37dc465b14596359c4f9c5c12ecb6b69f6f5c167 100644 (file)
@@ -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')