##// END OF EJS Templates
chore(deps): bumped zope.interface
chore(deps): bumped zope.interface

File last commit:

r1126:f96985cd python3
r1226:91594013 default
Show More
test_hgpatches.py
119 lines | 3.7 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.
source-code: updated copyrights to 2023
r1126 # Copyright (C) 2014-2023 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
python3: code change for py3 support...
r1048 LARGEFILES_CAPABILITY = b'largefiles=serve'
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
def test_patch_largefiles_capabilities_applies_patch(
patched_capabilities):
lfproto = hgcompat.largefiles.proto
hgpatches.patch_largefiles_capabilities()
py3: 2to3 run
r1044 assert lfproto._capabilities.__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
@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