-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathconfig_tests.py
124 lines (109 loc) · 4.14 KB
/
config_tests.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
119
120
121
122
123
124
import unittest
import sys
import lib50.errors
import lib50.config
class TestLoader(unittest.TestCase):
def test_no_tool(self):
content = ""
config = lib50.config.Loader("check50").load(content)
self.assertEqual(config, None)
def test_falsy_tool(self):
content = "check50: false"
config = lib50.config.Loader("check50").load(content)
self.assertFalse(config)
def test_truthy_tool(self):
content = "check50: true"
config = lib50.config.Loader("check50").load(content)
self.assertTrue(config)
def test_no_files(self):
content = \
"check50:\n" \
" dependencies:\n" \
" - foo"
config = lib50.config.Loader("check50").load(content)
self.assertEqual(config, {"dependencies" : ["foo"]})
def test_global_tag(self):
content = \
"check50:\n" \
" foo:\n" \
" - !include baz\n" \
" bar:\n" \
" - !include qux"
config = lib50.config.Loader("check50", "include").load(content)
self.assertTrue(config["foo"][0].include)
self.assertEqual(config["foo"][0].value, "baz")
self.assertTrue(config["bar"][0].include)
self.assertEqual(config["bar"][0].value, "qux")
def test_local_tag(self):
content = \
"check50:\n" \
" files:\n" \
" - !include foo"
loader = lib50.config.Loader("check50")
loader.scope("files", "include")
config = loader.load(content)
self.assertTrue(config["files"][0].include)
self.assertEqual(config["files"][0].value, "foo")
content = \
"check50:\n" \
" bar:\n" \
" - !include foo"
loader = lib50.config.Loader("check50")
loader.scope("files", "include", default=False)
with self.assertRaises(lib50.errors.InvalidConfigError):
config = loader.load(content)
def test_no_default(self):
content = \
"check50:\n" \
" files:\n" \
" - !INVALID foo"
loader = lib50.config.Loader("check50")
loader.scope("files", "include", default=False)
with self.assertRaises(lib50.errors.InvalidConfigError):
config = loader.load(content)
def test_local_default(self):
content = \
"check50:\n" \
" files:\n" \
" - foo"
loader = lib50.config.Loader("check50")
loader.scope("files", default="bar")
config = loader.load(content)
self.assertTrue(config["files"][0].bar)
self.assertEqual(config["files"][0].value, "foo")
def test_global_default(self):
content = \
"check50:\n" \
" files:\n" \
" - foo"
config = lib50.config.Loader("check50", default="bar").load(content)
self.assertTrue(config["files"][0].bar)
self.assertEqual(config["files"][0].value, "foo")
def test_multiple_defaults(self):
content = \
"check50:\n" \
" foo:\n" \
" - baz\n" \
" bar:\n" \
" - qux"
loader = lib50.config.Loader("check50", default="include")
loader.scope("bar", default="exclude")
config = loader.load(content)
self.assertTrue(config["foo"][0].include)
self.assertEqual(config["foo"][0].value, "baz")
self.assertTrue(config["bar"][0].exclude)
self.assertEqual(config["bar"][0].value, "qux")
def test_same_tag_default(self):
content = \
"check50:\n" \
" foo:\n" \
" - !include bar\n" \
" - baz"
config = lib50.config.Loader("check50", "include", default="include").load(content)
self.assertTrue(config["foo"][0].include)
self.assertEqual(config["foo"][0].value, "bar")
self.assertTrue(config["foo"][1].include)
self.assertEqual(config["foo"][1].value, "baz")
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
unittest.TextTestRunner(verbosity=2).run(suite)