@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_os_error(self, mock_open, mock_util, mock_rm, mock_wr, mock_op, mock_exists, mock_close):
    'Tests trying to acquire the lock but generating an os-level error.\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        '
    serial_no = 3735928559
    mock_exists.side_effect = [False, False]
    mock_op.side_effect = [OSError((~ errno.EEXIST), 'Message')]
    lock = jlock.JLock(serial_no)
    lock.release = mock.Mock()
    self.assertFalse(lock.acquired)
    with self.assertRaisesRegexp(OSError, 'Message'):
        lock.acquire()
    self.assertFalse(lock.acquired)
    mock_open.assert_not_called()
    mock_util.pid_exists.assert_not_called()
    mock_op.assert_called_once()
    mock_rm.assert_not_called()
    mock_wr.assert_not_called()
Tests trying to acquire the lock but generating an os-level error.

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_os_error(self, mock_open, mock_util, mock_rm, mock_wr, mock_op, mock_exists, mock_close):
    'Tests trying to acquire the lock but generating an os-level error.\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        '
    serial_no = 3735928559
    mock_exists.side_effect = [False, False]
    mock_op.side_effect = [OSError((~ errno.EEXIST), 'Message')]
    lock = jlock.JLock(serial_no)
    lock.release = mock.Mock()
    self.assertFalse(lock.acquired)
    with self.assertRaisesRegexp(OSError, 'Message'):
        lock.acquire()
    self.assertFalse(lock.acquired)
    mock_open.assert_not_called()
    mock_util.pid_exists.assert_not_called()
    mock_op.assert_called_once()
    mock_rm.assert_not_called()
    mock_wr.assert_not_called()