Files
pre-commit/tests/commands/clean_test.py
Anthony Sottile 9e34e6e316 pre-commit gc
2019-01-02 19:07:23 -08:00

36 lines
846 B
Python

from __future__ import unicode_literals
import os.path
import mock
import pytest
from pre_commit.commands.clean import clean
@pytest.fixture(autouse=True)
def fake_old_dir(tempdir_factory):
fake_old_dir = tempdir_factory.get()
def _expanduser(path, *args, **kwargs):
assert path == '~/.pre-commit'
return fake_old_dir
with mock.patch.object(os.path, 'expanduser', side_effect=_expanduser):
yield fake_old_dir
def test_clean(store, fake_old_dir):
assert os.path.exists(fake_old_dir)
assert os.path.exists(store.directory)
clean(store)
assert not os.path.exists(fake_old_dir)
assert not os.path.exists(store.directory)
def test_clean_idempotent(store):
clean(store)
assert not os.path.exists(store.directory)
clean(store)
assert not os.path.exists(store.directory)