tests.test_clean   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A TestClean._make_list() 0 7 3
A TestClean.test_clean_aggressive() 0 9 1
A TestClean.test_clean() 0 13 1
1
from pathlib import Path
2
3
import pytest
4
5
from tyrannosaurus.clean import Clean
6
7
from tests import TestResources
8
9
10
class TestClean:
11
    def test_clean(self):
12
        root = TestResources.resource("fake")
13
        self._make_list("__pycache__", "eggs", "cython_debug", root=root)
14
        cleaner = Clean(dists=False, aggressive=False, hard_delete=False, dry_run=True)
15
        trashed = cleaner.clean(root)
16
        st = {k.name for k, v in trashed}
17
        assert "__pycache__" in st
18
        assert "eggs" in st
19
        assert "cython_debug" in st
20
        assert "tyrannosaurus" not in st
21
        assert "docs" not in st
22
        assert "recipes" not in st
23
        assert ".tox" not in st
24
25
    def test_clean_aggressive(self):
26
        root = TestResources.resource("fake")
27
        self._make_list("eggs", ".ipynb_checkpoints", ".tox", ".tyrannosaurus", root=root)
28
        cleaner = Clean(dists=False, aggressive=True, hard_delete=False, dry_run=True)
29
        trashed = cleaner.clean(root)
30
        st = {k.name for k, v in trashed}
31
        assert "eggs" in st
32
        assert ".ipynb_checkpoints" in st
33
        assert ".tox" in st
34
35
    def _make_list(self, *paths: str, root: Path):
36
        made = []
37
        for p in paths:
38
            if not (root / p).exists():
39
                (root / p).mkdir()
40
            made.append(root / p)
41
        return made
42
43
44
if __name__ == "__main__":
45
    pytest.main()
46