def test_bounce_lock(self): import fcntl lock_name = 'the_internet' lock_file = '/var/lock/%s.lock' % lock_name fake_fd = mock.mock_open() with mock.patch('builtins.open', fake_fd, autospec=None) as open_patch: with mock.patch('fcntl.lockf', autospec=None) as lockf_patch: with mock.patch('os.remove', autospec=None) as remove_patch: with bounce_lib.bounce_lock(lock_name): pass open_patch.assert_called_once_with(lock_file, 'w') lockf_patch.assert_called_once_with(fake_fd.return_value, fcntl.LOCK_EX | fcntl.LOCK_NB) fake_fd.return_value.__exit__.assert_called_once_with(None, None, None) remove_patch.assert_called_once_with(lock_file)
def test_bounce_lock(self): import fcntl lock_name = "the_internet" lock_file = "/var/lock/%s.lock" % lock_name fake_fd = mock.mock_open() with mock.patch("builtins.open", fake_fd, autospec=None) as open_patch: with mock.patch("fcntl.lockf", autospec=None) as lockf_patch: with mock.patch("os.remove", autospec=None) as remove_patch: with bounce_lib.bounce_lock(lock_name): pass open_patch.assert_called_once_with(lock_file, "w") lockf_patch.assert_called_once_with(fake_fd.return_value, fcntl.LOCK_EX | fcntl.LOCK_NB) fake_fd.return_value.__exit__.assert_called_once_with(None, None, None) remove_patch.assert_called_once_with(lock_file)
def test_bounce_lock(self): import fcntl lock_name = 'the_internet' lock_file = '/var/lock/%s.lock' % lock_name fake_fd = mock.MagicMock(spec=file) with contextlib.nested( mock.patch('paasta_tools.bounce_lib.open', create=True, return_value=fake_fd), mock.patch('fcntl.lockf'), mock.patch('os.remove')) as (open_patch, lockf_patch, remove_patch): with bounce_lib.bounce_lock(lock_name): pass open_patch.assert_called_once_with(lock_file, 'w') lockf_patch.assert_called_once_with(fake_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) fake_fd.close.assert_called_once_with() remove_patch.assert_called_once_with(lock_file)
def test_bounce_lock(self): import fcntl lock_name = 'the_internet' lock_file = '/var/lock/%s.lock' % lock_name fake_fd = mock.MagicMock(spec=file, autospec=None) with contextlib.nested( mock.patch('paasta_tools.bounce_lib.open', create=True, return_value=fake_fd, autospec=None), mock.patch('fcntl.lockf', autospec=None), mock.patch('os.remove', autospec=None) ) as ( open_patch, lockf_patch, remove_patch ): with bounce_lib.bounce_lock(lock_name): pass open_patch.assert_called_once_with(lock_file, 'w') lockf_patch.assert_called_once_with(fake_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) fake_fd.close.assert_called_once_with() remove_patch.assert_called_once_with(lock_file)