Merged revisions 2302-2362,2364-2452 via svnmerge from
[scons.git] / src / engine / SCons / UtilTests.py
index 724c51db241cc26ffb523fce9e86d5c36d3702b5..3e8085bae8f58d1170d27818dba9cf9712a4ff53 100644 (file)
@@ -46,6 +46,18 @@ class OutBuffer:
     def write(self, str):
         self.buffer = self.buffer + str
 
+class dictifyTestCase(unittest.TestCase):
+    def test_dictify(self):
+        """Test the dictify() function"""
+        r = SCons.Util.dictify(['a', 'b', 'c'], [1, 2, 3])
+        assert r == {'a':1, 'b':2, 'c':3}, r
+
+        r = {}
+        SCons.Util.dictify(['a'], [1], r)
+        SCons.Util.dictify(['b'], [2], r)
+        SCons.Util.dictify(['c'], [3], r)
+        assert r == {'a':1, 'b':2, 'c':3}, r
+
 class UtilTestCase(unittest.TestCase):
     def test_splitext(self):
         assert splitext('foo') == ('foo','')
@@ -56,6 +68,7 @@ class UtilTestCase(unittest.TestCase):
         def __init__(self, name, children=[]):
             self.children = children
             self.name = name
+            self.nocache = None
         def __str__(self):
             return self.name
         def exists(self):
@@ -72,7 +85,9 @@ class UtilTestCase(unittest.TestCase):
             return 1
         def always_build(self):
             return 1
-        def current(self):
+        def is_up_to_date(self):
+            return 1
+        def noclean(self):
             return 1
 
     def tree_case_1(self):
@@ -98,12 +113,12 @@ class UtilTestCase(unittest.TestCase):
 """
 
         lines = string.split(expect, '\n')[:-1]
-        lines = map(lambda l: '[E BSPAC]'+l, lines)
+        lines = map(lambda l: '[E BSPAC]'+l, lines)
         withtags = string.join(lines, '\n') + '\n'
 
         return foo, expect, withtags
 
-    def tree_case_2(self):
+    def tree_case_2(self, prune=1):
         """Fixture for the render_tree() and print_tree() tests."""
 
         stdlib_h = self.Node("stdlib.h")
@@ -118,10 +133,15 @@ class UtilTestCase(unittest.TestCase):
     +-blat.h
     | +-stdlib.h
     +-bar.h
+      +-[stdlib.h]
 """
 
+        if not prune:
+            expect = string.replace(expect, '[', '')
+            expect = string.replace(expect, ']', '')
+
         lines = string.split(expect, '\n')[:-1]
-        lines = map(lambda l: '[E BSPAC]'+l, lines)
+        lines = map(lambda l: '[E BSPAC]'+l, lines)
         withtags = string.join(lines, '\n') + '\n'
 
         return blat_o, expect, withtags
@@ -159,7 +179,7 @@ class UtilTestCase(unittest.TestCase):
             actual = sys.stdout.getvalue()
             assert withtags == actual, (withtags, actual)
 
-            node, expect, withtags = self.tree_case_2()
+            node, expect, withtags = self.tree_case_2(prune=0)
 
             sys.stdout = StringIO.StringIO()
             print_tree(node, get_children, 1)
@@ -186,6 +206,7 @@ class UtilTestCase(unittest.TestCase):
         assert is_Dict({})
         assert is_Dict(UserDict())
         assert not is_Dict([])
+        assert not is_Dict(())
         assert not is_Dict("")
         if hasattr(types, 'UnicodeType'):
             exec "assert not is_Dict(u'')"
@@ -194,6 +215,7 @@ class UtilTestCase(unittest.TestCase):
         assert is_List([])
         import UserList
         assert is_List(UserList.UserList())
+        assert not is_List(())
         assert not is_List({})
         assert not is_List("")
         if hasattr(types, 'UnicodeType'):
@@ -211,6 +233,15 @@ class UtilTestCase(unittest.TestCase):
             assert is_String(UserString.UserString(''))
         assert not is_String({})
         assert not is_String([])
+        assert not is_String(())
+
+    def test_is_Tuple(self):
+        assert is_Tuple(())
+        assert not is_Tuple([])
+        assert not is_Tuple({})
+        assert not is_Tuple("")
+        if hasattr(types, 'UnicodeType'):
+            exec "assert not is_Tuple(u'')"
 
     def test_to_String(self):
         """Test the to_String() method."""
@@ -668,7 +699,33 @@ bling
             'bling\n',
         ], lines
 
+class MD5TestCase(unittest.TestCase):
+
+    def test_collect(self):
+        """Test collecting a list of signatures into a new signature value
+        """
+        s = map(MD5signature, ('111', '222', '333'))
+        
+        assert '698d51a19d8a121ce581499d7b701668' == MD5collect(s[0:1])
+        assert '8980c988edc2c78cc43ccb718c06efd5' == MD5collect(s[0:2])
+        assert '53fd88c84ff8a285eb6e0a687e55b8c7' == MD5collect(s)
+
+    def test_MD5signature(self):
+        """Test generating a signature"""
+        s = MD5signature('111')
+        assert '698d51a19d8a121ce581499d7b701668' == s, s
+
+        s = MD5signature('222')
+        assert 'bcbe3365e6ac95ea2c0343a2395834dd' == s, s
+
 if __name__ == "__main__":
-    suite = unittest.makeSuite(UtilTestCase, 'test_')
+    suite = unittest.TestSuite()
+    tclasses = [ dictifyTestCase,
+                 MD5TestCase,
+                 UtilTestCase,
+               ]
+    for tclass in tclasses:
+        names = unittest.getTestCaseNames(tclass, 'test_')
+        suite.addTests(map(tclass, names))
     if not unittest.TextTestRunner().run(suite).wasSuccessful():
         sys.exit(1)