summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2008-12-30 23:15:49 (GMT)
committerSteven Knight <knight@baldmt.com>2008-12-30 23:15:49 (GMT)
commitcc05c121706797a7708d135ce20ff40039111fa7 (patch)
treed31e1021d742e862be3124f1fdafc7249822f61c /src/engine
parent312f88d4f0daa0aa8ccdad202c76b7e297b605cd (diff)
downloadSCons-cc05c121706797a7708d135ce20ff40039111fa7.zip
SCons-cc05c121706797a7708d135ce20ff40039111fa7.tar.gz
SCons-cc05c121706797a7708d135ce20ff40039111fa7.tar.bz2
Allow subclassing of File and Dir nodes by having the must_be_same()
method check for isinstance(), not an exact class match.
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Node/FS.py2
-rw-r--r--src/engine/SCons/Node/FSTests.py14
2 files changed, 15 insertions, 1 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index 4e89e8d..f8911b0 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 424aa5e..37dc465 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')