From f6387de9aedb21ff6f06dcc47b4e59b151d21d6c Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sun, 26 Sep 2004 06:12:36 +0000 Subject: [PATCH] More robust Scanner comparisons. (Kevin Quick) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1105 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 5 +++-- src/engine/SCons/BuilderTests.py | 17 +++++++++++++++++ src/engine/SCons/Scanner/ScannerTests.py | 5 +++++ src/engine/SCons/Scanner/__init__.py | 6 +++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index c111ffd7..f1239de6 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -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: diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 53a56284..a67d22a2 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -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: diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index 2115c70a..d4ae05b5 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -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") diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index f1b85e84..68b56bb5 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -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) -- 2.26.2