forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tag.py
118 lines (79 loc) · 2.96 KB
/
test_tag.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import shutil
import filecmp
import logging
from dvc.main import main
from dvc.utils import from_yaml_string
from tests.basic_env import TestDvc
class TestTag(TestDvc):
def test(self):
fname = "file"
shutil.copyfile(self.FOO, fname)
stages = self.dvc.add(fname)
self.assertEqual(len(stages), 1)
stage = stages[0]
self.assertTrue(stage is not None)
ret = main(["tag", "add", "v1", stage.path])
self.assertEqual(ret, 0)
os.unlink(fname)
shutil.copyfile(self.BAR, fname)
ret = main(["repro", stage.path])
self.assertEqual(ret, 0)
ret = main(["tag", "add", "v2", stage.path])
self.assertEqual(ret, 0)
ret = main(["tag", "list", stage.path])
self.assertEqual(ret, 0)
ret = main(["checkout", stage.path + "@v1"])
self.assertEqual(ret, 0)
self.assertTrue(filecmp.cmp(fname, self.FOO, shallow=False))
ret = main(["checkout", stage.path + "@v2"])
self.assertEqual(ret, 0)
self.assertTrue(filecmp.cmp(fname, self.BAR, shallow=False))
class TestTagAll(TestDvc):
def test(self):
ret = main(["add", self.FOO, self.BAR])
self.assertEqual(ret, 0)
self._caplog.clear()
ret = main(["tag", "list"])
self.assertEqual(ret, 0)
self.assertEqual("", self._caplog.text)
ret = main(["tag", "add", "v1"])
self.assertEqual(ret, 0)
self._caplog.clear()
ret = main(["tag", "list"])
self.assertEqual(ret, 0)
expected = {
"foo.dvc": {
"foo": {"v1": {"md5": "acbd18db4cc2f85cedef654fccc4a4d8"}}
},
"bar.dvc": {
"bar": {"v1": {"md5": "8978c98bb5a48c2fb5f2c4c905768afa"}}
},
}
stdout = "\n".join(record.message for record in self._caplog.records)
received = from_yaml_string(stdout)
assert expected == received
ret = main(["tag", "remove", "v1"])
self.assertEqual(ret, 0)
self._caplog.clear()
ret = main(["tag", "list"])
self.assertEqual(ret, 0)
self.assertEqual("", self._caplog.text)
class TestTagAddNoChecksumInfo(TestDvc):
def test(self):
ret = main(["run", "-o", self.FOO, "--no-exec"])
self.assertEqual(ret, 0)
self._caplog.clear()
with self._caplog.at_level(logging.WARNING, logger="dvc"):
ret = main(["tag", "add", "v1", "foo.dvc"])
self.assertEqual(ret, 0)
assert "missing checksum info for 'foo'" in self._caplog.text
class TestTagRemoveNoTag(TestDvc):
def test(self):
ret = main(["add", self.FOO])
self.assertEqual(ret, 0)
self._caplog.clear()
with self._caplog.at_level(logging.WARNING, logger="dvc"):
ret = main(["tag", "remove", "v1", "foo.dvc"])
self.assertEqual(ret, 0)
assert "tag 'v1' not found for 'foo'" in self._caplog.text