added git/hg repos for testing

This commit is contained in:
laerus 2016-11-14 21:09:25 +02:00
parent 904d71b83e
commit b7a1ed4721
5 changed files with 39 additions and 11 deletions

View file

@ -1,5 +1,6 @@
import glob
import builtins
import glob
import os
import pytest
@ -15,6 +16,13 @@ from xonsh.platform import ON_WINDOWS
from tools import DummyShell, sp, DummyCommandsCache, DummyEnv, DummyHistory
@pytest.fixture
def source_path():
"""Get the xonsh source path."""
pwd = os.path.dirname(__file__)
return os.path.dirname(pwd)
@pytest.fixture
def xonsh_execer(monkeypatch):
"""Initiate the Execer with a mocked nop `load_builtins`"""

1
tests/git-test-repo Submodule

@ -0,0 +1 @@
Subproject commit 8f5e6cab3efbe2341d7e27efd5b739efed3ae93f

Binary file not shown.

View file

@ -0,0 +1,5 @@
dotencode
fncache
generaldelta
revlogv1
store

View file

@ -1,3 +1,4 @@
import os
import subprocess as sp
from unittest.mock import Mock
@ -5,9 +6,9 @@ import pytest
from xonsh.environ import Env
from xonsh.prompt.base import PromptFormatter
from xonsh.prompt.vc import get_git_branch
from xonsh.prompt import vc
from tools import skip_if_py34
from tools import skip_if_py34, DummyEnv
@pytest.fixture
@ -114,13 +115,26 @@ def test_promptformatter_clears_cache(formatter):
assert spam.call_count == 2
@pytest.mark.parametrize('repo', ['hg', 'git'])
def test_test_repos(source_path, repo):
test_repo = os.path.join(source_path, 'tests', '{}-test-repo'.format(repo))
assert os.path.isdir(test_repo)
assert os.path.isdir(os.path.join(test_repo, '.{}'.format(repo)))
@skip_if_py34
@pytest.mark.parametrize('cmd', ['git'])
def test_vc_get_branch(cmd, xonsh_builtins):
try:
out = sp.run([cmd, 'status'], stdout=sp.PIPE, check=True).stdout
except FileNotFoundError:
pytest.skip('cannot find {} executable'.format(cmd))
exp = out.decode().splitlines()[0].split()[-1]
obs = get_git_branch()
@pytest.mark.parametrize('cmd, exp', [
('git', 'master'),
('hg', 'default'),
])
def test_vc_get_branch(cmd, exp, source_path, xonsh_builtins):
test_repo = '{}-test-repo'.format(cmd)
test_repo_path = os.path.join(source_path, 'tests', test_repo)
os.chdir(test_repo_path)
xonsh_builtins.__xonsh_env__ = Env(VC_BRANCH_TIMEOUT=1)
# get corresponding function from vc module
if cmd == 'hg':
obs = vc.get_hg_branch()
else:
obs = vc.get_git_branch()
assert obs == exp