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','')
def __init__(self, name, children=[]):
self.children = children
self.name = name
+ self.nocache = None
def __str__(self):
return self.name
def exists(self):
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):
"""
lines = string.split(expect, '\n')[:-1]
- lines = map(lambda l: '[E BSPAC]'+l, lines)
+ lines = map(lambda l: '[E BSPACN ]'+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")
+-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 BSPACN ]'+l, lines)
withtags = string.join(lines, '\n') + '\n'
return blat_o, expect, withtags
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)
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'')"
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'):
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."""
'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)