コード例 #1
0
ファイル: test_daemon.py プロジェクト: cecedille1/Sett
    def test_status_stopped(self):
        d = Daemon(['ls'], pid_file='/run/pid')

        mocks = mock.MagicMock()
        mocks.open.side_effect = IOError('No such file or directory')

        with mock.patch.multiple('sett.daemon', os=mocks.os, open=mocks.open):
            status = d.status()

        mocks.assert_has_calls([
            mock.call.open('/run/pid', 'r'),
        ])
        self.assertEqual(status, 'Not running')
コード例 #2
0
ファイル: test_daemon.py プロジェクト: cecedille1/Sett
    def test_status_running(self):
        d = Daemon(['ls'], pid_file='/run/pid')

        mocks = mock.MagicMock()
        opened = mocks.open.return_value
        opened.__enter__ = opened.__exit__ = mock.Mock(name='catch', return_value=opened)
        mocks.open.return_value.read.return_value = '1109\n'

        with mock.patch.multiple('sett.daemon', os=mocks.os, open=mocks.open):
            status = d.status()

        mocks.assert_has_calls([
            mock.call.open('/run/pid', 'r'),
            mock.call.open().read(),
            mock.call.os.kill(1109, 0),
        ])
        self.assertEqual(status, 'Running with pid 1109')
コード例 #3
0
ファイル: test_daemon.py プロジェクト: cecedille1/Sett
    def test_status_stale(self):
        d = Daemon(['ls'], pid_file='/run/pid')

        mocks = mock.MagicMock()
        opened = mocks.open.return_value
        opened.__enter__ = opened.__exit__ = mock.Mock(name='catch', return_value=opened)
        mocks.open.return_value.read.return_value = '1109\n'
        mocks.os.kill.side_effect = OSError('oh snap')

        with mock.patch.multiple('sett.daemon', os=mocks.os, open=mocks.open):
            status = d.status()

        mocks.assert_has_calls([
            mock.call.open('/run/pid', 'r'),
            mock.call.open().read(),
            mock.call.os.kill(1109, 0),
        ])
        self.assertEqual(status, 'Not running, stale PID file')