forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gc.py
49 lines (38 loc) · 1.33 KB
/
test_gc.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import shutil
import filecmp
from dvc.main import main
from dvc.utils import file_md5
from dvc.stage import Stage
from dvc.output import CmdOutputNoCacheError, CmdOutputOutsideOfRepoError
from dvc.output import CmdOutputDoesNotExistError
from dvc.project import StageNotFoundError
from dvc.command.gc import CmdGC
from tests.basic_env import TestDvc
class TestGC(TestDvc):
def setUp(self):
super(TestGC, self).setUp()
self.dvc.add(self.FOO)
self.dvc.add(self.DATA_DIR)
self.good_cache = self.dvc.cache.all()
self.bad_cache = []
for i in ['123', '234', '345']:
path = os.path.join(self.dvc.cache.cache_dir, i[0:2], i[2:])
self.create(path, i)
self.bad_cache.append(path)
path = os.path.join(self.dvc.cache.cache_dir, '45', '6', 'data')
os.mkdir(os.path.dirname(path))
self.create(path, 'md5: "123"')
self.bad_cache.append(path)
def test_api(self):
self.dvc.gc()
self._test_gc()
def test_cli(self):
ret = main(['gc'])
self._test_gc()
def _test_gc(self):
self.assertTrue(os.path.isdir(self.dvc.cache.cache_dir))
for c in self.bad_cache:
self.assertFalse(os.path.exists(c))
for c in self.good_cache:
self.assertTrue(os.path.exists(c))