0c652ab25a2eb02ceaeb87fb51aad7daedd97ef6
[scons.git] / src / engine / SCons / Sig / TimeStampTests.py
1 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
2
3 import sys
4 import unittest
5
6 from SCons.Sig.TimeStamp import current, collect, signature, to_string, from_string
7
8
9
10 class my_obj:
11     """A dummy object class that satisfies the interface
12     requirements of the TimeStamp class.
13     """
14
15     def __init__(self, value = 0):
16         self.value = value
17
18     def get_signature(self):
19         return self.value
20
21     def get_timestamp(self):
22         return self.value
23
24
25 class TimeStampTestCase(unittest.TestCase):
26
27     def test_current(self):
28         """Test deciding if an object is up-to-date
29
30         Simple comparison of different timestamp values.
31         """
32         o1 = my_obj(value = 111)
33         assert current(o1, 110)
34         assert current(o1, 111)
35         assert not current(o1, 112)
36
37     def test_collect(self):
38         """Test collecting a list of signatures into a new signature value
39         into a new timestamp value.
40         """
41         
42         assert 111 == collect((111,))
43         assert 222 == collect((111, 222))
44         assert 333 == collect((333, 222, 111))
45
46     def test_signature(self):
47         """Test generating a signature"""
48         o1 = my_obj(value = 111)
49         assert 111 == signature(o1)
50
51     def test_to_string(self):
52         assert '111' == to_string(111)
53
54     def test_from_string(self):
55         assert 111 == from_string('111')
56
57
58 if __name__ == "__main__":
59     suite = unittest.makeSuite(TimeStampTestCase, 'test_')
60     if not unittest.TextTestRunner().run(suite).wasSuccessful():
61         sys.exit(1)