##// END OF EJS Templates
py3: remove safe_unicode in places where it no longer is needed because all strings (except bytes) already *are* unicode strings...
py3: remove safe_unicode in places where it no longer is needed because all strings (except bytes) already *are* unicode strings (The remaining safe_unicode calls are still needed and can't just be removed, generally because we in these cases still have to convert from bytes to unicode strings.)

File last commit:

r7914:ed78b4fb default
r8075:e3537310 default
Show More
test_vcs.py
88 lines | 2.7 KiB | text/x-python | PythonLexer
import os
import shutil
import pytest
from kallithea.lib.vcs import VCSError, get_backend, get_repo
from kallithea.lib.vcs.backends.hg import MercurialRepository
from kallithea.lib.vcs.utils import safe_str
from kallithea.tests.vcs.conf import TEST_GIT_REPO, TEST_HG_REPO, TESTS_TMP_PATH
class TestVCS(object):
"""
Tests for main module's methods.
"""
def test_get_backend(self):
hg = get_backend('hg')
assert hg == MercurialRepository
def test_alias_detect_hg(self):
alias = 'hg'
path = TEST_HG_REPO
backend = get_backend(alias)
repo = backend(safe_str(path))
assert 'hg' == repo.alias
def test_alias_detect_git(self):
alias = 'git'
path = TEST_GIT_REPO
backend = get_backend(alias)
repo = backend(safe_str(path))
assert 'git' == repo.alias
def test_wrong_alias(self):
alias = 'wrong_alias'
with pytest.raises(VCSError):
get_backend(alias)
def test_get_repo(self):
alias = 'hg'
path = TEST_HG_REPO
backend = get_backend(alias)
repo = backend(safe_str(path))
assert repo.__class__ == get_repo(safe_str(path), alias).__class__
assert repo.path == get_repo(safe_str(path), alias).path
def test_get_repo_autoalias_hg(self):
alias = 'hg'
path = TEST_HG_REPO
backend = get_backend(alias)
repo = backend(safe_str(path))
assert repo.__class__ == get_repo(safe_str(path)).__class__
assert repo.path == get_repo(safe_str(path)).path
def test_get_repo_autoalias_git(self):
alias = 'git'
path = TEST_GIT_REPO
backend = get_backend(alias)
repo = backend(safe_str(path))
assert repo.__class__ == get_repo(safe_str(path)).__class__
assert repo.path == get_repo(safe_str(path)).path
def test_get_repo_err(self):
blank_repo_path = os.path.join(TESTS_TMP_PATH, 'blank-error-repo')
if os.path.isdir(blank_repo_path):
shutil.rmtree(blank_repo_path)
os.mkdir(blank_repo_path)
with pytest.raises(VCSError):
get_repo(blank_repo_path)
with pytest.raises(VCSError):
get_repo(blank_repo_path + 'non_existing')
def test_get_repo_multialias(self):
multialias_repo_path = os.path.join(TESTS_TMP_PATH, 'hg-git-repo')
if os.path.isdir(multialias_repo_path):
shutil.rmtree(multialias_repo_path)
os.mkdir(multialias_repo_path)
os.mkdir(os.path.join(multialias_repo_path, '.git'))
os.mkdir(os.path.join(multialias_repo_path, '.hg'))
with pytest.raises(VCSError):
get_repo(multialias_repo_path)