|
1
|
|
|
from opinionated_configparser import OpinionatedConfigParser |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
TEST_DICT1 = { |
|
5
|
|
|
"_common": { |
|
6
|
|
|
"key1[foo_bar_1]": "value6", |
|
7
|
|
|
"key3": "value7", |
|
8
|
|
|
"key4": "value8" |
|
9
|
|
|
}, |
|
10
|
|
|
"section1": { |
|
11
|
|
|
"key1": "value1", |
|
12
|
|
|
"key1[fOo]": "value2", |
|
13
|
|
|
"key1[foo_bar]": "value3", |
|
14
|
|
|
"key2": "value4" |
|
15
|
|
|
}, |
|
16
|
|
|
"section2": { |
|
17
|
|
|
"key3": "value5" |
|
18
|
|
|
}, |
|
19
|
|
|
"section3": { |
|
20
|
|
|
"issue8[foo]bar": "foobar" |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
def test_constructor(): |
|
26
|
|
|
x = OpinionatedConfigParser() |
|
27
|
|
|
assert x is not None |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
def test_issue8(): |
|
31
|
|
|
x = OpinionatedConfigParser() |
|
32
|
|
|
x.read_dict(TEST_DICT1) |
|
33
|
|
|
assert x.get("section3", "issue8[foo]bar") == "foobar" |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
View Code Duplication |
def test_read_dict_without_inheritance(): |
|
|
|
|
|
|
37
|
|
|
x = OpinionatedConfigParser(configuration_name="foo") |
|
38
|
|
|
x.read_dict(TEST_DICT1) |
|
39
|
|
|
assert x.get("section1", "key1") == "value2" |
|
40
|
|
|
assert x.get("section1", "key2") == "value4" |
|
41
|
|
|
assert x.get("section1", "key3", fallback=None) is None |
|
42
|
|
|
assert x.get("section1", "key4", fallback=None) is None |
|
43
|
|
|
assert x.get("section2", "key1", fallback=None) is None |
|
44
|
|
|
assert x.get("section2", "key3") == "value5" |
|
45
|
|
|
assert x.get("section2", "key4", fallback=None) is None |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
View Code Duplication |
def test_read_dict_without_inheritance2(): |
|
|
|
|
|
|
49
|
|
|
x = OpinionatedConfigParser(configuration_name="foo_foo_foo_foo") |
|
50
|
|
|
x.read_dict(TEST_DICT1) |
|
51
|
|
|
assert x.get("section1", "key1") == "value2" |
|
52
|
|
|
assert x.get("section1", "key2") == "value4" |
|
53
|
|
|
assert x.get("section1", "key3", fallback=None) is None |
|
54
|
|
|
assert x.get("section1", "key4", fallback=None) is None |
|
55
|
|
|
assert x.get("section2", "key1", fallback=None) is None |
|
56
|
|
|
assert x.get("section2", "key3") == "value5" |
|
57
|
|
|
assert x.get("section2", "key4", fallback=None) is None |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
View Code Duplication |
def test_read_dict_with_inheritance(): |
|
|
|
|
|
|
61
|
|
|
x = OpinionatedConfigParser(configuration_name="foo", |
|
62
|
|
|
default_section="_common") |
|
63
|
|
|
x.read_dict(TEST_DICT1) |
|
64
|
|
|
assert x.get("section1", "key1") == "value2" |
|
65
|
|
|
assert x.get("section1", "key2") == "value4" |
|
66
|
|
|
assert x.get("section1", "key3") == "value7" |
|
67
|
|
|
assert x.get("section1", "key4") == "value8" |
|
68
|
|
|
assert x.get("section2", "key1", fallback=None) is None |
|
69
|
|
|
assert x.get("section2", "key3") == "value5" |
|
70
|
|
|
assert x.get("section1", "key4") == "value8" |
|
71
|
|
|
assert x.get("_common", "key3", fallback=None) is None |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
def test_read_dict_with_inheritance2(): |
|
75
|
|
|
x = OpinionatedConfigParser(configuration_name="foo_bar_1", |
|
76
|
|
|
default_section="_common") |
|
77
|
|
|
x.read_dict(TEST_DICT1) |
|
78
|
|
|
assert x.get("section1", "key1") == "value6" |
|
79
|
|
|
assert x.get("section1", "key2") == "value4" |
|
80
|
|
|
assert x.get("section1", "key3") == "value7" |
|
81
|
|
|
assert x.get("section1", "key4") == "value8" |
|
82
|
|
|
assert x.get("section2", "key1") == "value6" |
|
83
|
|
|
assert x.get("section2", "key3") == "value5" |
|
84
|
|
|
assert x.get("section1", "key4") == "value8" |
|
85
|
|
|
assert x.get("_common", "key3", fallback=None) is None |
|
86
|
|
|
|