summaryrefslogtreecommitdiffstats
path: root/tests/commands/clean_test.py
blob: 955a6bc4ebbb7a2fae5092179fe9b7a5b2f1ad15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os.path
from unittest 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)