mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Move cwd() to tests-only
This commit is contained in:
parent
082c950d8f
commit
29033f10ca
21 changed files with 84 additions and 103 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import pipes
|
||||
import shutil
|
||||
from collections import OrderedDict
|
||||
|
|
@ -14,7 +15,6 @@ from pre_commit.commands.autoupdate import autoupdate
|
|||
from pre_commit.commands.autoupdate import RepositoryCannotBeUpdatedError
|
||||
from pre_commit.runner import Runner
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
from testing.fixtures import add_config_to_repo
|
||||
from testing.fixtures import config_with_local_hooks
|
||||
|
|
@ -62,14 +62,13 @@ def test_autoupdate_old_revision_broken(
|
|||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path, check=False)
|
||||
|
||||
with cwd(path):
|
||||
cmd_output('git', 'mv', C.MANIFEST_FILE, 'nope.yaml')
|
||||
cmd_output('git', 'commit', '-m', 'simulate old repo')
|
||||
# Assume this is the revision the user's old repository was at
|
||||
rev = git.head_sha(path)
|
||||
cmd_output('git', 'mv', 'nope.yaml', C.MANIFEST_FILE)
|
||||
cmd_output('git', 'commit', '-m', 'move hooks file')
|
||||
update_rev = git.head_sha(path)
|
||||
cmd_output('git', '-C', path, 'mv', C.MANIFEST_FILE, 'nope.yaml')
|
||||
cmd_output('git', '-C', path, 'commit', '-m', 'simulate old repo')
|
||||
# Assume this is the revision the user's old repository was at
|
||||
rev = git.head_sha(path)
|
||||
cmd_output('git', '-C', path, 'mv', 'nope.yaml', C.MANIFEST_FILE)
|
||||
cmd_output('git', '-C', path, 'commit', '-m', 'move hooks file')
|
||||
update_rev = git.head_sha(path)
|
||||
|
||||
config['sha'] = rev
|
||||
write_config('.', config)
|
||||
|
|
@ -87,8 +86,7 @@ def out_of_date_repo(tempdir_factory):
|
|||
original_sha = git.head_sha(path)
|
||||
|
||||
# Make a commit
|
||||
with cwd(path):
|
||||
cmd_output('git', 'commit', '--allow-empty', '-m', 'foo')
|
||||
cmd_output('git', '-C', path, 'commit', '--allow-empty', '-m', 'foo')
|
||||
head_sha = git.head_sha(path)
|
||||
|
||||
yield auto_namedtuple(
|
||||
|
|
@ -223,8 +221,7 @@ def test_loses_formatting_when_not_detectable(
|
|||
|
||||
@pytest.fixture
|
||||
def tagged_repo(out_of_date_repo):
|
||||
with cwd(out_of_date_repo.path):
|
||||
cmd_output('git', 'tag', 'v1.2.3')
|
||||
cmd_output('git', '-C', out_of_date_repo.path, 'tag', 'v1.2.3')
|
||||
yield out_of_date_repo
|
||||
|
||||
|
||||
|
|
@ -243,8 +240,8 @@ def test_autoupdate_tagged_repo(
|
|||
|
||||
@pytest.fixture
|
||||
def tagged_repo_with_more_commits(tagged_repo):
|
||||
with cwd(tagged_repo.path):
|
||||
cmd_output('git', 'commit', '--allow-empty', '-m', 'commit!')
|
||||
cmd = ('git', '-C', tagged_repo.path, 'commit', '--allow-empty', '-mfoo')
|
||||
cmd_output(*cmd)
|
||||
yield tagged_repo
|
||||
|
||||
|
||||
|
|
@ -267,13 +264,12 @@ def hook_disappearing_repo(tempdir_factory):
|
|||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
original_sha = git.head_sha(path)
|
||||
|
||||
with cwd(path):
|
||||
shutil.copy(
|
||||
get_resource_path('manifest_without_foo.yaml'),
|
||||
C.MANIFEST_FILE,
|
||||
)
|
||||
cmd_output('git', 'add', '.')
|
||||
cmd_output('git', 'commit', '-m', 'Remove foo')
|
||||
shutil.copy(
|
||||
get_resource_path('manifest_without_foo.yaml'),
|
||||
os.path.join(path, C.MANIFEST_FILE),
|
||||
)
|
||||
cmd_output('git', '-C', path, 'add', '.')
|
||||
cmd_output('git', '-C', path, 'commit', '-m', 'Remove foo')
|
||||
|
||||
yield auto_namedtuple(path=path, original_sha=original_sha)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ from pre_commit.commands.install_uninstall import PRIOR_HASHES
|
|||
from pre_commit.commands.install_uninstall import uninstall
|
||||
from pre_commit.runner import Runner
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.util import make_executable
|
||||
from pre_commit.util import mkdirp
|
||||
from pre_commit.util import resource_filename
|
||||
|
|
@ -28,6 +27,7 @@ from testing.fixtures import git_dir
|
|||
from testing.fixtures import make_consuming_repo
|
||||
from testing.fixtures import remove_config_from_repo
|
||||
from testing.util import cmd_output_mocked_pre_commit_home
|
||||
from testing.util import cwd
|
||||
from testing.util import xfailif_no_symlink
|
||||
|
||||
|
||||
|
|
@ -153,9 +153,8 @@ def test_install_pre_commit_and_run_custom_path(tempdir_factory):
|
|||
def test_install_in_submodule_and_run(tempdir_factory):
|
||||
src_path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
parent_path = git_dir(tempdir_factory)
|
||||
with cwd(parent_path):
|
||||
cmd_output('git', 'submodule', 'add', src_path, 'sub')
|
||||
cmd_output('git', 'commit', '-m', 'foo')
|
||||
cmd_output('git', '-C', parent_path, 'submodule', 'add', src_path, 'sub')
|
||||
cmd_output('git', '-C', parent_path, 'commit', '-m', 'foo')
|
||||
|
||||
sub_pth = os.path.join(parent_path, 'sub')
|
||||
with cwd(sub_pth):
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ from pre_commit.commands.run import _has_unmerged_paths
|
|||
from pre_commit.commands.run import run
|
||||
from pre_commit.runner import Runner
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.util import make_executable
|
||||
from testing.fixtures import add_config_to_repo
|
||||
from testing.fixtures import make_consuming_repo
|
||||
from testing.fixtures import modify_config
|
||||
from testing.fixtures import read_config
|
||||
from testing.util import cmd_output_mocked_pre_commit_home
|
||||
from testing.util import cwd
|
||||
from testing.util import run_opts
|
||||
from testing.util import xfailif_no_symlink
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ import re
|
|||
|
||||
from pre_commit.commands.try_repo import try_repo
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
from testing.fixtures import git_dir
|
||||
from testing.fixtures import make_repo
|
||||
from testing.util import cwd
|
||||
from testing.util import run_opts
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ from pre_commit.logging_handler import add_logging_handler
|
|||
from pre_commit.runner import Runner
|
||||
from pre_commit.store import Store
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from testing.fixtures import git_dir
|
||||
from testing.fixtures import make_consuming_repo
|
||||
from testing.fixtures import write_config
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -68,10 +68,9 @@ def _make_conflict():
|
|||
@pytest.fixture
|
||||
def in_merge_conflict(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
open('dummy', 'a').close()
|
||||
cmd_output('git', 'add', 'dummy')
|
||||
cmd_output('git', 'commit', '-m', 'Add config.')
|
||||
open(os.path.join(path, 'dummy'), 'a').close()
|
||||
cmd_output('git', '-C', path, 'add', 'dummy')
|
||||
cmd_output('git', '-C', path, 'commit', '-m', 'Add config.')
|
||||
|
||||
conflict_path = tempdir_factory.get()
|
||||
cmd_output('git', 'clone', path, conflict_path)
|
||||
|
|
@ -84,10 +83,8 @@ def in_merge_conflict(tempdir_factory):
|
|||
def in_conflicting_submodule(tempdir_factory):
|
||||
git_dir_1 = git_dir(tempdir_factory)
|
||||
git_dir_2 = git_dir(tempdir_factory)
|
||||
with cwd(git_dir_2):
|
||||
cmd_output('git', 'commit', '--allow-empty', '-m', 'init!')
|
||||
with cwd(git_dir_1):
|
||||
cmd_output('git', 'submodule', 'add', git_dir_2, 'sub')
|
||||
cmd_output('git', '-C', git_dir_2, 'commit', '--allow-empty', '-minit!')
|
||||
cmd_output('git', '-C', git_dir_1, 'submodule', 'add', git_dir_2, 'sub')
|
||||
with cwd(os.path.join(git_dir_1, 'sub')):
|
||||
_make_conflict()
|
||||
yield
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import pytest
|
|||
from pre_commit import git
|
||||
from pre_commit.error_handler import FatalError
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from testing.fixtures import git_dir
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
def test_get_root_at_root(tempdir_factory):
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import mock
|
|||
import pytest
|
||||
|
||||
from pre_commit import main
|
||||
from pre_commit.util import cwd
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
FNS = (
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import pytest
|
|||
from pre_commit import git
|
||||
from pre_commit import make_archives
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from testing.fixtures import git_dir
|
||||
|
||||
|
||||
|
|
@ -17,16 +16,15 @@ def test_make_archive(tempdir_factory):
|
|||
output_dir = tempdir_factory.get()
|
||||
git_path = git_dir(tempdir_factory)
|
||||
# Add a files to the git directory
|
||||
with cwd(git_path):
|
||||
open('foo', 'a').close()
|
||||
cmd_output('git', 'add', '.')
|
||||
cmd_output('git', 'commit', '-m', 'foo')
|
||||
# We'll use this sha
|
||||
head_sha = git.head_sha('.')
|
||||
# And check that this file doesn't exist
|
||||
open('bar', 'a').close()
|
||||
cmd_output('git', 'add', '.')
|
||||
cmd_output('git', 'commit', '-m', 'bar')
|
||||
open(os.path.join(git_path, 'foo'), 'a').close()
|
||||
cmd_output('git', '-C', git_path, 'add', '.')
|
||||
cmd_output('git', '-C', git_path, 'commit', '-m', 'foo')
|
||||
# We'll use this sha
|
||||
head_sha = git.head_sha(git_path)
|
||||
# And check that this file doesn't exist
|
||||
open(os.path.join(git_path, 'bar'), 'a').close()
|
||||
cmd_output('git', '-C', git_path, 'add', '.')
|
||||
cmd_output('git', '-C', git_path, 'commit', '-m', 'bar')
|
||||
|
||||
# Do the thing
|
||||
archive_path = make_archives.make_archive(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
from pre_commit.meta_hooks import check_hooks_apply
|
||||
from pre_commit.util import cwd
|
||||
from testing.fixtures import add_config_to_repo
|
||||
from testing.fixtures import git_dir
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
def test_hook_excludes_everything(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
from pre_commit.meta_hooks import check_useless_excludes
|
||||
from pre_commit.util import cwd
|
||||
from testing.fixtures import add_config_to_repo
|
||||
from testing.fixtures import git_dir
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
def test_useless_exclude_global(capsys, tempdir_factory):
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@ from pre_commit.languages import python
|
|||
from pre_commit.languages import ruby
|
||||
from pre_commit.repository import Repository
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from testing.fixtures import config_with_local_hooks
|
||||
from testing.fixtures import git_dir
|
||||
from testing.fixtures import make_config_from_repo
|
||||
from testing.fixtures import make_repo
|
||||
from testing.fixtures import modify_manifest
|
||||
from testing.util import cwd
|
||||
from testing.util import get_resource_path
|
||||
from testing.util import skipif_cant_run_docker
|
||||
from testing.util import skipif_cant_run_swift
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ from collections import OrderedDict
|
|||
import pre_commit.constants as C
|
||||
from pre_commit.runner import Runner
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from testing.fixtures import add_config_to_repo
|
||||
from testing.fixtures import git_dir
|
||||
from testing.fixtures import make_consuming_repo
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
def test_init_has_no_side_effects(tmpdir):
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ import pytest
|
|||
|
||||
from pre_commit.staged_files_only import staged_files_only
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
from testing.fixtures import git_dir
|
||||
from testing.util import cwd
|
||||
from testing.util import get_resource_path
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ from pre_commit import git
|
|||
from pre_commit.store import _get_default_directory
|
||||
from pre_commit.store import Store
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.util import rmtree
|
||||
from testing.fixtures import git_dir
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
def test_our_session_fixture_works():
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import pytest
|
|||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.util import memoize_by_cwd
|
||||
from pre_commit.util import tmpdir
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
def test_CalledProcessError_str():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue