def setup(self): self.mock_repo = MagicMock() self.mock_repo.__getitem__.side_effect = LookupError( 'revision_or_commit_id', 'index', 'message') factory = Mock() factory.repo = Mock(return_value=self.mock_repo) self.remote_hg = hg.HgRemote(factory)
def test_raising_safe_exception_when_lookup_failed(self): factory = Mock() hg_remote = hg.HgRemote(factory) with patch('mercurial.patch.diff') as diff_mock: diff_mock.side_effect = LookupError( 'deadbeef', 'index', 'message') with pytest.raises(Exception) as exc_info: hg_remote.diff( wire={}, commit_id_1='deadbeef', commit_id_2='deadbee1', file_filter=None, opt_git=True, opt_ignorews=True, context=3) assert type(exc_info.value) == Exception assert exc_info.value._vcs_kind == 'lookup'
def revset_gitnode(repo, subset, x): '''``gitnode(hash)`` Select the changeset that originates in the given Git revision. The hash may be abbreviated: `gitnode(a5b)` selects the revision whose Git hash starts with `a5b`. Aborts if multiple changesets match the abbreviation. ''' args = revset.getargs(x, 1, 1, "gitnode takes one argument") rev = revset.getstring(args[0], "the argument to gitnode() must be a hash") git = repo.githandler node = repo.changelog.node def matches(r): gitnode = git.map_git_get(hex(node(r))) if gitnode is None: return False return gitnode.startswith(rev) result = revset.baseset(r for r in subset if matches(r)) if 0 <= len(result) < 2: return result raise LookupError(rev, git.map_file, _('ambiguous identifier'))