##// END OF EJS Templates
beaker: add patch for metadata re-use
beaker: add patch for metadata re-use

File last commit:

r432:92b33b73 default
r447:eb8a667d default
Show More
test_hgpatches.py
124 lines | 3.8 KiB | text/x-python | PythonLexer
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 # RhodeCode VCSServer provides access to different vcs backends via network.
core: udpate copyright string to 2018
r352 # Copyright (C) 2014-2018 RhodeCode GmbH
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 #
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import mock
import pytest
from vcsserver import hgcompat, hgpatches
LARGEFILES_CAPABILITY = 'largefiles=serve'
def test_patch_largefiles_capabilities_applies_patch(
patched_capabilities):
lfproto = hgcompat.largefiles.proto
hgpatches.patch_largefiles_capabilities()
hg: fixed code after version upgrade to 4.6.0 release
r432 assert lfproto._capabilities.func_name == '_dynamic_capabilities'
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
def test_dynamic_capabilities_uses_original_function_if_not_enabled(
hg: fixed code after version upgrade to 4.6.0 release
r432 stub_repo, stub_proto, stub_ui, stub_extensions, patched_capabilities,
orig_capabilities):
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 dynamic_capabilities = hgpatches._dynamic_capabilities_wrapper(
hgcompat.largefiles.proto, stub_extensions)
hg: fixed code after version upgrade to 4.6.0 release
r432 caps = dynamic_capabilities(orig_capabilities, stub_repo, stub_proto)
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
stub_extensions.assert_called_once_with(stub_ui)
assert LARGEFILES_CAPABILITY not in caps
def test_dynamic_capabilities_ignores_updated_capabilities(
hg: fixed code after version upgrade to 4.6.0 release
r432 stub_repo, stub_proto, stub_ui, stub_extensions, patched_capabilities,
orig_capabilities):
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 stub_extensions.return_value = [('largefiles', mock.Mock())]
dynamic_capabilities = hgpatches._dynamic_capabilities_wrapper(
hgcompat.largefiles.proto, stub_extensions)
# This happens when the extension is loaded for the first time, important
# to ensure that an updated function is correctly picked up.
hg: fixed code after version upgrade to 4.6.0 release
r432 hgcompat.largefiles.proto._capabilities = mock.Mock(
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 side_effect=Exception('Must not be called'))
hg: fixed code after version upgrade to 4.6.0 release
r432 dynamic_capabilities(orig_capabilities, stub_repo, stub_proto)
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
def test_dynamic_capabilities_uses_largefiles_if_enabled(
hg: fixed code after version upgrade to 4.6.0 release
r432 stub_repo, stub_proto, stub_ui, stub_extensions, patched_capabilities,
orig_capabilities):
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 stub_extensions.return_value = [('largefiles', mock.Mock())]
dynamic_capabilities = hgpatches._dynamic_capabilities_wrapper(
hgcompat.largefiles.proto, stub_extensions)
hg: fixed code after version upgrade to 4.6.0 release
r432 caps = dynamic_capabilities(orig_capabilities, stub_repo, stub_proto)
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
stub_extensions.assert_called_once_with(stub_ui)
assert LARGEFILES_CAPABILITY in caps
dependencies: bind sqlite with hgsubversion
r320 def test_hgsubversion_import():
from hgsubversion import svnrepo
assert svnrepo
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 @pytest.fixture
def patched_capabilities(request):
"""
Patch in `capabilitiesorig` and restore both capability functions.
"""
lfproto = hgcompat.largefiles.proto
hg: fixed code after version upgrade to 4.6.0 release
r432 orig_capabilities = lfproto._capabilities
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
@request.addfinalizer
def restore():
hg: fixed code after version upgrade to 4.6.0 release
r432 lfproto._capabilities = orig_capabilities
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
@pytest.fixture
def stub_repo(stub_ui):
repo = mock.Mock()
repo.ui = stub_ui
return repo
@pytest.fixture
def stub_proto(stub_ui):
proto = mock.Mock()
proto.ui = stub_ui
return proto
@pytest.fixture
hg: fixed code after version upgrade to 4.6.0 release
r432 def orig_capabilities():
from mercurial.wireprotov1server import wireprotocaps
def _capabilities(repo, proto):
return wireprotocaps
return _capabilities
@pytest.fixture
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 def stub_ui():
return hgcompat.ui.ui()
@pytest.fixture
def stub_extensions():
extensions = mock.Mock(return_value=tuple())
return extensions