def testInstance(self): t = Timer() # Mock the timestamp to some fixed value t._time = self.mock.Mock() t._time.return_value = 100.0 # Start the timer. Elapsed should remain 0.0 before and after start self.assertEqual(t.elapsed, 0.0) t.start() self.assertEqual(t.elapsed, 0.0) # Make sure running time is 5s t._time.return_value = 105.0 self.assertEqual(t.elapsed, 5.0) # Stop and make sure elapsed time is 5s as well t.stop() self.assertEqual(t.elapsed, 5.0) # Bump time by 5s, but make sure elapsed stays the same t._time.return_value = 110.0 self.assertEqual(t.elapsed, 5.0) # Re-stop the timer, which should update stop_time and elapsed to 10s t.stop() self.assertEqual(t.elapsed, 10.0)