Skip to content

Commit 6d683a5

Browse files
committed
clean: separate store from runner
1 parent 0e430be commit 6d683a5

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

pre_commit/commands/clean.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from pre_commit.util import rmtree
88

99

10-
def clean(runner):
10+
def clean(store):
1111
legacy_path = os.path.expanduser('~/.pre-commit')
12-
for directory in (runner.store.directory, legacy_path):
12+
for directory in (store.directory, legacy_path):
1313
if os.path.exists(directory):
1414
rmtree(directory)
1515
output.write_line('Cleaned {}.'.format(directory))

pre_commit/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def main(argv=None):
243243
elif args.command == 'uninstall':
244244
return uninstall(runner, hook_type=args.hook_type)
245245
elif args.command == 'clean':
246-
return clean(runner)
246+
return clean(runner.store)
247247
elif args.command == 'autoupdate':
248248
if args.tags_only:
249249
logger.warning('--tags-only is the default')

tests/commands/clean_test.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pytest
77

88
from pre_commit.commands.clean import clean
9-
from pre_commit.util import rmtree
109

1110

1211
@pytest.fixture(autouse=True)
@@ -21,17 +20,16 @@ def _expanduser(path, *args, **kwargs):
2120
yield fake_old_dir
2221

2322

24-
def test_clean(runner_with_mocked_store, fake_old_dir):
23+
def test_clean(store, fake_old_dir):
24+
store.require_created()
2525
assert os.path.exists(fake_old_dir)
26-
assert os.path.exists(runner_with_mocked_store.store.directory)
27-
clean(runner_with_mocked_store)
26+
assert os.path.exists(store.directory)
27+
clean(store)
2828
assert not os.path.exists(fake_old_dir)
29-
assert not os.path.exists(runner_with_mocked_store.store.directory)
29+
assert not os.path.exists(store.directory)
3030

3131

32-
def test_clean_empty(runner_with_mocked_store):
33-
"""Make sure clean succeeds when the directory doesn't exist."""
34-
rmtree(runner_with_mocked_store.store.directory)
35-
assert not os.path.exists(runner_with_mocked_store.store.directory)
36-
clean(runner_with_mocked_store)
37-
assert not os.path.exists(runner_with_mocked_store.store.directory)
32+
def test_clean_idempotent(store):
33+
assert not os.path.exists(store.directory)
34+
clean(store)
35+
assert not os.path.exists(store.directory)

tests/conftest.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
import pytest
1212
import six
1313

14-
import pre_commit.constants as C
1514
from pre_commit import output
1615
from pre_commit.logging_handler import add_logging_handler
17-
from pre_commit.runner import Runner
1816
from pre_commit.store import Store
1917
from pre_commit.util import cmd_output
2018
from testing.fixtures import git_dir
@@ -151,11 +149,6 @@ def store(tempdir_factory):
151149
yield Store(os.path.join(tempdir_factory.get(), '.pre-commit'))
152150

153151

154-
@pytest.fixture
155-
def runner_with_mocked_store(mock_out_store_directory):
156-
yield Runner('/', C.CONFIG_FILE)
157-
158-
159152
@pytest.fixture
160153
def log_info_mock():
161154
with mock.patch.object(logging.getLogger('pre_commit'), 'info') as mck:

0 commit comments

Comments
 (0)