More robust Scanner comparisons. (Kevin Quick)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 26 Sep 2004 06:12:36 +0000 (06:12 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 26 Sep 2004 06:12:36 +0000 (06:12 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1105 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/BuilderTests.py
src/engine/SCons/Scanner/ScannerTests.py
src/engine/SCons/Scanner/__init__.py

index c111ffd7ab8e2308588f4bd74fb9e1df3ea14acb..f1239de678dd0098c7de48e96a5fc86e53899c3e 100644 (file)
@@ -165,8 +165,9 @@ RELEASE 0.97 - XXX
   - Use the source_scanner from the target Node, not the source node
     itself.
 
-  - Enforce internally that Scanners are only passed Nodes.  Fix how a
-    Scanner.Selector called its base class initialization.
+  - Internal Scanners fixes:  Make sure Scanners are only passed Nodes.
+    Fix how a Scanner.Selector called its base class initialization.
+    Make comparisons of Scanner objects more robust.
 
   From Christoph Wiedemann:
 
index 53a5628401a87939cfd621b800955c6266fa3639..a67d22a26b45165a99cb7376eb90d24bb2d8f6e3 100644 (file)
@@ -864,6 +864,23 @@ class BuilderTestCase(unittest.TestCase):
         assert tgt.target_scanner == tscan, tgt.target_scanner
         assert tgt.source_scanner == tscan, tgt.source_scanner
 
+    def test_actual_scanner(self):
+        """Test usage of actual Scanner objects."""
+
+        import SCons.Scanner
+
+        def func(self):
+            pass
+        
+        scanner = SCons.Scanner.Scanner(func, name='fooscan')
+
+        b1 = SCons.Builder.Builder(action='bld', target_scanner=scanner)
+        b2 = SCons.Builder.Builder(action='bld', target_scanner=scanner)
+        b3 = SCons.Builder.Builder(action='bld')
+
+        assert b1 == b2
+        assert b1 != b3
+        
     def test_src_scanner(slf):
         """Testing ability to set a source file scanner through a builder."""
         class TestScanner:
index 2115c70afc677a4fda7f93ca406f2e9cda29cfbe..d4ae05b5e278be47b71111fd3744ca8beeb17405 100644 (file)
@@ -172,6 +172,11 @@ class BaseTestCase(unittest.TestCase):
         env.VARIABLE = "i4"
         self.test(s, env, DummyNode('i4.cpp'), ['i4.h', 'i4.hpp'], arg)
 
+    def test___cmp__(self):
+        """Test the Scanner.Base class __cmp__() method"""
+        s = SCons.Scanner.Base(self.func, "Cmp")
+        assert cmp(s, None)
+
     def test_hash(self):
         """Test the Scanner.Base class __hash__() method"""
         s = SCons.Scanner.Base(self.func, "Hash")
index f1b85e84095f7541820373d5f9c017bb2152eef0..68b56bb577d2a0d26d50444f0d8f6074cc788adb 100644 (file)
@@ -217,7 +217,11 @@ class Base:
         return nodes
 
     def __cmp__(self, other):
-        return cmp(self.__dict__, other.__dict__)
+        try:
+            return cmp(self.__dict__, other.__dict__)
+        except AttributeError:
+            # other probably doesn't have a __dict__
+            return cmp(self.__dict__, other)
 
     def __hash__(self):
         return id(self)