Home | History | Annotate | Download | only in cros_utils
      1 # Copyright 2012 Google Inc. All Rights Reserved.
      2 """Tests for time_line.py."""
      3 
      4 from __future__ import print_function
      5 
      6 __author__ = 'yunlian (at] google.com (Yunlian Jiang)'
      7 
      8 import time
      9 import unittest
     10 
     11 import timeline
     12 
     13 
     14 class TimeLineTest(unittest.TestCase):
     15   """Tests for the Timeline class."""
     16 
     17   def testRecord(self):
     18     tl = timeline.Timeline()
     19     tl.Record('A')
     20     t = time.time()
     21     t1 = tl.events[0].timestamp
     22     self.assertEqual(int(t1 - t), 0)
     23     self.assertRaises(AssertionError, tl.Record, 'A')
     24 
     25   def testGetEvents(self):
     26     tl = timeline.Timeline()
     27     tl.Record('A')
     28     e = tl.GetEvents()
     29     self.assertEqual(e, ['A'])
     30     tl.Record('B')
     31     e = tl.GetEvents()
     32     self.assertEqual(e, ['A', 'B'])
     33 
     34   def testGetEventTime(self):
     35     tl = timeline.Timeline()
     36     tl.Record('A')
     37     t = time.time()
     38     t1 = tl.GetEventTime('A')
     39     self.assertEqual(int(t1 - t), 0)
     40     self.assertRaises(IndexError, tl.GetEventTime, 'B')
     41 
     42   def testGetLastEventTime(self):
     43     tl = timeline.Timeline()
     44     self.assertRaises(IndexError, tl.GetLastEventTime)
     45     tl.Record('A')
     46     t = time.time()
     47     t1 = tl.GetLastEventTime()
     48     self.assertEqual(int(t1 - t), 0)
     49     time.sleep(2)
     50     tl.Record('B')
     51     t = time.time()
     52     t1 = tl.GetLastEventTime()
     53     self.assertEqual(int(t1 - t), 0)
     54 
     55 
     56 if __name__ == '__main__':
     57   unittest.main()
     58