mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 09:04:41 +04:00
Tests pass on windows
This commit is contained in:
parent
56e5c4eb2d
commit
143ed94500
21 changed files with 224 additions and 109 deletions
|
|
@ -1,9 +1,9 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import shutil
|
||||
|
||||
from pre_commit.commands.clean import clean
|
||||
from pre_commit.util import rmtree
|
||||
|
||||
|
||||
def test_clean(runner_with_mocked_store):
|
||||
|
|
@ -14,7 +14,7 @@ def test_clean(runner_with_mocked_store):
|
|||
|
||||
def test_clean_empty(runner_with_mocked_store):
|
||||
"""Make sure clean succeeds when we the directory doesn't exist."""
|
||||
shutil.rmtree(runner_with_mocked_store.store.directory)
|
||||
rmtree(runner_with_mocked_store.store.directory)
|
||||
assert not os.path.exists(runner_with_mocked_store.store.directory)
|
||||
clean(runner_with_mocked_store)
|
||||
assert not os.path.exists(runner_with_mocked_store.store.directory)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import io
|
|||
import os
|
||||
import os.path
|
||||
import re
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
|
@ -63,8 +62,7 @@ def test_install_pre_commit(tmpdir_factory):
|
|||
pre_push=''
|
||||
)
|
||||
assert pre_commit_contents == expected_contents
|
||||
stat_result = os.stat(runner.pre_commit_path)
|
||||
assert stat_result.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
||||
assert os.access(runner.pre_commit_path, os.X_OK)
|
||||
|
||||
ret = install(runner, hook_type='pre-push')
|
||||
assert ret == 0
|
||||
|
|
@ -120,19 +118,19 @@ def _get_commit_output(
|
|||
# osx does this different :(
|
||||
FILES_CHANGED = (
|
||||
r'('
|
||||
r' 1 file changed, 0 insertions\(\+\), 0 deletions\(-\)\n'
|
||||
r' 1 file changed, 0 insertions\(\+\), 0 deletions\(-\)\r?\n'
|
||||
r'|'
|
||||
r' 0 files changed\n'
|
||||
r' 0 files changed\r?\n'
|
||||
r')'
|
||||
)
|
||||
|
||||
|
||||
NORMAL_PRE_COMMIT_RUN = re.compile(
|
||||
r'^\[INFO\] Initializing environment for .+\.\n'
|
||||
r'Bash hook\.+Passed\n'
|
||||
r'\[master [a-f0-9]{7}\] Commit!\n' +
|
||||
r'^\[INFO\] Initializing environment for .+\.\r?\n'
|
||||
r'Bash hook\.+Passed\r?\n'
|
||||
r'\[master [a-f0-9]{7}\] Commit!\r?\n' +
|
||||
FILES_CHANGED +
|
||||
r' create mode 100644 foo\n$'
|
||||
r' create mode 100644 foo\r?\n$'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -166,7 +164,7 @@ def test_environment_not_sourced(tmpdir_factory):
|
|||
|
||||
ret, stdout, stderr = cmd_output(
|
||||
'git', 'commit', '--allow-empty', '-m', 'foo',
|
||||
env={'HOME': os.environ['HOME']},
|
||||
env={'HOME': os.path.expanduser('~')},
|
||||
retcode=None,
|
||||
)
|
||||
assert ret == 1
|
||||
|
|
@ -178,13 +176,13 @@ def test_environment_not_sourced(tmpdir_factory):
|
|||
|
||||
|
||||
FAILING_PRE_COMMIT_RUN = re.compile(
|
||||
r'^\[INFO\] Initializing environment for .+\.\n'
|
||||
r'Failing hook\.+Failed\n'
|
||||
r'hookid: failing_hook\n'
|
||||
r'\n'
|
||||
r'Fail\n'
|
||||
r'foo\n'
|
||||
r'\n$'
|
||||
r'^\[INFO\] Initializing environment for .+\.\r?\n'
|
||||
r'Failing hook\.+Failed\r?\n'
|
||||
r'hookid: failing_hook\r?\n'
|
||||
r'\r?\n'
|
||||
r'Fail\r?\n'
|
||||
r'foo\r?\n'
|
||||
r'\r?\n$'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -199,10 +197,10 @@ def test_failing_hooks_returns_nonzero(tmpdir_factory):
|
|||
|
||||
|
||||
EXISTING_COMMIT_RUN = re.compile(
|
||||
r'^legacy hook\n'
|
||||
r'\[master [a-f0-9]{7}\] Commit!\n' +
|
||||
r'^legacy hook\r?\n'
|
||||
r'\[master [a-f0-9]{7}\] Commit!\r?\n' +
|
||||
FILES_CHANGED +
|
||||
r' create mode 100644 baz\n$'
|
||||
r' create mode 100644 baz\r?\n$'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -253,9 +251,9 @@ def test_install_existing_hook_no_overwrite_idempotent(tmpdir_factory):
|
|||
|
||||
|
||||
FAIL_OLD_HOOK = re.compile(
|
||||
r'fail!\n'
|
||||
r'\[INFO\] Initializing environment for .+\.\n'
|
||||
r'Bash hook\.+Passed\n'
|
||||
r'fail!\r?\n'
|
||||
r'\[INFO\] Initializing environment for .+\.\r?\n'
|
||||
r'Bash hook\.+Passed\r?\n'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -363,10 +361,10 @@ def test_uninstall_doesnt_remove_not_our_hooks(tmpdir_factory):
|
|||
|
||||
|
||||
PRE_INSTALLED = re.compile(
|
||||
r'Bash hook\.+Passed\n'
|
||||
r'\[master [a-f0-9]{7}\] Commit!\n' +
|
||||
r'Bash hook\.+Passed\r?\n'
|
||||
r'\[master [a-f0-9]{7}\] Commit!\r?\n' +
|
||||
FILES_CHANGED +
|
||||
r' create mode 100644 foo\n$'
|
||||
r' create mode 100644 foo\r?\n$'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -394,8 +392,10 @@ def test_installed_from_venv(tmpdir_factory):
|
|||
ret, output = _get_commit_output(
|
||||
tmpdir_factory,
|
||||
env_base={
|
||||
'HOME': os.environ['HOME'],
|
||||
'HOME': os.path.expanduser('~'),
|
||||
'TERM': os.environ.get('TERM', ''),
|
||||
# Windows needs this to import `random`
|
||||
'SYSTEMROOT': os.environ.get('SYSTEMROOT', ''),
|
||||
},
|
||||
)
|
||||
assert ret == 0
|
||||
|
|
|
|||
|
|
@ -275,7 +275,9 @@ def test_stdout_write_bug_py26(
|
|||
):
|
||||
with cwd(repo_with_failing_hook):
|
||||
# Add bash hook on there again
|
||||
with io.open('.pre-commit-config.yaml', 'a+') as config_file:
|
||||
with io.open(
|
||||
'.pre-commit-config.yaml', 'a+', encoding='UTF-8',
|
||||
) as config_file:
|
||||
config_file.write(' args: ["☃"]\n')
|
||||
cmd_output('git', 'add', '.pre-commit-config.yaml')
|
||||
stage_a_file()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue