Merge branch 'vc_tests' into vcfix

This commit is contained in:
laerus 2016-11-16 15:22:53 +02:00
commit cf2e9f7ca5
8 changed files with 51 additions and 5 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,9 +1,14 @@
import os
import subprocess as sp
from unittest.mock import Mock
import pytest
from xonsh.environ import Env
from xonsh.prompt.base import PromptFormatter
from xonsh.prompt import vc
from tools import skip_if_py34, DummyEnv
@pytest.fixture
@ -76,7 +81,9 @@ def test_format_prompt_with_invalid_func(formatter, xonsh_builtins):
assert isinstance(formatter(p), str)
def test_format_prompt_with_func_that_raises(formatter, capsys, xonsh_builtins):
def test_format_prompt_with_func_that_raises(formatter,
capsys,
xonsh_builtins):
xonsh_builtins.__xonsh_env__ = Env()
template = 'tt {zerodiv} tt'
exp = 'tt (ERROR:zerodiv) tt'
@ -106,3 +113,28 @@ def test_promptformatter_clears_cache(formatter):
formatter(template, fields)
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, 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

View file

@ -1,9 +1,9 @@
import pytest
try:
import prompt_toolkit
import prompt_toolkit # NOQA
except ImportError:
pytest.skip(msg='prompt_toolkit is not available')
pytest.mark.skip(msg='prompt_toolkit is not available')
from xonsh.ptk.history import PromptToolkitHistory

View file

@ -18,7 +18,7 @@ from xonsh.prompt.cwd import (
)
from xonsh.prompt.job import _current_job
from xonsh.prompt.env import (env_name, vte_new_tab_cwd)
from xonsh.prompt.vc_branch import (
from xonsh.prompt.vc import (
current_branch, branch_color, branch_bg_color
)
from xonsh.prompt.gitstatus import gitstatus_prompt