コード例 #1
0
    def test_without_cooldown_time(self):
        """If no cooldown_time is specified, there's no sleep, and exactly the
        same time is returned."""

        goal_seconds = 0.01
        body = SimpleLoop(3)

        no_cooldown_loop = LoopTuner(body, goal_seconds, cooldown_time=None)
        old_time = time.time()

        new_time = no_cooldown_loop._coolDown(old_time)

        self.assertEqual(new_time, old_time)
コード例 #2
0
    def test_cooldown_bedtime(self):
        """A private _coolDown method on LoopTuner sleeps for cooldown_time,
        and returns time after sleep is done."""

        goal_seconds = 0.01
        body = SimpleLoop(3)

        cooldown_loop = LoopTuner(body, goal_seconds, cooldown_time=0.2)
        old_time = time.time()

        new_time = cooldown_loop._coolDown(old_time)

        self.assertTrue(new_time > old_time)
コード例 #3
0
    def test_without_cooldown_time(self):
        """If no cooldown_time is specified, there's no sleep, and exactly the
        same time is returned."""

        goal_seconds = 0.01
        body = SimpleLoop(3)

        no_cooldown_loop = LoopTuner(body, goal_seconds, cooldown_time=None)
        old_time = time.time()

        new_time = no_cooldown_loop._coolDown(old_time)

        self.assertEqual(new_time, old_time)
コード例 #4
0
    def test_cooldown_bedtime(self):
        """A private _coolDown method on LoopTuner sleeps for cooldown_time,
        and returns time after sleep is done."""

        goal_seconds = 0.01
        body = SimpleLoop(3)

        cooldown_loop = LoopTuner(body, goal_seconds, cooldown_time=0.2)
        old_time = time.time()

        new_time = cooldown_loop._coolDown(old_time)

        self.assertTrue(new_time > old_time)
コード例 #5
0
    def test_cleanup_exception_on_success(self):
        """Main task succeeded but cleanup failed.

        Exception from cleanup raised.
        """
        loop = FailingLoop(fail_cleanup=True)
        tuner = LoopTuner(loop, 5, log=MagicMock())
        self.assertRaises(CleanupException, tuner.run)
        tuner.log.exception.assert_has_no_calls()
コード例 #6
0
    def test_cleanup_exception_on_failure(self):
        """Main task failed and cleanup also failed.

        Exception from cleanup is logged.
        Original exception from main task is raised.
        """
        loop = FailingLoop(fail_main=True, fail_cleanup=True)
        tuner = LoopTuner(loop, 5, log=MagicMock())
        self.assertRaises(MainException, tuner.run)
        tuner.log.exception.assert_called_once_with(
            'Unhandled exception in cleanUp')
コード例 #7
0
 def __init__(self, *argl, **argv):
     self.clock = 0
     LoopTuner.__init__(self, *argl, **argv)
コード例 #8
0
 def __init__(self, *argl, **argv):
     self.clock = 0
     LoopTuner.__init__(self, *argl, **argv)