Beispiel #1
0
 def test_ignore_too_early(self, mocker):
     now = datetime.now(timezone.utc)
     wakeup = mocker.MagicMock(spec=autosuspend.Wakeup)
     wakeup.check.return_value = now
     assert autosuspend.execute_wakeups([wakeup], now,
                                        mocker.MagicMock()) is None
     assert autosuspend.execute_wakeups(
         [wakeup], now + timedelta(seconds=1), mocker.MagicMock()) is None
Beispiel #2
0
 def test_basic_return(self, mocker):
     wakeup = mocker.MagicMock(spec=autosuspend.Wakeup)
     now = datetime.now(timezone.utc)
     wakeup_time = now + timedelta(seconds=10)
     wakeup.check.return_value = wakeup_time
     assert autosuspend.execute_wakeups([wakeup], now,
                                        mocker.MagicMock()) == wakeup_time
Beispiel #3
0
    def test_ignore_temporary_errors(self, mocker):
        now = datetime.now(timezone.utc)

        wakeup = mocker.MagicMock(spec=autosuspend.Wakeup)
        wakeup.check.return_value = now + timedelta(seconds=20)
        wakeup_error = mocker.MagicMock(spec=autosuspend.Wakeup)
        wakeup_error.check.side_effect = autosuspend.TemporaryCheckError()
        wakeup_earlier = mocker.MagicMock(spec=autosuspend.Wakeup)
        wakeup_earlier.check.return_value = now + timedelta(seconds=10)
        assert autosuspend.execute_wakeups(
            [wakeup, wakeup_error, wakeup_earlier], now,
            mocker.MagicMock()) == now + timedelta(seconds=10)
Beispiel #4
0
 def test_soonest_taken(self, mocker):
     reference = datetime.now(timezone.utc)
     wakeup = mocker.MagicMock(spec=autosuspend.Wakeup)
     wakeup.check.return_value = reference + timedelta(seconds=20)
     earlier = reference + timedelta(seconds=10)
     wakeup_earlier = mocker.MagicMock(spec=autosuspend.Wakeup)
     wakeup_earlier.check.return_value = earlier
     in_between = reference + timedelta(seconds=15)
     wakeup_later = mocker.MagicMock(spec=autosuspend.Wakeup)
     wakeup_later.check.return_value = in_between
     assert autosuspend.execute_wakeups(
         [wakeup, wakeup_earlier, wakeup_later], reference,
         mocker.MagicMock()) == earlier
 def test_skips_none_outdated_and_continues(self, mocker, illegal) -> None:
     wakeup_none = mocker.MagicMock(spec=autosuspend.Wakeup)
     wakeup_none.check.return_value = illegal
     now = dateutil.parser.parse("20040705T090000Z")
     wake_up_at = now + timedelta(minutes=10)
     wakeup_real = mocker.MagicMock(spec=autosuspend.Wakeup)
     wakeup_real.check.return_value = wake_up_at
     assert (autosuspend.execute_wakeups(
         [wakeup_none, wakeup_real],
         now,
         mocker.MagicMock(),
     ) == wake_up_at)
     assert wakeup_none.check.called
Beispiel #6
0
 def test_all_none(self, mocker):
     wakeup = mocker.MagicMock(spec=autosuspend.Wakeup)
     wakeup.check.return_value = None
     assert autosuspend.execute_wakeups([wakeup], 0,
                                        mocker.MagicMock()) is None
Beispiel #7
0
 def test_no_wakeups(self, mocker):
     assert autosuspend.execute_wakeups([], 0, mocker.MagicMock()) is None
 def test_all_none(self, mocker) -> None:
     wakeup = mocker.MagicMock(spec=autosuspend.Wakeup)
     wakeup.check.return_value = None
     assert (autosuspend.execute_wakeups([wakeup], datetime.now(
         timezone.utc), mocker.MagicMock()) is None)
 def test_no_wakeups(self, mocker) -> None:
     assert (autosuspend.execute_wakeups([], datetime.now(timezone.utc),
                                         mocker.MagicMock()) is None)