예제 #1
0
    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
    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
    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')