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)
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
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)
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()
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)
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()
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
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)