Fix comparisons between Action and subclass instances. (Kevin Quick)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 31 Aug 2004 02:16:18 +0000 (02:16 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 31 Aug 2004 02:16:18 +0000 (02:16 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1051 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Action.py
src/engine/SCons/ActionTests.py

index 830679108e80fb59833be40a2344e6a3b451a233..69ba78c1adb99cca5287852062636bbe799d67e7 100644 (file)
@@ -474,7 +474,7 @@ class LazyCmdGenerator:
             return ''
 
     def __cmp__(self, other):
-        return cmp(self.__dict__, other.__dict__)
+        return cmp(self.__dict__, other)
 
 class FunctionAction(ActionBase):
     """Class for Python function actions."""
index 4c1649c748d56eedb9ef204327bac9e83c6d92dd..be0b418f467d287e8478e4e897be3cbf879c6c49 100644 (file)
@@ -1521,6 +1521,35 @@ class ActionFactoryTestCase(unittest.TestCase):
         assert strfunc_args == [3, 6, 9], strfunc_args
 
 
+class ActionCompareTestCase(unittest.TestCase):
+
+    def test_1_solo_name(self):
+        """Test Lazy Cmd Generator Action get_name alone.
+
+        Basically ensures we can locate the builder, comparing it to
+        itself along the way."""
+        bar = SCons.Builder.Builder(action = {})
+        env = Environment( BUILDERS = {'BAR' : bar} )
+        name = bar.get_name(env)
+        assert name == 'BAR', name
+
+    def test_2_multi_name(self):
+        """Test LazyCmdGenerator Action get_name multi builders.
+
+        Ensure that we can compare builders (and thereby actions) to
+        each other safely."""
+        foo = SCons.Builder.Builder(action = '$FOO', suffix = '.foo')
+        bar = SCons.Builder.Builder(action = {})
+        assert foo != bar
+        assert foo.action != bar.action
+        env = Environment( BUILDERS = {'FOO' : foo,
+                                       'BAR' : bar} )
+        name = foo.get_name(env)
+        assert name == 'FOO', name
+        name = bar.get_name(env)
+        assert name == 'BAR', name
+
+
 if __name__ == "__main__":
     suite = unittest.TestSuite()
     tclasses = [ ActionTestCase,
@@ -1531,7 +1560,8 @@ if __name__ == "__main__":
                  ListActionTestCase,
                  LazyActionTestCase,
                  ActionCallerTestCase,
-                 ActionFactoryTestCase ]
+                 ActionFactoryTestCase,
+                 ActionCompareTestCase ]
     for tclass in tclasses:
         names = unittest.getTestCaseNames(tclass, 'test_')
         suite.addTests(map(tclass, names))