def test_every_steps(self):
    timer = basic_session_run_hooks._SecondOrStepTimer(every_steps=3)
    self.assertTrue(timer.should_trigger_for_step(1))

    timer.update_last_triggered_step(1)
    self.assertFalse(timer.should_trigger_for_step(1))
    self.assertFalse(timer.should_trigger_for_step(2))
    self.assertFalse(timer.should_trigger_for_step(3))
    self.assertTrue(timer.should_trigger_for_step(4))
    def test_every_steps(self):
        timer = basic_session_run_hooks._SecondOrStepTimer(every_steps=3)
        self.assertTrue(timer.should_trigger_for_step(1))

        timer.update_last_triggered_step(1)
        self.assertFalse(timer.should_trigger_for_step(1))
        self.assertFalse(timer.should_trigger_for_step(2))
        self.assertFalse(timer.should_trigger_for_step(3))
        self.assertTrue(timer.should_trigger_for_step(4))
    def test_update_last_triggered_step(self):
        timer = basic_session_run_hooks._SecondOrStepTimer(every_steps=1)

        elapsed_secs, elapsed_steps = timer.update_last_triggered_step(1)
        self.assertEqual(None, elapsed_secs)
        self.assertEqual(None, elapsed_steps)

        elapsed_secs, elapsed_steps = timer.update_last_triggered_step(5)
        self.assertLess(0, elapsed_secs)
        self.assertEqual(4, elapsed_steps)

        elapsed_secs, elapsed_steps = timer.update_last_triggered_step(7)
        self.assertLess(0, elapsed_secs)
        self.assertEqual(2, elapsed_steps)
  def test_update_last_triggered_step(self):
    timer = basic_session_run_hooks._SecondOrStepTimer(every_steps=1)

    elapsed_secs, elapsed_steps = timer.update_last_triggered_step(1)
    self.assertEqual(None, elapsed_secs)
    self.assertEqual(None, elapsed_steps)

    elapsed_secs, elapsed_steps = timer.update_last_triggered_step(5)
    self.assertLess(0, elapsed_secs)
    self.assertEqual(4, elapsed_steps)

    elapsed_secs, elapsed_steps = timer.update_last_triggered_step(7)
    self.assertLess(0, elapsed_secs)
    self.assertEqual(2, elapsed_steps)
 def test_raise_in_none_secs_and_steps(self):
     with self.assertRaises(ValueError):
         basic_session_run_hooks._SecondOrStepTimer()
 def test_raise_in_both_secs_and_steps(self):
     with self.assertRaises(ValueError):
         basic_session_run_hooks._SecondOrStepTimer(every_secs=2.0,
                                                    every_steps=10)
 def test_raise_in_none_secs_and_steps(self):
   with self.assertRaises(ValueError):
     basic_session_run_hooks._SecondOrStepTimer()
 def test_raise_in_both_secs_and_steps(self):
   with self.assertRaises(ValueError):
     basic_session_run_hooks._SecondOrStepTimer(every_secs=2.0, every_steps=10)