Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #15
0
 def test_remove(self, unlink):
     unlink.return_value = True
     p = Pidfile('/var/pid')
     p.remove()
     unlink.assert_called_with(p.path)
Exemple #16
0
 def test_remove(self, unlink):
     unlink.return_value = True
     p = Pidfile('/var/pid')
     p.remove()
     unlink.assert_called_with(p.path)