diff --git a/pre_commit/commands/clean.py b/pre_commit/commands/clean.py index 75d0acc0..5c763029 100644 --- a/pre_commit/commands/clean.py +++ b/pre_commit/commands/clean.py @@ -7,9 +7,9 @@ from pre_commit import output from pre_commit.util import rmtree -def clean(runner): +def clean(store): legacy_path = os.path.expanduser('~/.pre-commit') - for directory in (runner.store.directory, legacy_path): + for directory in (store.directory, legacy_path): if os.path.exists(directory): rmtree(directory) output.write_line('Cleaned {}.'.format(directory)) diff --git a/pre_commit/main.py b/pre_commit/main.py index f9882368..4ff8073d 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -243,7 +243,7 @@ def main(argv=None): elif args.command == 'uninstall': return uninstall(runner, hook_type=args.hook_type) elif args.command == 'clean': - return clean(runner) + return clean(runner.store) elif args.command == 'autoupdate': if args.tags_only: logger.warning('--tags-only is the default') diff --git a/tests/commands/clean_test.py b/tests/commands/clean_test.py index fddd444d..3bfa46a3 100644 --- a/tests/commands/clean_test.py +++ b/tests/commands/clean_test.py @@ -6,7 +6,6 @@ import mock import pytest from pre_commit.commands.clean import clean -from pre_commit.util import rmtree @pytest.fixture(autouse=True) @@ -21,17 +20,16 @@ def fake_old_dir(tempdir_factory): yield fake_old_dir -def test_clean(runner_with_mocked_store, fake_old_dir): +def test_clean(store, fake_old_dir): + store.require_created() assert os.path.exists(fake_old_dir) - assert os.path.exists(runner_with_mocked_store.store.directory) - clean(runner_with_mocked_store) + assert os.path.exists(store.directory) + clean(store) assert not os.path.exists(fake_old_dir) - assert not os.path.exists(runner_with_mocked_store.store.directory) + assert not os.path.exists(store.directory) -def test_clean_empty(runner_with_mocked_store): - """Make sure clean succeeds when the directory doesn't exist.""" - 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) +def test_clean_idempotent(store): + assert not os.path.exists(store.directory) + clean(store) + assert not os.path.exists(store.directory) diff --git a/tests/conftest.py b/tests/conftest.py index c0e13186..eb2ecf6e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,10 +11,8 @@ import mock import pytest import six -import pre_commit.constants as C from pre_commit import output 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 testing.fixtures import git_dir @@ -151,11 +149,6 @@ def store(tempdir_factory): yield Store(os.path.join(tempdir_factory.get(), '.pre-commit')) -@pytest.fixture -def runner_with_mocked_store(mock_out_store_directory): - yield Runner('/', C.CONFIG_FILE) - - @pytest.fixture def log_info_mock(): with mock.patch.object(logging.getLogger('pre_commit'), 'info') as mck: