Fix appveyor and windows. Resolves #293

This commit is contained in:
Anthony Sottile
2015-11-23 20:10:08 -08:00
parent 1cdbe38b5f
commit 248930f6dc
7 changed files with 60 additions and 34 deletions

View File

@@ -90,7 +90,9 @@ def test_install_hooks_directory_not_present(tempdir_factory):
@xfailif_no_symlink
def test_install_hooks_dead_symlink(tempdir_factory):
def test_install_hooks_dead_symlink(
tempdir_factory,
): # pragma: no cover (non-windows)
path = git_dir(tempdir_factory)
os.symlink('/fake/baz', os.path.join(path, '.git', 'hooks', 'pre-commit'))
runner = Runner(path)
@@ -175,6 +177,14 @@ def test_install_idempotent(tempdir_factory):
assert NORMAL_PRE_COMMIT_RUN.match(output)
def _path_without_us():
# Choose a path which *probably* doesn't include us
return os.pathsep.join([
x for x in os.environ['PATH'].split(os.pathsep)
if x.lower() != os.path.dirname(sys.executable).lower()
])
def test_environment_not_sourced(tempdir_factory):
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
with cwd(path):
@@ -193,7 +203,7 @@ def test_environment_not_sourced(tempdir_factory):
)
ret, stdout, stderr = cmd_output(
'git', 'commit', '--allow-empty', '-m', 'foo',
env={'HOME': homedir},
env={'HOME': homedir, 'PATH': _path_without_us()},
retcode=None,
)
assert ret == 1
@@ -422,6 +432,7 @@ def test_installed_from_venv(tempdir_factory):
tempdir_factory,
env_base={
'HOME': os.path.expanduser('~'),
'PATH': _path_without_us(),
'TERM': os.environ.get('TERM', ''),
# Windows needs this to import `random`
'SYSTEMROOT': os.environ.get('SYSTEMROOT', ''),

View File

@@ -0,0 +1,18 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import os.path
from pre_commit.languages import python
def test_norm_version_expanduser():
home = os.path.expanduser('~')
if os.name == 'nt': # pragma: no cover (nt)
path = r'~\python343'
expected_path = r'{0}\python343'.format(home)
else: # pragma: no cover (non-nt)
path = '~/.pyenv/versions/3.4.3/bin/python'
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
result = python.norm_version(path)
assert result == expected_path

View File

@@ -342,7 +342,9 @@ def test_additional_python_dependencies_installed(tempdir_factory, store):
@xfailif_windows_no_ruby
@pytest.mark.integration
def test_additional_ruby_dependencies_installed(tempdir_factory, store):
def test_additional_ruby_dependencies_installed(
tempdir_factory, store,
): # pragma: no cover (non-windows)
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
config = make_config_from_repo(path)
config['hooks'][0]['additional_dependencies'] = ['thread_safe']
@@ -355,7 +357,9 @@ def test_additional_ruby_dependencies_installed(tempdir_factory, store):
@xfailif_windows_no_node
@pytest.mark.integration
def test_additional_node_dependencies_installed(tempdir_factory, store):
def test_additional_node_dependencies_installed(
tempdir_factory, store,
): # pragma: no cover (non-windows)
path = make_repo(tempdir_factory, 'node_hooks_repo')
config = make_config_from_repo(path)
# Careful to choose a small package that's not depped by npm
@@ -481,15 +485,3 @@ def test_local_repository():
with pytest.raises(NotImplementedError):
local_repo.manifest
assert len(local_repo.hooks) == 1
def test_norm_version_expanduser(): # pragma: no cover
home = os.path.expanduser('~')
if os.name == 'nt':
path = r'~\python343'
expected_path = r'C:{0}\python343\python.exe'.format(home)
else:
path = '~/.pyenv/versions/3.4.3/bin/python'
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
result = python.norm_version(path)
assert result == expected_path