Exemplo n.º 1
0
 def test_date(self, mocker):
     mock = mocker.patch('subprocess.check_call')
     dt = datetime.fromtimestamp(1525270801, timezone(timedelta(hours=4)))
     autosuspend.notify_suspend('echo {timestamp:.0f} {iso}', 'not this',
                                dt)
     mock.assert_called_once_with(
         'echo 1525270801 2018-05-02T18:20:01+04:00', shell=True)
Exemplo n.º 2
0
 def test_ignore_execution_errors(self, mocker, caplog) -> None:
     mock = mocker.patch("subprocess.check_call")
     mock.side_effect = subprocess.CalledProcessError(2, "cmd")
     dt = datetime.fromtimestamp(1525270801, timezone(timedelta(hours=4)))
     with caplog.at_level(logging.WARNING):
         autosuspend.notify_suspend("wakeup", "nowakeup", dt)
         assert "Unable to execute" in caplog.text
         assert mock.called
Exemplo n.º 3
0
 def test_ignore_execution_errors(self, mocker):
     mock = mocker.patch('subprocess.check_call')
     mock.side_effect = subprocess.CalledProcessError(2, 'cmd')
     dt = datetime.fromtimestamp(1525270801, timezone(timedelta(hours=4)))
     autosuspend.notify_suspend(None, 'not this', dt)
Exemplo n.º 4
0
 def test_no_date_no_command(self, mocker):
     mock = mocker.patch('subprocess.check_call')
     autosuspend.notify_suspend('echo {timestamp:.0f} {iso}', None, None)
     mock.assert_not_called()
Exemplo n.º 5
0
 def test_no_date(self, mocker):
     mock = mocker.patch('subprocess.check_call')
     autosuspend.notify_suspend('echo {timestamp:.0f} {iso}',
                                'echo nothing', None)
     mock.assert_called_once_with('echo nothing', shell=True)
Exemplo n.º 6
0
 def test_date_no_command(self, mocker):
     mock = mocker.patch('subprocess.check_call')
     dt = datetime.fromtimestamp(1525270801, timezone(timedelta(hours=4)))
     autosuspend.notify_suspend(None, 'not this', dt)
     mock.assert_not_called()
Exemplo n.º 7
0
 def test_info_no_command(self, caplog) -> None:
     with caplog.at_level(logging.INFO):
         autosuspend.notify_suspend(None, None, datetime.now())
         assert "suitable" in caplog.text
Exemplo n.º 8
0
 def test_no_date(self, mocker) -> None:
     mock = mocker.patch("subprocess.check_call")
     autosuspend.notify_suspend("echo {timestamp:.0f} {iso}",
                                "echo nothing", None)
     mock.assert_called_once_with("echo nothing", shell=True)