Exemplo n.º 1
0
 def test_remove_EACCES(self, unlink):
     exc = OSError()
     exc.errno = errno.EACCES
     unlink.side_effect = exc
     p = Pidfile('/var/pid')
     p.remove()
     unlink.assert_called_with(p.path)
Exemplo n.º 2
0
 def test_remove_EACCES(self, unlink):
     exc = OSError()
     exc.errno = errno.EACCES
     unlink.side_effect = exc
     p = Pidfile('/var/pid')
     p.remove()
     unlink.assert_called_with(p.path)
Exemplo n.º 3
0
 def test_remove_ENOENT(self, unlink):
     exc = OSError()
     exc.errno = errno.ENOENT
     unlink.side_effect = exc
     p = Pidfile("/var/pid")
     p.remove()
     unlink.assert_called_with(p.path)
Exemplo n.º 4
0
 def test_remove_OSError(self, unlink):
     exc = OSError()
     exc.errno = errno.EAGAIN
     unlink.side_effect = exc
     p = Pidfile('/var/pid')
     with pytest.raises(OSError):
         p.remove()
     unlink.assert_called_with(p.path)
Exemplo n.º 5
0
 def test_remove_OSError(self, unlink):
     exc = OSError()
     exc.errno = errno.EAGAIN
     unlink.side_effect = exc
     p = Pidfile('/var/pid')
     with self.assertRaises(OSError):
         p.remove()
     unlink.assert_called_with(p.path)
Exemplo n.º 6
0
    def test_remove_if_stale_no_pidfile(self):
        p = Pidfile('/var/pid')
        p.read_pid = Mock()
        p.read_pid.return_value = None
        p.remove = Mock()

        assert p.remove_if_stale()
        p.remove.assert_called_with()
Exemplo n.º 7
0
    def test_remove_if_stale_no_pidfile(self):
        p = Pidfile('/var/pid')
        p.read_pid = Mock()
        p.read_pid.return_value = None
        p.remove = Mock()

        self.assertTrue(p.remove_if_stale())
        p.remove.assert_called_with()
Exemplo n.º 8
0
    def test_remove_if_stale_broken_pid(self):
        with mock.stdouts():
            p = Pidfile('/var/pid')
            p.read_pid = Mock()
            p.read_pid.side_effect = ValueError()
            p.remove = Mock()

            assert p.remove_if_stale()
            p.remove.assert_called_with()
Exemplo n.º 9
0
    def test_context(self):
        p = Pidfile('/var/pid')
        p.write_pid = Mock()
        p.remove = Mock()

        with p as _p:
            assert _p is p
        p.write_pid.assert_called_with()
        p.remove.assert_called_with()
Exemplo n.º 10
0
    def test_remove_if_stale_broken_pid(self):
        with override_stdouts():
            p = Pidfile('/var/pid')
            p.read_pid = Mock()
            p.read_pid.side_effect = ValueError()
            p.remove = Mock()

            self.assertTrue(p.remove_if_stale())
            p.remove.assert_called_with()
Exemplo n.º 11
0
    def test_context(self):
        p = Pidfile('/var/pid')
        p.write_pid = Mock()
        p.remove = Mock()

        with p as _p:
            self.assertIs(_p, p)
        p.write_pid.assert_called_with()
        p.remove.assert_called_with()
Exemplo n.º 12
0
 def test_remove_if_stale_process_dead(self, kill):
     with mock.stdouts():
         p = Pidfile('/var/pid')
         p.read_pid = Mock()
         p.read_pid.return_value = 1816
         p.remove = Mock()
         exc = OSError()
         exc.errno = errno.ESRCH
         kill.side_effect = exc
         assert p.remove_if_stale()
         kill.assert_called_with(1816, 0)
         p.remove.assert_called_with()
Exemplo n.º 13
0
 def test_remove_if_stale_process_dead(self, kill):
     with override_stdouts():
         p = Pidfile('/var/pid')
         p.read_pid = Mock()
         p.read_pid.return_value = 1816
         p.remove = Mock()
         exc = OSError()
         exc.errno = errno.ESRCH
         kill.side_effect = exc
         self.assertTrue(p.remove_if_stale())
         kill.assert_called_with(1816, 0)
         p.remove.assert_called_with()
Exemplo n.º 14
0
 def test_remove_if_stale_unprivileged_user(self, kill):
     with mock.stdouts():
         p = Pidfile('/var/pid')
         p.read_pid = Mock()
         p.read_pid.return_value = 1817
         p.remove = Mock()
         exc = OSError()
         exc.errno = errno.EPERM
         kill.side_effect = exc
         assert p.remove_if_stale()
         kill.assert_called_with(1817, 0)
         p.remove.assert_called_with()
Exemplo n.º 15
0
 def test_remove(self, unlink):
     unlink.return_value = True
     p = Pidfile('/var/pid')
     p.remove()
     unlink.assert_called_with(p.path)
Exemplo n.º 16
0
 def test_remove(self, unlink):
     unlink.return_value = True
     p = Pidfile('/var/pid')
     p.remove()
     unlink.assert_called_with(p.path)