Ejemplo n.º 1
0
 def test__iter(self):
     iterations = []
     for i in utils.Timer(timeout=2):
         iterations.append(i)
         time.sleep(1.1)
     self.assertEqual(2, len(iterations))
Ejemplo n.º 2
0
 def test_delta_time_sec(self):
     with utils.Timer() as timer:
         self.assertIsInstance(timer.delta_time_sec, float)
Ejemplo n.º 3
0
 def test__enter_with_timeout_no_exception(self):
     with utils.Timer(timeout=1, raise_exception=False):
         time.sleep(2)
Ejemplo n.º 4
0
 def test__enter_with_timeout_exception(self):
     msg = r'Timer timeout expired after 1 second\(s\).'
     with self.assertRaisesRegex(utils.TimerTimeout, msg):
         with utils.Timer(timeout=1):
             time.sleep(2)
Ejemplo n.º 5
0
 def test__enter_with_timeout(self):
     with utils.Timer(timeout=10) as timer:
         time.sleep(1)
     self.assertLess(timer.total_seconds(), 2)
Ejemplo n.º 6
0
 def test__getattr(self):
     with utils.Timer() as timer:
         time.sleep(1)
     self.assertLess(timer.total_seconds(), 2)
     self.assertEqual(1, timer.delta.seconds)
Ejemplo n.º 7
0
 def test__enter_with_timeout(self):
     with utils.Timer(timeout=10) as timer:
         time.sleep(1)
     self.assertEqual(1, round(timer.total_seconds()))