##// END OF EJS Templates
deps: bumped test requirements
deps: bumped test requirements

File last commit:

r1327:278da2b3 default
r1328:942ebeb1 default
Show More
test_hg.py
112 lines | 4.2 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: updated copyrights to 2024
r1327 # Copyright (C) 2014-2024 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 inspect
import sys
import traceback
import pytest
from mercurial.error import LookupError
core: move git/svn/hg into submodule
r1043 from mock import Mock, patch
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
core: move git/svn/hg into submodule
r1043 from vcsserver import exceptions, hgcompat
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 from vcsserver.remote import hg_remote
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
lint: auto-fixes
r1152 class TestDiff:
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 def test_raising_safe_exception_when_lookup_failed(self):
caches: new cache implementation for remote functions
r739
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 factory = Mock()
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 hg_remote_instance = hg_remote.HgRemote(factory)
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 with patch('mercurial.patch.diff') as diff_mock:
python3: code change for py3 support...
r1048 diff_mock.side_effect = LookupError(b'deadbeef', b'index', b'message')
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 with pytest.raises(Exception) as exc_info:
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 hg_remote_instance.diff(
vcs: turned some of the commands to be context_uid based. Those selected...
r746 wire={}, commit_id_1='deadbeef', commit_id_2='deadbee1',
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 file_filter=None, opt_git=True, opt_ignorews=True,
context=3)
assert type(exc_info.value) == Exception
assert exc_info.value._vcs_kind == 'lookup'
lint: auto-fixes
r1152 class TestReraiseSafeExceptions:
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 original_traceback = None
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 def test_method_decorated_with_reraise_safe_exceptions(self):
factory = Mock()
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 hg_remote_instance = hg_remote.HgRemote(factory)
methods = inspect.getmembers(hg_remote_instance, predicate=inspect.ismethod)
decorator = hg_remote.reraise_safe_exceptions(None)
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 for method_name, method in methods:
caches: small naming refactor to fix tests.
r964 if not method_name.startswith('_') and method_name not in ['vcsserver_invalidate_cache']:
py3: 2to3 run
r1044 assert method.__func__.__code__ == decorator.__code__
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
@pytest.mark.parametrize('side_effect, expected_type', [
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 (hgcompat.Abort(b'failed-abort'), 'abort'),
(hgcompat.InterventionRequired(b'intervention-required'), 'abort'),
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 (hgcompat.RepoLookupError(), 'lookup'),
python3: code change for py3 support...
r1048 (hgcompat.LookupError(b'deadbeef', b'index', b'message'), 'lookup'),
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 (hgcompat.RepoError(), 'error'),
(hgcompat.RequirementError(), 'requirement'),
])
def test_safe_exceptions_reraised(self, side_effect, expected_type):
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 @hg_remote.reraise_safe_exceptions
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 def fake_method():
raise side_effect
with pytest.raises(Exception) as exc_info:
fake_method()
assert type(exc_info.value) == Exception
assert exc_info.value._vcs_kind == expected_type
def test_keeps_original_traceback(self):
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145
@hg_remote.reraise_safe_exceptions
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 def fake_method():
try:
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 raise hgcompat.Abort(b'test-abort')
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 except:
python3: code change for py3 support...
r1048 self.original_traceback = traceback.format_tb(sys.exc_info()[2])
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 raise
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 new_traceback = None
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 try:
fake_method()
except Exception:
new_traceback = traceback.format_tb(sys.exc_info()[2])
new_traceback_tail = new_traceback[-len(self.original_traceback):]
assert new_traceback_tail == self.original_traceback
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 def test_maps_unknown_exceptions_to_unhandled(self):
@hg_remote.reraise_safe_exceptions
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 def stub_method():
raise ValueError('stub')
with pytest.raises(Exception) as exc_info:
stub_method()
assert exc_info.value._vcs_kind == 'unhandled'
def test_does_not_map_known_exceptions(self):
core: renamed remote packages to prevent conflicts with builtin libraries like svn core library called same as svn remote
r1145 @hg_remote.reraise_safe_exceptions
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 def stub_method():
exceptions: use new wrapper that store the org exception inside the newly generated exceptions....
r490 raise exceptions.LookupException()('stub')
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
with pytest.raises(Exception) as exc_info:
stub_method()
assert exc_info.value._vcs_kind == 'lookup'