forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_config.py
85 lines (62 loc) · 2.42 KB
/
test_config.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
import configobj
from dvc.main import main
from tests.basic_env import TestDvc
class TestConfigCLI(TestDvc):
def _contains(self, section, field, value, local=False):
if local:
fname = self.dvc.config.config_local_file
else:
fname = self.dvc.config.config_file
config = configobj.ConfigObj(fname)
if section not in config.keys():
return False
if field not in config[section].keys():
return False
if config[section][field] != value:
return False
return True
def test_root(self):
ret = main(["root"])
self.assertEqual(ret, 0)
# NOTE: check that `dvc root` is not blocked with dvc lock
with self.dvc.lock:
ret = main(["root"])
self.assertEqual(ret, 0)
def _do_test(self, local=False):
section = "setsection"
field = "setfield"
section_field = "{}.{}".format(section, field)
value = "setvalue"
newvalue = "setnewvalue"
base = ["config"]
if local:
base.append("--local")
ret = main(base + [section_field, value])
self.assertEqual(ret, 0)
self.assertTrue(self._contains(section, field, value, local))
ret = main(base + [section_field])
self.assertEqual(ret, 0)
ret = main(base + [section_field, newvalue])
self.assertEqual(ret, 0)
self.assertTrue(self._contains(section, field, newvalue, local))
self.assertFalse(self._contains(section, field, value, local))
ret = main(base + [section_field, "--unset"])
self.assertEqual(ret, 0)
self.assertFalse(self._contains(section, field, value, local))
def test(self):
self._do_test(False)
def test_local(self):
self._do_test(True)
def test_non_existing(self):
ret = main(["config", "non_existing_section.field"])
self.assertEqual(ret, 251)
ret = main(["config", "global.non_existing_field"])
self.assertEqual(ret, 251)
ret = main(["config", "non_existing_section.field", "-u"])
self.assertEqual(ret, 251)
ret = main(["config", "global.non_existing_field", "-u"])
self.assertEqual(ret, 251)
ret = main(["config", "core.remote", "myremote"])
self.assertEqual(ret, 0)
ret = main(["config", "core.non_existing_field", "-u"])
self.assertEqual(ret, 251)