@mock.patch('tempfile.tempdir', new='tmp')
@mock.patch('os.close')
@mock.patch('os.path.exists')
@mock.patch('os.open')
@mock.patch('os.write')
@mock.patch('os.remove')
@mock.patch('pylink.jlock.psutil')
@mock.patch('pylink.jlock.open')
def test_jlock_acquire_old_pid(self, mock_open, mock_util, mock_rm, mock_wr, mock_op, mock_exists, mock_close):
    'Tests acquiring when the PID in the lockfile does not exist.\n\n        Args:\n          self (TestJLock): the ``TestJLock`` instance\n          mock_open (Mock): mocked built-in open method\n          mock_util (Mock): mocked ``psutil`` module\n          mock_rm (Mock): mocked os remove method\n          mock_wr (Mock): mocked os write method\n          mock_op (Mock): mocked os open method\n          mock_exists (Mock): mocked path exist method\n          mock_close (Mock): mocked os file close method\n\n        Returns:\n          ``None``\n        '
    fd = 1
    serial_no = 3735928559
    mock_open.side_effect = [mock.mock_open(read_data='42\n').return_value]
    mock_op.return_value = fd
    mock_util.pid_exists.return_value = False
    lock = jlock.JLock(serial_no)
    lock.release = mock.Mock()
    self.assertFalse(lock.acquired)
    self.assertTrue(lock.acquire())
    self.assertTrue(lock.acquired)
    mock_exists.assert_called_once()
    mock_open.assert_called_once()
    mock_util.pid_exists.assert_called_once_with(42)
    mock_rm.assert_called()
    mock_op.assert_called_once()
    mock_wr.assert_called_once()
Tests acquiring when the PID in the lockfile does not exist.

Args:
  self (TestJLock): the ``TestJLock`` instance
  mock_open (Mock): mocked built-in open method
  mock_util (Mock): mocked ``psutil`` module
  mock_rm (Mock): mocked os remove method
  mock_wr (Mock): mocked os write method
  mock_op (Mock): mocked os open method
  mock_exists (Mock): mocked path exist method
  mock_close (Mock): mocked os file close method

Returns:
  ``None``
@mock.patch('tempfile.tempdir', new='tmp')
@mock.patch('os.close')
@mock.patch('os.path.exists')
@mock.patch('os.open')
@mock.patch('os.write')
@mock.patch('os.remove')
@mock.patch('pylink.jlock.psutil')
@mock.patch('pylink.jlock.open')
def test_jlock_acquire_old_pid(self, mock_open, mock_util, mock_rm, mock_wr, mock_op, mock_exists, mock_close):
    'Tests acquiring when the PID in the lockfile does not exist.\n\n        Args:\n          self (TestJLock): the ``TestJLock`` instance\n          mock_open (Mock): mocked built-in open method\n          mock_util (Mock): mocked ``psutil`` module\n          mock_rm (Mock): mocked os remove method\n          mock_wr (Mock): mocked os write method\n          mock_op (Mock): mocked os open method\n          mock_exists (Mock): mocked path exist method\n          mock_close (Mock): mocked os file close method\n\n        Returns:\n          ``None``\n        '
    fd = 1
    serial_no = 3735928559
    mock_open.side_effect = [mock.mock_open(read_data='42\n').return_value]
    mock_op.return_value = fd
    mock_util.pid_exists.return_value = False
    lock = jlock.JLock(serial_no)
    lock.release = mock.Mock()
    self.assertFalse(lock.acquired)
    self.assertTrue(lock.acquire())
    self.assertTrue(lock.acquired)
    mock_exists.assert_called_once()
    mock_open.assert_called_once()
    mock_util.pid_exists.assert_called_once_with(42)
    mock_rm.assert_called()
    mock_op.assert_called_once()
    mock_wr.assert_called_once()