annotate tests/test.py @ 417:83d537f1dfbb

Implement sub-jails: allow to get a jailed configuration from a jail
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 01 Dec 2021 23:10:20 +0100
parents 2abde0d3c735
children bb5f11abd12a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
2
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
3 import sys
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
4 import os
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
5 import unittest
116
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
6 import platform
119
eefde3288fb8 FIX: YAML-file streams must be opened as UTF-8 text files; otherwise double encoding occurs for non-Unicode locales (e.g. Windows)
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 116
diff changeset
7 import io
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
8
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
9 sys.path.insert(
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
10 0,
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
11 os.path.abspath(
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
12 os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
13
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
14 import configmix
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
15 import configmix.ini
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
16 import configmix.yaml
122
21d92ff8cf31 Begin the handling of JSON-style configuration files
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
17 import configmix.json
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
18 import configmix.py
195
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents: 183
diff changeset
19 import configmix.toml
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
20 from configmix.compat import u
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
21
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
22
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
23 TESTDATADIR = os.path.join(
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
24 os.path.abspath(os.path.dirname(__file__)),
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
25 "data")
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
26
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
27
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
28 class T01Basic(unittest.TestCase):
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
29
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
30 """Check with low-level internal interfaces"""
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
31
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
32 def __check_types(self, cfg):
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
33 self.assertEqual(u("the value"),
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
34 cfg.get("key1"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
35 self.assertTrue(isinstance(cfg.get("key1"), type(u(''))))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
36 self.assertEqual(2, cfg.get("key2"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
37 self.assertEqual(5.7, cfg.get("key3"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
38 self.assertTrue(isinstance(cfg.get("key1"), type(u(''))))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
39 self.assertTrue(cfg.get("key4"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
40 self.assertTrue(isinstance(cfg.get("key4"), bool))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
41 self.assertFalse(cfg.get("key5"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
42 self.assertTrue(isinstance(cfg.get("key5"), bool))
95
a0ed95975980 Test octal n umbers in values
Franz Glasner <hg@dom66.de>
parents: 93
diff changeset
43 self.assertEqual(255, cfg.get("key6"))
120
ba5970a2dcef The default file encoding when reading INI style files with configmix.ini.load() is now "UTF-8".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 119
diff changeset
44 self.assertEqual(u("Umlaute: ÄÖÜäöüß"),
ba5970a2dcef The default file encoding when reading INI style files with configmix.ini.load() is now "UTF-8".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 119
diff changeset
45 cfg.get("key7"))
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
46
144
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
47 def __check_comment(self, cfg):
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
48 # Check comments: low level comments are *not* filtered
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
49 self.assertEqual(u("Comment 1"), cfg.get("__comment1"))
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
50 self.assertEqual(u("Comment no 2"), cfg.get("__comment2"))
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
51
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
52 def __check_no_comment(self, cfg):
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
53
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
54 def _c(name):
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
55 def _f():
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
56 cfg[u(name)]
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
57 return _f
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
58
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
59 # Variables with leading underscores are *not* imported by default
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
60 self.assertRaises(KeyError, _c("__comment1"))
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
61 self.assertRaises(KeyError, _c("__comment2"))
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
62
97
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
63 def __check_tree(self, cfg):
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
64 self.assertEqual(u("in the root namespace"),
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
65 cfg.get("key1"))
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
66 self.assertEqual(u("in the root namespace -- too"),
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
67 cfg.get("key2"))
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
68 self.assertEqual(32,
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
69 cfg["tree1"]["key3"])
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
70 self.assertEqual(u("get this as `tree1.tree2.key4'"),
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
71 cfg["tree1"]["tree2"]["key4"])
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
72 self.assertTrue(cfg["tree1"]["tree2"]["key5"])
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
73
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
74 def test01_ini_types(self):
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
75 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
76 self.__check_types(cfg)
144
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
77 self.__check_comment(cfg)
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
78
198
0b855758ba08 An additional TOML-related unittest (types)
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
79 def test01_toml_types(self):
0b855758ba08 An additional TOML-related unittest (types)
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
80 cfg = configmix.toml.load(os.path.join(TESTDATADIR, "conf1.toml"))
0b855758ba08 An additional TOML-related unittest (types)
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
81 self.__check_types(cfg)
227
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
82 self.__check_comment(cfg)
198
0b855758ba08 An additional TOML-related unittest (types)
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
83
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
84 def test02_py_types(self):
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
85 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf1.py"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
86 self.__check_types(cfg)
144
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
87 self.__check_no_comment(cfg)
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
88
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
89 def test03_yaml_types(self):
119
eefde3288fb8 FIX: YAML-file streams must be opened as UTF-8 text files; otherwise double encoding occurs for non-Unicode locales (e.g. Windows)
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 116
diff changeset
90 with io.open(os.path.join(TESTDATADIR, "conf1.yml"), "rt",
eefde3288fb8 FIX: YAML-file streams must be opened as UTF-8 text files; otherwise double encoding occurs for non-Unicode locales (e.g. Windows)
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 116
diff changeset
91 encoding="utf-8") as f:
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
92 cfg = configmix.yaml.safe_load(f)
134
2f2e819e8d17 Check the return type of the JSON and YAML loading functions: they must be a dict alike
Franz Glasner <hg@dom66.de>
parents: 130
diff changeset
93 if configmix.yaml.OrderedDict:
2f2e819e8d17 Check the return type of the JSON and YAML loading functions: they must be a dict alike
Franz Glasner <hg@dom66.de>
parents: 130
diff changeset
94 self.assertTrue(isinstance(cfg, configmix.yaml.OrderedDict))
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
95 self.__check_types(cfg)
144
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
96 self.__check_comment(cfg)
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
97
122
21d92ff8cf31 Begin the handling of JSON-style configuration files
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
98 def test04_json_types(self):
21d92ff8cf31 Begin the handling of JSON-style configuration files
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
99 cfg = configmix.json.load(os.path.join(TESTDATADIR, "conf1.json"))
127
5b62d2c0e5a8 Use the available "OrderedDict" class as dict for the JSON parser
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
100 self.assertTrue(isinstance(cfg, configmix.json.DictImpl))
122
21d92ff8cf31 Begin the handling of JSON-style configuration files
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
101 self.__check_types(cfg)
144
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
102 self.__check_comment(cfg)
122
21d92ff8cf31 Begin the handling of JSON-style configuration files
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
103
21d92ff8cf31 Begin the handling of JSON-style configuration files
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
104 def test05_py_export_all(self):
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
105 # When __all__ is given only it's keys are exported
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
106 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf2.py"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
107 self.assertEqual(u("the next value"), cfg.get("key1"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
108 self.assertTrue(isinstance(cfg.get("key1"), type(u(''))))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
109 self.assertTrue(cfg.get("key2") is None)
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
110
122
21d92ff8cf31 Begin the handling of JSON-style configuration files
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
111 def test06_py_hide_private(self):
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
112 # When no __all__ is given all symbols with leading "_" are hidden
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
113 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf3.py"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
114 self.assertEqual(u("the next value "), cfg.get("key1"))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
115 self.assertTrue(isinstance(cfg.get("key1"), type(u(''))))
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
116 self.assertTrue(cfg.get("_key2") is None)
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
117
122
21d92ff8cf31 Begin the handling of JSON-style configuration files
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
118 def test07_ini_tree(self):
97
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
119 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf10.ini"))
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
120 self.__check_tree(cfg)
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
121
122
21d92ff8cf31 Begin the handling of JSON-style configuration files
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
122 def test08_py_tree(self):
97
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
123 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf10.py"))
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
124 self.__check_tree(cfg)
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
125
122
21d92ff8cf31 Begin the handling of JSON-style configuration files
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
126 def test09_yaml_tree(self):
119
eefde3288fb8 FIX: YAML-file streams must be opened as UTF-8 text files; otherwise double encoding occurs for non-Unicode locales (e.g. Windows)
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 116
diff changeset
127 with io.open(os.path.join(TESTDATADIR, "conf10.yml"), "rt",
eefde3288fb8 FIX: YAML-file streams must be opened as UTF-8 text files; otherwise double encoding occurs for non-Unicode locales (e.g. Windows)
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 116
diff changeset
128 encoding="utf-8") as f:
97
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
129 cfg = configmix.yaml.safe_load(f)
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
130 self.__check_tree(cfg)
1b4d95f60650 Build a tree-ish configuration from an INI style configuration file
Franz Glasner <hg@dom66.de>
parents: 95
diff changeset
131
130
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
132 def test10_json_tree(self):
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
133 cfg = configmix.json.load(os.path.join(TESTDATADIR, "conf10.json"))
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
134 self.__check_tree(cfg)
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
135
195
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents: 183
diff changeset
136 def test11_toml_tree(self):
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents: 183
diff changeset
137 cfg = configmix.toml.load(os.path.join(TESTDATADIR, "conf10.toml"))
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents: 183
diff changeset
138 self.__check_tree(cfg)
28e6c1413947 Added support for TOML style configuration files
Franz Glasner <fzglas.hg@dom66.de>
parents: 183
diff changeset
139
292
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
140 def test12_yaml_no_duplicate_keys(self):
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
141 import yaml.constructor as yc
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
142 with io.open(os.path.join(TESTDATADIR, "duplicate-keys.yml"), "rt",
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
143 encoding="utf-8") as f:
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
144 cfg = configmix.yaml.safe_load(f)
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
145
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
146 with io.open(os.path.join(TESTDATADIR, "duplicate-keys.yml"), "rt",
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
147 encoding="utf-8") as f:
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
148 self.assertRaises(yc.ConstructorError,
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
149 configmix.yaml.safe_load,
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
150 f, strict=True)
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
151
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
152 def test13_yaml_no_duplicate_keys_2(self):
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
153 import yaml.constructor as yc
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
154 with io.open(os.path.join(TESTDATADIR, "duplicate-keys-2.yml"), "rt",
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
155 encoding="utf-8") as f:
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
156 cfg = configmix.yaml.safe_load(f)
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
157
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
158 with io.open(os.path.join(TESTDATADIR, "duplicate-keys-2.yml"), "rt",
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
159 encoding="utf-8") as f:
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
160 self.assertRaises(yc.ConstructorError,
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
161 configmix.yaml.safe_load,
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
162 f, strict=True)
6a044778371a Some unittests for the new "strict" YAML parsing mode to prevent duplicate keys within a single YAML document
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 276
diff changeset
163
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
164
112
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
165 class _T02MixinLoadAndMerge:
105
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
166
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
167 def test01_load(self):
112
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
168 cfg = self._load(
105
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
169 os.path.join(TESTDATADIR, "conf20.yml"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
170 os.path.join(TESTDATADIR, "conf21.yml"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
171
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
172 self.assertEqual(u("the_database_user"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
173 cfg.getvar_s("db.user.name"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
174 self.assertEqual(u("the-database-password"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
175 cfg.getvar_s("db.user.pwd"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
176
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
177 tmpdir = cfg.getvar_s("tmpdir")
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
178 if os.name == 'nt':
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
179 self.assertFalse(u('/') in tmpdir)
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
180 self.assertEqual(os.path.normpath(
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
181 os.path.abspath(os.path.join(os.getcwd(), "tmp"))),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
182 tmpdir)
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
183
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
184 self.assertEqual(u("anotherhost"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
185 cfg.getvar_s("db.locinfo.ro.hostname"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
186 self.assertEqual(u("localhost"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
187 cfg.getvar_s("db.locinfo.rw.hostname"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
188
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
189 self.assertEqual(5432, cfg.getvar_s("db.locinfo.ro.port"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
190
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
191 url = cfg.getvar_s("db.engines.ro.url")
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
192 self.assertEqual(
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
193 u("postgresql+psycopg2://the_database_user:the-database-password@anotherhost:5432/my_database_catalog"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
194 url)
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
195
109
057d87d030f1 Test replacing lists by strings and replacing strings by lists
Franz Glasner <hg@dom66.de>
parents: 105
diff changeset
196 self.assertEqual(u("not a list any more"),
057d87d030f1 Test replacing lists by strings and replacing strings by lists
Franz Glasner <hg@dom66.de>
parents: 105
diff changeset
197 cfg.getvar_s("test.List"))
057d87d030f1 Test replacing lists by strings and replacing strings by lists
Franz Glasner <hg@dom66.de>
parents: 105
diff changeset
198
057d87d030f1 Test replacing lists by strings and replacing strings by lists
Franz Glasner <hg@dom66.de>
parents: 105
diff changeset
199 self.assertEqual(list(range(0, 3)),
057d87d030f1 Test replacing lists by strings and replacing strings by lists
Franz Glasner <hg@dom66.de>
parents: 105
diff changeset
200 cfg.getvar_s("test.Str"))
057d87d030f1 Test replacing lists by strings and replacing strings by lists
Franz Glasner <hg@dom66.de>
parents: 105
diff changeset
201
105
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
202 def test02_load_with_ini(self):
112
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
203 cfg = self._load(
105
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
204 os.path.join(TESTDATADIR, "conf20.yml"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
205 os.path.join(TESTDATADIR, "conf21.yml"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
206 os.path.join(TESTDATADIR, "conf22.ini"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
207
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
208 self.assertEqual(u("the_database_user_2"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
209 cfg.getvar_s("db.user.name"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
210 self.assertEqual(u("the-database-password-2"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
211 cfg.getvar_s("db.user.pwd"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
212
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
213 tmpdir = cfg.getvar_s("tmpdir")
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
214 self.assertEqual(u(os.getcwd()) + u("/tmp\\2"), tmpdir)
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
215
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
216 self.assertEqual(u("3rd-host"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
217 cfg.getvar_s("db.locinfo.ro.hostname"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
218 self.assertEqual(u("localhost"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
219 cfg.getvar_s("db.locinfo.rw.hostname"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
220
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
221 self.assertEqual(5432, cfg.getvar_s("db.locinfo.ro.port"))
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
222
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
223 url = cfg.getvar_s("db.engines.ro.url")
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
224 self.assertEqual(
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
225 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
226 url)
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
227
130
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
228 def test02_load_with_json(self):
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
229 cfg = self._load(
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
230 os.path.join(TESTDATADIR, "conf20.yml"),
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
231 os.path.join(TESTDATADIR, "conf21.yml"),
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
232 # .ini replaced with an equivalent .json
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
233 os.path.join(TESTDATADIR, "conf23.json"))
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
234
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
235 self.assertEqual(u("the_database_user_2"),
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
236 cfg.getvar_s("db.user.name"))
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
237 self.assertEqual(u("the-database-password-2"),
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
238 cfg.getvar_s("db.user.pwd"))
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
239
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
240 tmpdir = cfg.getvar_s("tmpdir")
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
241 self.assertEqual(u(os.getcwd()) + u("/tmp\\3"), tmpdir)
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
242
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
243 self.assertEqual(u("3rd-host"),
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
244 cfg.getvar_s("db.locinfo.ro.hostname"))
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
245 self.assertEqual(u("localhost"),
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
246 cfg.getvar_s("db.locinfo.rw.hostname"))
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
247
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
248 self.assertEqual(5432, cfg.getvar_s("db.locinfo.ro.port"))
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
249
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
250 url = cfg.getvar_s("db.engines.ro.url")
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
251 self.assertEqual(
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
252 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
253 url)
b11af3ded7c1 Added more JSON specific unit tests
Franz Glasner <hg@dom66.de>
parents: 127
diff changeset
254
196
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
255 def test02_load_with_toml(self):
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
256 cfg = self._load(
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
257 os.path.join(TESTDATADIR, "conf20.yml"),
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
258 os.path.join(TESTDATADIR, "conf21.yml"),
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
259 # .ini replaced with an equivalent .toml
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
260 os.path.join(TESTDATADIR, "conf24.toml"))
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
261
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
262 self.assertEqual(u("the_database_user_2"),
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
263 cfg.getvar_s("db.user.name"))
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
264 self.assertEqual(u("the-database-password-2"),
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
265 cfg.getvar_s("db.user.pwd"))
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
266
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
267 tmpdir = cfg.getvar_s("tmpdir")
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
268 self.assertEqual(u(os.getcwd()) + u("/tmp\\4"), tmpdir)
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
269
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
270 self.assertEqual(u("3rd-host"),
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
271 cfg.getvar_s("db.locinfo.ro.hostname"))
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
272 self.assertEqual(u("localhost"),
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
273 cfg.getvar_s("db.locinfo.rw.hostname"))
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
274
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
275 self.assertEqual(5432, cfg.getvar_s("db.locinfo.ro.port"))
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
276
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
277 url = cfg.getvar_s("db.engines.ro.url")
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
278 self.assertEqual(
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
279 u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
227
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
280 url)
196
13527d70e9e3 An additional unit test with a TOML style configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
281
116
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
282 def test03_namespace(self):
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
283 cfg = self._load(
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
284 os.path.join(TESTDATADIR, "conf20.yml"),
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
285 os.path.join(TESTDATADIR, "conf21.yml"),
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
286 os.path.join(TESTDATADIR, "conf22.ini"))
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
287 self.assertEqual(u(os.getcwd()), cfg.getvar("OS:cwd"))
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
288 self.assertEqual(u(platform.python_version()),
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
289 cfg.getvar_s("PY:version"))
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
290
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
291 def test03_namespace_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
292 cfg = self._load(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
293 os.path.join(TESTDATADIR, "conf20.yml"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
294 os.path.join(TESTDATADIR, "conf21.yml"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
295 os.path.join(TESTDATADIR, "conf22.ini"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
296 self.assertEqual(u(os.getcwd()), cfg.getvarl("cwd", namespace="OS"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
297 self.assertEqual(u(platform.python_version()),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
298 cfg.getvarl_s("version", namespace="PY"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
299
116
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
300 def test04_no_filter(self):
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
301 cfg = self._load(
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
302 os.path.join(TESTDATADIR, "conf20.yml"),
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
303 os.path.join(TESTDATADIR, "conf21.yml"),
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
304 os.path.join(TESTDATADIR, "conf22.ini"))
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
305
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
306 def _look():
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
307 return cfg.getvar("OS:cwd|upper")
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
308
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
309 self.assertRaises(KeyError, _look)
c37fa787c022 More unittests for fetching namespaced variables and filters
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
310
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
311 def test04_no_filter_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
312 cfg = self._load(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
313 os.path.join(TESTDATADIR, "conf20.yml"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
314 os.path.join(TESTDATADIR, "conf21.yml"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
315 os.path.join(TESTDATADIR, "conf22.ini"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
316
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
317 def _look():
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
318 return cfg.getvarl("cwd|upper", namespace="OS")
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
319
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
320 self.assertRaises(KeyError, _look)
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
321
144
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
322 def test05_comments(self):
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
323 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"),
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
324 os.path.join(TESTDATADIR, "conf21.yml"),
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
325 os.path.join(TESTDATADIR, "conf22.ini"),
198
0b855758ba08 An additional TOML-related unittest (types)
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
326 os.path.join(TESTDATADIR, "conf23.json"),
0b855758ba08 An additional TOML-related unittest (types)
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
327 os.path.join(TESTDATADIR, "conf24.toml"))
144
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
328
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
329 def _c(name):
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
330 def _f():
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
331 cfg.getvar_s(name)
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
332 return _f
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
333
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
334 # Variables with leading underscores are *not* imported by default
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
335 self.assertEqual(0o0027, int(cfg.getvar_s("process.umask"), 0))
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
336 self.assertRaises(KeyError, _c("process.__doc1"))
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
337 self.assertRaises(KeyError, _c("db.__comment1"))
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
338 self.assertRaises(KeyError, _c("db.user.__doc2"))
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
339
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
340 def test05_comments_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
341 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
342 os.path.join(TESTDATADIR, "conf21.yml"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
343 os.path.join(TESTDATADIR, "conf22.ini"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
344 os.path.join(TESTDATADIR, "conf23.json"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
345 os.path.join(TESTDATADIR, "conf24.toml"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
346
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
347 def _c(*names):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
348 def _f():
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
349 cfg.getvarl_s(*names)
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
350 return _f
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
351
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
352 # Variables with leading underscores are *not* imported by default
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
353 self.assertEqual(0o0027, int(cfg.getvarl_s("process", "umask"), 0))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
354 self.assertRaises(KeyError, _c("process", "__doc1"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
355 self.assertRaises(KeyError, _c("db", "__comment1"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
356 self.assertRaises(KeyError, _c("db", "user", "__doc2"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
357
146
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
358 def test06_check_all_comments(self):
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
359 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"),
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
360 os.path.join(TESTDATADIR, "conf21.yml"),
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
361 os.path.join(TESTDATADIR, "conf22.ini"),
198
0b855758ba08 An additional TOML-related unittest (types)
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
362 os.path.join(TESTDATADIR, "conf23.json"),
0b855758ba08 An additional TOML-related unittest (types)
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
363 os.path.join(TESTDATADIR, "conf24.toml"))
146
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
364
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
365 def _check(d):
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
366 for k, v in d.items():
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
367 self.assertFalse(configmix._is_comment(k))
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
368 if isinstance(v, dict):
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
369 _check(v)
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
370
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
371 _check(cfg)
bbf47bfb48a2 Add a unittest that scans the complete configuration dict for comment keys
Franz Glasner <hg@dom66.de>
parents: 144
diff changeset
372
276
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
373 def test07_deletions(self):
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
374 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"),
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
375 os.path.join(TESTDATADIR, "conf21.yml"),
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
376 os.path.join(TESTDATADIR, "conf22.ini"),
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
377 os.path.join(TESTDATADIR, "conf23.json"),
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
378 os.path.join(TESTDATADIR, "conf24.toml"),
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
379 os.path.join(TESTDATADIR, "delete-in-dict.yml"))
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
380 # automatic clean-up
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
381 self.assertRaises(KeyError, cfg.getvar_s, "not-deleted")
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
382 # explicit deletion
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
383 self.assertRaises(KeyError, cfg.getvar_s, "to-be-deleted")
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
384 self.assertRaises(KeyError, cfg.getvar_s, "db.user.name")
323
Franz Glasner <fzglas.hg@dom66.de>
parents: 320
diff changeset
385 self.assertEqual("the-database-password-2", cfg.getvar_s("db.user.pwd"))
276
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
386 self.assertRaises(KeyError, cfg.getvar_s, "test.Str")
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
387 self.assertEqual("not a list any more", cfg.getvar_s("test.List"))
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
388 self.assertEqual("the last value",
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
389 cfg.getvar_s("to-be-deleted-but-reassigned"))
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
390
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
391 def test07_deletions_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
392 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
393 os.path.join(TESTDATADIR, "conf21.yml"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
394 os.path.join(TESTDATADIR, "conf22.ini"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
395 os.path.join(TESTDATADIR, "conf23.json"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
396 os.path.join(TESTDATADIR, "conf24.toml"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
397 os.path.join(TESTDATADIR, "delete-in-dict.yml"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
398 # automatic clean-up
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
399 self.assertRaises(KeyError, cfg.getvarl_s, "not-deleted")
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
400 # explicit deletion
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
401 self.assertRaises(KeyError, cfg.getvarl_s, "to-be-deleted")
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
402 self.assertRaises(KeyError, cfg.getvarl_s, "db" "user.name")
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
403 self.assertEqual("the-database-password-2",
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
404 cfg.getvarl_s("db", "user", "pwd"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
405 self.assertRaises(KeyError, cfg.getvarl_s, "test", "Str")
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
406 self.assertEqual("not a list any more", cfg.getvarl_s("test", "List"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
407 self.assertEqual("the last value",
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
408 cfg.getvarl_s("to-be-deleted-but-reassigned"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
409
351
efbf7ba40287 Unittests for the "|None" filter
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 340
diff changeset
410 def test08_None_filter_single(self):
efbf7ba40287 Unittests for the "|None" filter
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 340
diff changeset
411 cfg = self._load()
efbf7ba40287 Unittests for the "|None" filter
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 340
diff changeset
412 x = cfg.expand_variable("{{non-existing|None}}")
efbf7ba40287 Unittests for the "|None" filter
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 340
diff changeset
413 self.assertIsNone(x)
efbf7ba40287 Unittests for the "|None" filter
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 340
diff changeset
414
efbf7ba40287 Unittests for the "|None" filter
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 340
diff changeset
415 def test09_None_filter_embedded(self):
efbf7ba40287 Unittests for the "|None" filter
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 340
diff changeset
416 cfg = self._load()
efbf7ba40287 Unittests for the "|None" filter
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 340
diff changeset
417 x = cfg.expand_variable("A{{non-existing|None}}Z")
355
260354e9a7f9 Avoid DeprecationWarning: assertEquals() -> assertEqual()
Franz Glasner <fzglas.hg@dom66.de>
parents: 352
diff changeset
418 self.assertEqual("AZ", x)
351
efbf7ba40287 Unittests for the "|None" filter
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 340
diff changeset
419
352
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 351
diff changeset
420 def test10_Empty_filtersingle(self):
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 351
diff changeset
421 cfg = self._load()
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 351
diff changeset
422 x = cfg.expand_variable("{{non-existing|Empty}}")
355
260354e9a7f9 Avoid DeprecationWarning: assertEquals() -> assertEqual()
Franz Glasner <fzglas.hg@dom66.de>
parents: 352
diff changeset
423 self.assertEqual("", x)
352
2b209bdf6995 Implement the "Empty" filter.
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 351
diff changeset
424
356
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
425 def test11_None_filter_pass_through(self):
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
426 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"),
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
427 os.path.join(TESTDATADIR, "conf21.yml"),
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
428 os.path.join(TESTDATADIR, "conf22.ini"),
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
429 os.path.join(TESTDATADIR, "conf23.json"),
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
430 os.path.join(TESTDATADIR, "conf24.toml"))
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
431 x = cfg.expand_variable("{{intl.cache.items|None}}")
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
432 self.assertEqual(10, x)
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
433
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
434 def test12_Empty_filter_pass_through(self):
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
435 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"),
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
436 os.path.join(TESTDATADIR, "conf21.yml"),
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
437 os.path.join(TESTDATADIR, "conf22.ini"),
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
438 os.path.join(TESTDATADIR, "conf23.json"),
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
439 os.path.join(TESTDATADIR, "conf24.toml"))
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
440 x = cfg.expand_variable("{{intl.cache.items|Empty}}")
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
441 self.assertEqual(10, x)
a5c792074ec9 Unittest to check "None" and "Empty" filters for existing values: they just pass through unchanged
Franz Glasner <fzglas.hg@dom66.de>
parents: 355
diff changeset
442
364
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
443 def test13_keyerror(self):
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
444 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
445 self.assertRaises(KeyError, cfg.getvar_s, "non.existing.key")
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
446
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
447 def test14_getvar_with_default(self):
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
448 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
449 self.assertEqual("999", cfg.getvar("non.existing.key", default="999"))
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
450
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
451 def test15_getvar_s_with_default(self):
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
452 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
453 self.assertEqual("999", cfg.getvar_s("non.existing.key",
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
454 default="999"))
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
455
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
456 def test16_getintvar_s_with_default(self):
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
457 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
458 self.assertEqual(9999, cfg.getintvar_s("non.existing.key",
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
459 default=9999))
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
460 def test17_getintvar_s_with_default(self):
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
461 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
462 self.assertFalse(cfg.getboolvar_s("non.existing.key",
372
ac3e3cd6faae FIX: 4ff02a4f401a made a somewhat wrong fix for Python 2.7: now the real fix takes into account that all text types are supposed to be Unicode in Python 2
Franz Glasner <fzglas.hg@dom66.de>
parents: 371
diff changeset
463 default=u('false')))
364
1941f0188e81 FIX: Handle a "default" keyword parameter in ".getvar()" properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 356
diff changeset
464
370
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
465 def test18_getfirstvar_nonexisting(self):
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
466 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
467 self.assertRaises(
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
468 KeyError,
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
469 cfg.getfirstvar,
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
470 "db.non.existing.key",
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
471 "db.non.existing.key2")
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
472
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
473 def test19_getfirstvar_nonexisting_default(self):
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
474 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
475 self.assertIsNone(cfg.getfirstvar("db.non.existing.key",
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
476 "db.non.existing.key2",
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
477 "intl.non.existing",
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
478 default=None))
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
479
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
480 def test20_getfirstvar_existing(self):
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
481 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
482 self.assertEqual("test-configmix", cfg.getfirstvar("intl.domain"))
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
483 self.assertEqual("test-configmix", cfg.getfirstvar("intl.domain",
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
484 "intl.fallback"))
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
485 self.assertEqual("de", cfg.getfirstvar("intl.fallback",
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
486 "intl.domain",
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
487 default=None))
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
488
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
489 self.assertEqual("de", cfg.getfirstvar("intl.non.existing",
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
490 "intl.fallback",
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
491 default=None))
18622d265602 Unittests for ".getfirstvar()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
492
371
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
493 def test21_getfirstvar_s_existing(self):
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
494 cfg = self._load(
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
495 os.path.join(TESTDATADIR, "conf20.yml"),
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
496 os.path.join(TESTDATADIR, "conf21.yml"))
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
497 self.assertEqual(
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
498 os.getcwd()+"/locale",
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
499 cfg.getfirstvar_s("intl.non.existing", "intl.localedir"))
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
500 self.assertEqual(
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
501 os.getcwd()+"/locale",
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
502 cfg.getfirstvar_s("intl.localedir", "intl.non.existing"))
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
503
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
504 def test22_getfirstvar_s_non_existing(self):
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
505 cfg = self._load(
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
506 os.path.join(TESTDATADIR, "conf20.yml"),
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
507 os.path.join(TESTDATADIR, "conf21.yml"))
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
508 self.assertIsNone(
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
509 cfg.getfirstvar_s("intl.non.existing", "intl.non.existing2",
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
510 default=None))
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
511 self.assertRaises(
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
512 KeyError,
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
513 cfg.getfirstvar_s,
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
514 "intl.non.existing",
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
515 "intl.non.existing2")
873b9d2ecb0b Unittests for ".getfirstvar_s()"
Franz Glasner <fzglas.hg@dom66.de>
parents: 370
diff changeset
516
373
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
517 def test23_getfirstintvar_s_nonexisting(self):
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
518 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
519 self.assertIsNone(cfg.getfirstintvar_s("db.non.existing.key",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
520 "db.non.existing.key2",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
521 "intl.non.existing",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
522 default=None))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
523 self.assertRaises(
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
524 KeyError,
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
525 cfg.getfirstintvar_s,
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
526 "db.non.existing.key",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
527 "db.non.exksting.key2",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
528 "intl.non.existing")
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
529
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
530 def test23_getfirstintvar_s_nonexisting(self):
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
531 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
532 self.assertEqual(20,
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
533 cfg.getfirstintvar_s("db.non.existing.key",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
534 "db.non.existing.key2",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
535 "intl.non.existing",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
536 default=u("20")))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
537 self.assertEqual(30,
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
538 cfg.getfirstintvar_s("db.non.existing.key",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
539 "db.non.existing.key2",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
540 "intl.non.existing",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
541 default=30))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
542 self.assertRaises(
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
543 KeyError,
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
544 cfg.getfirstintvar_s,
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
545 "db.non.existing.key",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
546 "db.non.exksting.key2",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
547 "intl.non.existing")
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
548
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
549 def test24_getfirstintvar_s_existing(self):
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
550 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
551 self.assertEqual(10,
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
552 cfg.getfirstintvar_s("db.non.existing.key",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
553 "intl.cache.items",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
554 "db.non.existing.key2",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
555 default=u("20")))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
556
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
557 def test25_getfirstboolvar_s_nonexisting(self):
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
558 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
559 self.assertFalse(
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
560 cfg.getfirstboolvar_s("db.non.existing.key",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
561 "db.non.existing.key2",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
562 "db.engines.rw.no-echo",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
563 default=u("false")))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
564 self.assertTrue(
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
565 cfg.getfirstboolvar_s("db.non.existing.key",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
566 "db.non.existing.key2",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
567 "db.engines.rw.no-echo",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
568 default=True))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
569 self.assertRaises(
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
570 KeyError,
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
571 cfg.getfirstboolvar_s,
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
572 "db.non.existing.key",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
573 "db.non.exksting.key2",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
574 "b.engines.rw.no-echo")
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
575
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
576 def test26_getfirstboolvar_s_existing(self):
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
577 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
578 self.assertFalse(
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
579 cfg.getfirstboolvar_s("db.non.existing.key",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
580 "db.engines.rw.echo",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
581 "db.non.existing.key2",
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
582 default=u("true")))
0c65aac81807 Implement ".getfirstintvar_s()" and ".getfirstboolvar_s()" with unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 372
diff changeset
583
381
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
584 def test27_getfirstvarl_nonexisting(self):
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
585 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
586 self.assertRaises(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
587 KeyError,
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
588 cfg.getfirstvarl,
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
589 [["db", "non", "existing", "key"],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
590 ("db", "non", "existing", "key2")])
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
591
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
592 def test27b_getfirstvarl_nonexisting(self):
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
593 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
594 self.assertRaises(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
595 KeyError,
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
596 cfg.getfirstvarl,
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
597 [{"namespace": None, "path": ["db", "non", "existing", "key"]},
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
598 {"namespace": None, "path": ["db", "non", "existing", "key2"]}])
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
599
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
600 def test28_getfirstvarl_nonexisting(self):
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
601 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
602 self.assertIsNone(cfg.getfirstvarl(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
603 [["db", "non", "existing", "key"],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
604 ("db", "non", "existing", "key2")],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
605 default=None))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
606
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
607 def test28b_getfirstvarl_nonexisting(self):
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
608 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
609 self.assertIsNone(cfg.getfirstvarl(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
610 [{"namespace": None, "path": ["db", "non", "existing", "key"]},
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
611 {"namespace": None, "path": ("db", "non", "existing", "key2")}],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
612 default=None))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
613
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
614 def test29_getfirstvarl_existing(self):
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
615 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
616 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
617 "test-configmix",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
618 cfg.getfirstvarl(*(("intl", "domain"),)))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
619 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
620 "test-configmix",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
621 cfg.getfirstvarl(*(("intl", "domain"), ("intl", "fallback"))))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
622 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
623 "de",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
624 cfg.getfirstvarl(*[["intl", "fallback"],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
625 ["intl", "domain"]],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
626 default=None))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
627 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
628 "de",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
629 cfg.getfirstvarl(*[["intl", "non", "existing"],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
630 ["intl", "fallback"]],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
631 default=None))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
632
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
633 def test29b_getfirstvarl_existing(self):
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
634 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
635 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
636 "test-configmix",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
637 cfg.getfirstvarl(*({"namespace": None,
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
638 "path": ("intl", "domain")},)))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
639 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
640 "test-configmix",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
641 cfg.getfirstvarl(*({"namespace": None,
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
642 "path": ("intl", "domain")},
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
643 {"namespace": None, "path": ("intl", "fallback")})))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
644 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
645 "de",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
646 cfg.getfirstvarl(*[{"namespace": None, "path": ["intl", "fallback"]},
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
647 {"namespace": None, "path": ["intl", "domain"]}],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
648 default=None))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
649 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
650 "de",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
651 cfg.getfirstvarl(*[{"namespace": None, "path": ["intl", "non", "existing"]},
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
652 {"namespace": None, "path": ["intl", "fallback"]}],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
653 default=None))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
654
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
655 def test30_getfirstvarl_s_existing(self):
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
656 cfg = self._load(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
657 os.path.join(TESTDATADIR, "conf20.yml"),
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
658 os.path.join(TESTDATADIR, "conf21.yml"))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
659 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
660 os.getcwd()+"/locale",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
661 cfg.getfirstvarl_s(*[["intl", "non", "existing"],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
662 ["intl", "localedir"]]))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
663 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
664 os.getcwd()+"/locale",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
665 cfg.getfirstvarl_s(*[["intl", "localedir"], ["intl", "non", "existing"]]))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
666
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
667 def test30b_getfirstvarl_s_existing(self):
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
668 cfg = self._load(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
669 os.path.join(TESTDATADIR, "conf20.yml"),
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
670 os.path.join(TESTDATADIR, "conf21.yml"))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
671 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
672 os.getcwd()+"/locale",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
673 cfg.getfirstvarl_s(*[{"namespace": None, "path": ["intl", "non", "existing"]},
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
674 {"namespace": None, "path": ["intl", "localedir"]}]))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
675 self.assertEqual(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
676 os.getcwd()+"/locale",
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
677 cfg.getfirstvarl_s(*[{"namespace": None, "path": ["intl", "localedir"]}, {"namespace": None, "path": ["intl", "non", "existing"]}]))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
678
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
679 def test31_getfirstvar_s_non_existing(self):
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
680 cfg = self._load(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
681 os.path.join(TESTDATADIR, "conf20.yml"),
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
682 os.path.join(TESTDATADIR, "conf21.yml"))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
683 self.assertIsNone(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
684 cfg.getfirstvarl_s(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
685 *[["intl", "non", "existing"], ["intl", "non", "existing2"]],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
686 default=None))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
687 self.assertRaises(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
688 KeyError,
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
689 cfg.getfirstvarl_s,
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
690 ["intl" ,"non", "existing"],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
691 ["intl", "non", "existing2"])
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
692
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
693 def test31b_getfirstvar_s_non_existing(self):
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
694 cfg = self._load(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
695 os.path.join(TESTDATADIR, "conf20.yml"),
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
696 os.path.join(TESTDATADIR, "conf21.yml"))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
697 self.assertIsNone(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
698 cfg.getfirstvarl_s(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
699 *[{"namespace": None, "path": ["intl", "non", "existing"]},
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
700 {"namespace": None, "path": ["intl", "non", "existing2"]}],
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
701 default=None))
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
702 self.assertRaises(
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
703 KeyError,
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
704 cfg.getfirstvarl_s,
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
705 {"namespace": None, "path": ["intl" ,"non", "existing"]},
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
706 {"namespace": None, "path": ["intl", "non", "existing2"]})
fe3dfd687621 Implemented Configuration.getfirstvarl() and Configuration.getfirstvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 373
diff changeset
707
390
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
708 def test32_getfirstintvarl_s_nonexisting(self):
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
709 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
710 self.assertIsNone(cfg.getfirstintvarl_s(
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
711 *(("db", "non", "existing", "key"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
712 ("db", "non", "existing", "key2"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
713 ("intl", "non", "existing")),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
714 default=None))
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
715 self.assertRaises(
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
716 KeyError,
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
717 cfg.getfirstintvarl_s,
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
718 ("db", "non", "existing", "key"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
719 ("db", "non", "exksting", "key2"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
720 ("intl", "non", "existing"))
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
721
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
722 def test33_getfirstintvarl_s_nonexisting(self):
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
723 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
724 self.assertEqual(
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
725 20,
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
726 cfg.getfirstintvarl_s(
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
727 *(("db", "non", "existing", ".key"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
728 ("db", "non", "existing", "key2"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
729 ("intl", "non", "existing")),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
730 default=u("20")))
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
731 self.assertEqual(
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
732 30,
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
733 cfg.getfirstintvarl_s(
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
734 *(("db", "non", "existing", "key"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
735 ("db", "non", "existing", "key2"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
736 ("intl", "non", "existing")),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
737 default=30))
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
738 self.assertRaises(
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
739 KeyError,
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
740 cfg.getfirstintvarl_s,
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
741 ("db", "non", "existing", "key"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
742 ("db", "non", "exksting", "key2"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
743 ("intl", "non", "existing"))
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
744
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
745 def test34_getfirstintvarl_s_existing(self):
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
746 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"))
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
747 self.assertEqual(
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
748 10,
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
749 cfg.getfirstintvarl_s(
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
750 *(("db", "non", "existing", "key"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
751 ("intl", "cache", "items"),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
752 ("db", "non", "existing", "key2")),
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
753 default=u("20")))
0521e857c320 Tests for getfirstintvarl_s()
Franz Glasner <fzglas.hg@dom66.de>
parents: 381
diff changeset
754
105
1c2f8a96dec2 Unittests with some real-worl-examples of .yml and .ini configuration files
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 97
diff changeset
755
112
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
756 class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase):
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
757
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
758 def setUp(self):
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
759 self._load = configmix.load
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
760
301
a03a6797533b Renumber: make room for new tests implemented in the mixin class
Franz Glasner <fzglas.hg@dom66.de>
parents: 292
diff changeset
761 def test0100_identity(self):
113
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
762 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini"))
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
763 cfg2 = configmix.merge(cfg, None)
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
764 self.assertEqual(id(cfg), id(cfg2))
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
765
301
a03a6797533b Renumber: make room for new tests implemented in the mixin class
Franz Glasner <fzglas.hg@dom66.de>
parents: 292
diff changeset
766 def test0101_identity(self):
113
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
767 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini"))
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
768 cfg2 = configmix.merge(cfg, {})
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
769 self.assertEqual(id(cfg), id(cfg2))
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
770
112
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
771
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
772 class T03SafeLoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase):
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
773
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
774 def setUp(self):
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
775 self._load = configmix.safe_load
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
776
301
a03a6797533b Renumber: make room for new tests implemented in the mixin class
Franz Glasner <fzglas.hg@dom66.de>
parents: 292
diff changeset
777 def test0100_deepcopy(self):
113
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
778 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini"))
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
779 cfg2 = configmix.safe_merge(cfg, None)
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
780 self.assertNotEqual(id(cfg), id(cfg2))
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
781
301
a03a6797533b Renumber: make room for new tests implemented in the mixin class
Franz Glasner <fzglas.hg@dom66.de>
parents: 292
diff changeset
782 def test0101_deepcopy(self):
113
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
783 cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini"))
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
784 cfg2 = configmix.safe_merge(cfg, {})
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
785 self.assertNotEqual(id(cfg), id(cfg2))
5b667c252f8c Test whether safe_merge really returns a deepcopy in the initial case and when not really merging
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
786
112
c50ad93eb5dc Implemented a "safe_load()" to load with safe merging
Franz Glasner <hg@dom66.de>
parents: 109
diff changeset
787
140
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
788 class T04CustomExtension(unittest.TestCase):
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
789
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
790 def setUp(self):
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
791 self._reset()
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
792
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
793 def tearDown(self):
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
794 self._reset()
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
795
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
796 def _reset(self):
181
7cfdc972af42 Refactor: Renamed public functions to be conform with the new loader search
Franz Glasner <fzglas.hg@dom66.de>
parents: 171
diff changeset
797 configmix.clear_assoc()
7cfdc972af42 Refactor: Renamed public functions to be conform with the new loader search
Franz Glasner <fzglas.hg@dom66.de>
parents: 171
diff changeset
798 for pat, fmode in configmix.DEFAULT_ASSOC:
7cfdc972af42 Refactor: Renamed public functions to be conform with the new loader search
Franz Glasner <fzglas.hg@dom66.de>
parents: 171
diff changeset
799 configmix.set_assoc(pat, fmode)
140
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
800
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
801 def test01_additional(self):
181
7cfdc972af42 Refactor: Renamed public functions to be conform with the new loader search
Franz Glasner <fzglas.hg@dom66.de>
parents: 171
diff changeset
802 configmix.set_assoc("*.conf", configmix.get_default_assoc("*.yml"))
140
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
803 cfg = configmix.load(
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
804 os.path.join(TESTDATADIR, "conf1.ini"),
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
805 os.path.join(TESTDATADIR, "conf30.conf"))
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
806 self.assertEqual(u("Umlaute: ÄÖÜäöüß"), cfg.getvar_s("key7"))
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
807 self.assertEqual(u("new value"), cfg.getvar_s("key-new"))
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
808
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
809 def test02_only_style_wrong_style(self):
181
7cfdc972af42 Refactor: Renamed public functions to be conform with the new loader search
Franz Glasner <fzglas.hg@dom66.de>
parents: 171
diff changeset
810 configmix.clear_assoc()
7cfdc972af42 Refactor: Renamed public functions to be conform with the new loader search
Franz Glasner <fzglas.hg@dom66.de>
parents: 171
diff changeset
811 configmix.set_assoc("*.conf", configmix.get_default_assoc("*.yml"))
140
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
812
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
813 def _ld():
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
814 return configmix.load(os.path.join(TESTDATADIR, "conf1.ini"),
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
815 os.path.join(TESTDATADIR, "conf30.conf"))
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
816
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
817 self.assertRaises(ValueError, _ld)
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
818
227
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
819 def test02_ignore_one_style(self):
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
820 configmix.clear_assoc()
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
821 configmix.set_assoc("*.conf", configmix.get_default_assoc("*.yml"))
228
b2c75efad9e4 Renamed the 'ignore' loader key to '-*-ignore-*-'
Franz Glasner <fzglas.hg@dom66.de>
parents: 227
diff changeset
822 configmix.set_assoc("*", "-*-ignore-*-", append=True)
227
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
823
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
824 cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"),
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
825 os.path.join(TESTDATADIR, "conf30.conf"))
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
826 self.assertEqual(u("new value"), cfg.getvar_s("key-new"))
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
827 self.assertRaises(KeyError, cfg.getvar_s, "key1")
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
828
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
829 def test02_ignore_all(self):
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
830 configmix.clear_assoc()
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
831 configmix.set_assoc("*.conf", configmix.get_default_assoc("*.yml"))
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
832 # This inserts at index 0 effectively ignoring all configuration files!
228
b2c75efad9e4 Renamed the 'ignore' loader key to '-*-ignore-*-'
Franz Glasner <fzglas.hg@dom66.de>
parents: 227
diff changeset
833 configmix.set_assoc("*", "-*-ignore-*-")
227
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
834
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
835 cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"),
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
836 os.path.join(TESTDATADIR, "conf30.conf"))
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
837 self.assertRaises(KeyError, cfg.getvar_s, "key-new")
251
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
838 self.assertRaises(KeyError, cfg.getvar_s, "key1")
227
f5011eec3b6e Added a loader with key "ignore" that ignores the given configuration file
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
839
140
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
840 def test03_only_style_corrrect_style(self):
181
7cfdc972af42 Refactor: Renamed public functions to be conform with the new loader search
Franz Glasner <fzglas.hg@dom66.de>
parents: 171
diff changeset
841 configmix.clear_assoc()
7cfdc972af42 Refactor: Renamed public functions to be conform with the new loader search
Franz Glasner <fzglas.hg@dom66.de>
parents: 171
diff changeset
842 configmix.set_assoc("*.conf", configmix.get_default_assoc("*.yml"))
140
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
843 cfg = configmix.load(os.path.join(TESTDATADIR, "conf30.conf"))
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
844 self.assertEqual(u("new value"), cfg.getvar_s("key-new"))
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
845
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
846 def _g():
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
847 return cfg.getvar_s("key7")
144
7e6ec99d5ff5 Allow comments as keys and filter them by default
Franz Glasner <hg@dom66.de>
parents: 140
diff changeset
848
140
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
849 self.assertRaises(KeyError, _g)
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
850
183
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
851 def test04_determine_mode(self):
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
852 configmix.clear_assoc()
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
853 configmix.set_assoc("*.conf", configmix.try_determine_filemode)
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
854 cfg = configmix.load(os.path.join(TESTDATADIR, "conf30.conf"))
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
855 self.assertEqual(u("new value"), cfg.getvar_s("key-new"))
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
856
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
857 self.assertRaises(KeyError, cfg.getvar_s, "key7")
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
858
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
859 def test05_try_determine_mode_none(self):
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
860 configmix.clear_assoc()
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
861 configmix.set_assoc("*.conf", configmix.try_determine_filemode)
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
862
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
863 def _ld():
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
864 return configmix.load(os.path.join(TESTDATADIR, "no-mode.conf"))
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
865
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
866 self.assertRaises(ValueError, _ld)
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
867
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
868 def test06_try_determine_mode_unknown(self):
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
869 configmix.clear_assoc()
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
870 configmix.set_assoc("*.conf", configmix.try_determine_filemode)
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
871
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
872 def _ld():
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
873 return configmix.load(os.path.join(TESTDATADIR, "unknown-mode.conf"))
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
874
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
875 self.assertRaises(KeyError, _ld)
d1103f0f9166 Unit-tests with the file-mode scanner
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 181
diff changeset
876
140
d8d47893df5b Unittests for custom configuration filename extensions
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
877
251
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
878 class T05SubstituteExpand(unittest.TestCase):
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
879
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
880 def setUp(self):
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
881 self._reset()
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
882
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
883 def tearDown(self):
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
884 self._reset()
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
885
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
886 def _reset(self):
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
887 configmix.clear_assoc()
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
888 for pat, fmode in configmix.DEFAULT_ASSOC:
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
889 configmix.set_assoc(pat, fmode)
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
890
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
891 def test01_expand_int_ini(self):
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
892 cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"))
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
893 self.assertEqual(2, cfg.getvar_s("key100"))
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
894
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
895 def test01_expand_int_ini_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
896 cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
897 self.assertEqual(2, cfg.getvarl_s("key100"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
898
251
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
899 def test02_expand_int_indirect_ini(self):
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
900 cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"))
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
901 self.assertEqual(2, cfg.getvar_s("key102"))
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
902
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
903 def test02_expand_int_indirect_ini_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
904 cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
905 self.assertEqual(2, cfg.getvarl_s("key102"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
906
251
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
907 def test03_expand_int2str_ini(self):
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
908 cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"))
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
909 self.assertEqual("the 2 value", cfg.getvar_s("key101"))
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
910
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
911 def test03_expand_int2str_ini_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
912 cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
913 self.assertEqual("the 2 value", cfg.getvarl_s("key101"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
914
251
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
915 def test04_expand_intint2str_ini(self):
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
916 cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"))
276
af371f9c016d Allow deletion of key-value pairs when merging is done.
Franz Glasner <fzglas.hg@dom66.de>
parents: 251
diff changeset
917 self.assertEqual("22", cfg.getvar_s("key103"))
251
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
918
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
919 def test04_expand_intint2str_ini_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
920 cfg = configmix.load(os.path.join(TESTDATADIR, "conf1.ini"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
921 self.assertEqual("22", cfg.getvarl_s("key103"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
922
251
2a8dcab2de8c Do not implicitely convert a configuration value to text if the value is the result of just a variable expansion.
Franz Glasner <fzglas.hg@dom66.de>
parents: 228
diff changeset
923
305
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
924 class T06References(unittest.TestCase):
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
925
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
926 def setUp(self):
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
927 self._reset()
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
928 self._cfg = configmix.load(
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
929 os.path.join(TESTDATADIR, "conf20.yml"),
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
930 os.path.join(TESTDATADIR, "conf21.yml"),
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
931 os.path.join(TESTDATADIR, "conf22.ini"),
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
932 os.path.join(TESTDATADIR, "conf23.json"),
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
933 os.path.join(TESTDATADIR, "conf24.toml"),
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
934 os.path.join(TESTDATADIR, "reference-style.yml"))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
935
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
936 def tearDown(self):
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
937 self._reset()
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
938
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
939 def _reset(self):
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
940 configmix.clear_assoc()
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
941 for pat, fmode in configmix.DEFAULT_ASSOC:
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
942 configmix.set_assoc(pat, fmode)
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
943
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
944 def test01_reference_without_expansions(self):
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
945 self.assertTrue(isinstance(self._cfg.getvar("wsgi.profiler"), dict))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
946 self.assertTrue(isinstance(
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
947 self._cfg.getvar("wsgi.profiler.params"), dict))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
948 self.assertEqual("werkzeug",
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
949 self._cfg.getvar("wsgi.profiler.params.type"))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
950 self.assertTrue(self._cfg.getvar("wsgi.profiler.params.params.evalex"))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
951 self.assertEqual(self._cfg.getvar("wsgi.debugger"),
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
952 self._cfg.getvar("wsgi.profiler.params"))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
953
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
954 def test01_reference_without_expansions_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
955 self.assertTrue(isinstance(self._cfg.getvarl("wsgi", "profiler"), dict))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
956 self.assertTrue(isinstance(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
957 self._cfg.getvarl("wsgi", "profiler", "params"), dict))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
958 self.assertEqual(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
959 "werkzeug",
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
960 self._cfg.getvarl("wsgi", "profiler", "params", "type"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
961 self.assertTrue(self._cfg.getvarl(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
962 "wsgi", "profiler", "params", "params", "evalex"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
963 self.assertEqual(self._cfg.getvarl("wsgi", "debugger"),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
964 self._cfg.getvarl("wsgi", "profiler", "params"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
965
305
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
966 def test02_reference__with_expansions(self):
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
967 self.assertTrue(isinstance(self._cfg.getvar_s("wsgi.profiler"), dict))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
968 self.assertTrue(isinstance(
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
969 self._cfg.getvar_s("wsgi.profiler.params"), dict))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
970 self.assertTrue(
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
971 self._cfg.getvar_s("wsgi.profiler.params.params.evalex"))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
972 self.assertEqual("werkzeug",
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
973 self._cfg.getvar_s("wsgi.profiler.params.type"))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
974
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
975 def test02_reference__with_expansions_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
976 self.assertTrue(isinstance(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
977 self._cfg.getvarl_s("wsgi", "profiler"), dict))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
978 self.assertTrue(isinstance(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
979 self._cfg.getvarl_s("wsgi", "profiler", "params"), dict))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
980 self.assertTrue(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
981 self._cfg.getvarl_s("wsgi", "profiler", "params", "params", "evalex"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
982 self.assertEqual(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
983 "werkzeug",
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
984 self._cfg.getvarl_s("wsgi", "profiler", "params", "type"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
985
305
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
986 def test03_no_direct_attribute_access_to_expanded_references(self):
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
987 self.assertEqual(
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
988 "{{ref:#wsgi.debugger}}",
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
989 self._cfg.wsgi.profiler.params)
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
990 try:
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
991 self._cfg.wsgi.profiler.params.type
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
992 except AttributeError:
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
993 pass
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
994 else:
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
995 self.fail("no attribute error seen")
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
996
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
997 def test04_indirect_recursive_references(self):
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
998 self.assertEqual(
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
999 "werkzeug",
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
1000 self._cfg.getvar_s("testref.here.params.type"))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
1001 self.assertTrue(
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
1002 self._cfg.getvar_s("testref.here.params.params.evalex"))
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
1003
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1004 def test04_indirect_recursive_references_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1005 self.assertEqual(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1006 "werkzeug",
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1007 self._cfg.getvarl_s("testref", "here", "params", "type"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1008 self.assertTrue(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1009 self._cfg.getvarl_s("testref", "here", "params", "params", "evalex"))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1010
305
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
1011 def test05_recursive_expansion(self):
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
1012 c = self._cfg.getvar_s("testref")
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
1013 self.assertTrue(c["here"]["params"]["params"]["evalex"])
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
1014
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1015 def test05_recursive_expansion_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1016 c = self._cfg.getvarl_s("testref")
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1017 self.assertTrue(c["here"]["params"]["params"]["evalex"])
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1018
309
f77dba9fc164 New unittest for the behaviour of ".getvar()" with regard to config references
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
1019 def test06_no_recursive_expansion_in_getvar_parents(self):
f77dba9fc164 New unittest for the behaviour of ".getvar()" with regard to config references
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
1020 v = self._cfg.getvar("wsgi.profiler")
f77dba9fc164 New unittest for the behaviour of ".getvar()" with regard to config references
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
1021 self.assertEqual(
f77dba9fc164 New unittest for the behaviour of ".getvar()" with regard to config references
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
1022 "{{ref:#wsgi.debugger}}",
f77dba9fc164 New unittest for the behaviour of ".getvar()" with regard to config references
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
1023 v["params"])
f77dba9fc164 New unittest for the behaviour of ".getvar()" with regard to config references
Franz Glasner <fzglas.hg@dom66.de>
parents: 305
diff changeset
1024
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1025 def test06_no_recursive_expansion_in_getvar_parents_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1026 v = self._cfg.getvarl("wsgi", "profiler")
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1027 self.assertEqual(
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1028 "{{ref:#wsgi.debugger}}",
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1029 v["params"])
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1030
312
0788e8e162f6 Unittests for explicit expansion of configuration references
Franz Glasner <fzglas.hg@dom66.de>
parents: 309
diff changeset
1031 def test07_explicit_reference_expansion(self):
0788e8e162f6 Unittests for explicit expansion of configuration references
Franz Glasner <fzglas.hg@dom66.de>
parents: 309
diff changeset
1032 v = self._cfg.getvar("wsgi.profiler")
0788e8e162f6 Unittests for explicit expansion of configuration references
Franz Glasner <fzglas.hg@dom66.de>
parents: 309
diff changeset
1033 self.assertTrue(isinstance(self._cfg.expand_if_reference(v["params"]),
0788e8e162f6 Unittests for explicit expansion of configuration references
Franz Glasner <fzglas.hg@dom66.de>
parents: 309
diff changeset
1034 dict))
0788e8e162f6 Unittests for explicit expansion of configuration references
Franz Glasner <fzglas.hg@dom66.de>
parents: 309
diff changeset
1035
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1036 def test07_explicit_reference_expansion_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1037 v = self._cfg.getvarl("wsgi", "profiler")
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1038 self.assertTrue(isinstance(self._cfg.expand_if_reference(v["params"]),
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1039 dict))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1040
313
15a1d5fd0aa1 Further unittest for config reference expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 312
diff changeset
1041 def test08_explicit_indirect_expansion_through_value(self):
15a1d5fd0aa1 Further unittest for config reference expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 312
diff changeset
1042 v = self._cfg.getvar_s("expand-ref-value.key0")
15a1d5fd0aa1 Further unittest for config reference expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 312
diff changeset
1043 self.assertTrue(isinstance(v, bool))
15a1d5fd0aa1 Further unittest for config reference expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 312
diff changeset
1044 self.assertTrue(v)
15a1d5fd0aa1 Further unittest for config reference expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 312
diff changeset
1045 # but not that .getvar does not **not**
15a1d5fd0aa1 Further unittest for config reference expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 312
diff changeset
1046 v2 = self._cfg.getvar("expand-ref-value.key0")
15a1d5fd0aa1 Further unittest for config reference expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 312
diff changeset
1047 self.assertEqual("{{testref.here.params.params.evalex}}", v2)
15a1d5fd0aa1 Further unittest for config reference expansion
Franz Glasner <fzglas.hg@dom66.de>
parents: 312
diff changeset
1048
314
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1049 def test08_explicit_indirect_expansion_through_value_l(self):
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1050 v = self._cfg.getvarl_s("expand-ref-value", "key0")
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1051 self.assertTrue(isinstance(v, bool))
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1052 self.assertTrue(v)
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1053 # but not that .getvar does not **not**
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1054 v2 = self._cfg.getvarl("expand-ref-value", "key0")
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1055 self.assertEqual("{{testref.here.params.params.evalex}}", v2)
043a6412be3c Implemented new access methods .getvarl() and .getvarl_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 313
diff changeset
1056
305
f529ca46dd50 Implemented the "ref" namespace to get configuration tree references.
Franz Glasner <fzglas.hg@dom66.de>
parents: 301
diff changeset
1057
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1058 class T07Quoting(unittest.TestCase):
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1059
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1060 def setUp(self):
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1061 self._reset()
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1062 self._cfg = configmix.load(os.path.join(TESTDATADIR, "quoting.yml"))
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1063
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1064 def tearDown(self):
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1065 self._reset()
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1066
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1067 def _reset(self):
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1068 configmix.clear_assoc()
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1069 for pat, fmode in configmix.DEFAULT_ASSOC:
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1070 configmix.set_assoc(pat, fmode)
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1071
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1072 def test_getvar(self):
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1073 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1074 "value",
325
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1075 self._cfg.getvar("%x23%x3a%x7c%x25%x2e.%x2e.%x3a.%x25.%x7c./.%x23"))
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1076 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1077 "value",
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1078 self._cfg.getvar(
325
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1079 "%u0023%u003a%u007c%u0025%u002e.%u002e.%u003a.%u0025.%u007c./.%u0023"))
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1080 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1081 "value",
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1082 self._cfg.getvar(
325
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1083 "%U00000023%U0000003a%U0000007c%U00000025%U0000002e.%U0000002e.%U0000003a.%U00000025.%U0000007c./.%U00000023"))
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1084
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1085 def test_getvar_s(self):
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1086 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1087 "value",
325
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1088 self._cfg.getvar_s("%x23%x3a%x7c%x25%x2e.%x2e.%x3a.%x25.%x7c./.%x23"))
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1089 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1090 "value",
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1091 self._cfg.getvar_s(
325
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1092 "%u0023%u003a%u007c%u0025%u002e.%u002e.%u003a.%u0025.%u007c./.%u0023"))
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1093 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1094 "value",
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1095 self._cfg.getvar_s(
325
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1096 "%U00000023%U0000003a%U0000007c%U00000025%U0000002e.%U0000002e.%U0000003a.%U00000025.%U0000007c./.%U00000023"))
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1097
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1098 def test_getvarl(self):
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1099 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1100 "value",
325
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1101 self._cfg.getvarl("#:|%.", ".", ":", "%", "|", "/", "#"))
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1102
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1103 def test_getvarl_s(self):
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1104 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1105 "value",
325
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1106 self._cfg.getvarl_s("#:|%.", ".", ":", "%", "|", "/", "#"))
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1107
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1108 def test_interpolation1(self):
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1109 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1110 "value",
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1111 self._cfg.getvarl_s("events", "qc-2021.1-5G-summit", "xname"))
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1112
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1113 def test_interpolation2(self):
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1114 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1115 "value",
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1116 self._cfg.getvar_s("events.qc-2021%x2e1-5G-summit.xname"))
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1117
325
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1118 def test_reference1(self):
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1119 self.assertTrue(
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1120 isinstance(
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1121 self._cfg.getvar_s("events.qc-2021%x2e1-5G-summit.xref"),
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1122 dict))
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1123
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1124 def test_reference2(self):
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1125 self.assertEqual(
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1126 "value",
325
ab33d51f3412 By default quote the "#" character also because it is typically a comment in all the configuration file formats.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
1127 self._cfg.getvar_s("events.qc-2021%x2e1-5G-summit.xref.%x23"))
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1128
327
30f8dce82850 Test that quote() and unquote() are inverse
Franz Glasner <fzglas.hg@dom66.de>
parents: 325
diff changeset
1129 def test_quoting_and_unquoting_are_inverse(self):
336
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1130 for c in """%.:#|"'{}[]""":
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1131 qc = self._cfg.quote(c)
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1132 self.assertTrue(qc.startswith("%x") and len(qc) == 4)
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1133 self.assertEqual(c, self._cfg.unquote(qc))
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1134
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1135 def test_quoting_and_unquoting_are_identical(self):
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1136 # other characters
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1137 for c in """abc09/""":
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1138 qc = self._cfg.quote(c)
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1139 self.assertEqual(c, qc)
7692c91bb370 Tests: more thorough tests of identity and inverse quoting
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 335
diff changeset
1140 self.assertEqual(c, self._cfg.unquote(qc))
327
30f8dce82850 Test that quote() and unquote() are inverse
Franz Glasner <fzglas.hg@dom66.de>
parents: 325
diff changeset
1141
329
d81d2cdf4925 FIX: Handle the unquoting of namespaces within Configuration.getvar() properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 327
diff changeset
1142 def test_namespace_quoting(self):
d81d2cdf4925 FIX: Handle the unquoting of namespaces within Configuration.getvar() properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 327
diff changeset
1143 v1 = self._cfg.getvar("PY:version")
d81d2cdf4925 FIX: Handle the unquoting of namespaces within Configuration.getvar() properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 327
diff changeset
1144 v2 = self._cfg.getvar("P%x59:version")
331
4f31e69d1ad5 Tests: for namespace quoting use some encoding variants also
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
1145 v3 = self._cfg.getvar("%U00000050Y:version")
4f31e69d1ad5 Tests: for namespace quoting use some encoding variants also
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
1146 v4 = self._cfg.getvar("%x50%u0059:version")
332
5c2c72d26b63 Tests: add a test for variable interpolation with a quoted namespace
Franz Glasner <fzglas.hg@dom66.de>
parents: 331
diff changeset
1147 v5 = self._cfg.getvarl_s("events", "qc-2021.1-5G-summit", "xver")
338
933df3ffd428 Tests: add some more asserte to test_namespace_quoting
Franz Glasner <fzglas.hg@dom66.de>
parents: 337
diff changeset
1148 v6 = self._cfg.getvar_s("events.qc-2021%x2e1-5G-summit.xver")
329
d81d2cdf4925 FIX: Handle the unquoting of namespaces within Configuration.getvar() properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 327
diff changeset
1149 self.assertEqual(v1, v2)
d81d2cdf4925 FIX: Handle the unquoting of namespaces within Configuration.getvar() properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 327
diff changeset
1150 self.assertEqual(v1, v3)
d81d2cdf4925 FIX: Handle the unquoting of namespaces within Configuration.getvar() properly.
Franz Glasner <fzglas.hg@dom66.de>
parents: 327
diff changeset
1151 self.assertEqual(v1, v4)
337
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 336
diff changeset
1152 self.assertEqual(v1, v5)
338
933df3ffd428 Tests: add some more asserte to test_namespace_quoting
Franz Glasner <fzglas.hg@dom66.de>
parents: 337
diff changeset
1153 self.assertEqual(v1, v6)
320
98490375d90c Allow variable name quoting to be used in .getvar() and .getvar_s() and references
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
1154
340
176e22110fc5 docs, tests: notes and additional tests when quoting the "ref" namespace name
Franz Glasner <fzglas.hg@dom66.de>
parents: 338
diff changeset
1155 def test_direct_ref_namespace_quoting(self):
176e22110fc5 docs, tests: notes and additional tests when quoting the "ref" namespace name
Franz Glasner <fzglas.hg@dom66.de>
parents: 338
diff changeset
1156 v = self._cfg.getvar_s("re%x66:#%x23%u003a%x7c%U00000025%x2e.%x2e.%x3a.%x25.%x7c./.%x23")
176e22110fc5 docs, tests: notes and additional tests when quoting the "ref" namespace name
Franz Glasner <fzglas.hg@dom66.de>
parents: 338
diff changeset
1157 self.assertEqual("value", v)
176e22110fc5 docs, tests: notes and additional tests when quoting the "ref" namespace name
Franz Glasner <fzglas.hg@dom66.de>
parents: 338
diff changeset
1158
330
Franz Glasner <fzglas.hg@dom66.de>
parents: 329
diff changeset
1159
395
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1160 class T08Jailed(unittest.TestCase):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1161
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1162 def setUp(self):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1163 pass
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1164
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1165 def tearDown(self):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1166 self._reset()
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1167
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1168 def _reset(self):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1169 configmix.clear_assoc()
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1170 for pat, fmode in configmix.DEFAULT_ASSOC:
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1171 configmix.set_assoc(pat, fmode)
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1172
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1173 def test_root(self):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1174 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1175 jcfg = cfg.jailed(root=u"tree1")
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1176
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1177 self.assertTrue(jcfg.getvarl(u"tree2", u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1178 self.assertTrue(jcfg.getvarl_s(u"tree2", u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1179 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1180 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1181 jcfg.getvarl(u"tree2", u"key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1182 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1183 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1184 jcfg.getvarl_s(u"tree2", u"key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1185
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1186 self.assertTrue(jcfg.getvar(u"tree2.key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1187 self.assertTrue(jcfg.getvar_s(u"tree2.key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1188 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1189 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1190 jcfg.getvar(u"tree2.key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1191 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1192 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1193 jcfg.getvar_s(u"tree2.key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1194
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1195 def test_root2(self):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1196 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1197 jcfg = cfg.jailed(root=u"tree1.tree2")
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1198
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1199 self.assertTrue(jcfg.getvarl(u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1200 self.assertTrue(jcfg.getvarl_s(u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1201 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1202 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1203 jcfg.getvarl(u"key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1204 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1205 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1206 jcfg.getvarl_s(u"key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1207
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1208 self.assertTrue(jcfg.getvar(u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1209 self.assertTrue(jcfg.getvar_s(u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1210 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1211 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1212 jcfg.getvar(u"key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1213 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1214 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1215 jcfg.getvar_s(u"key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1216
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1217 def test_root_non_existing_raises(self):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1218 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1219 self.assertRaises(KeyError, cfg.jailed, root=u"tree-non-existing")
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1220
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1221 def test_rootpath(self):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1222 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1223 jcfg = cfg.jailed(rootpath=[u"tree1"])
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1224
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1225 self.assertTrue(jcfg.getvarl(u"tree2", u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1226 self.assertTrue(jcfg.getvarl_s(u"tree2", u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1227 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1228 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1229 jcfg.getvarl_s(u"tree2", u"key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1230
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1231 self.assertTrue(jcfg.getvar(u"tree2.key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1232 self.assertTrue(jcfg.getvar_s(u"tree2.key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1233 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1234 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1235 jcfg.getvar_s(u"tree2.key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1236
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1237 def test_rootpath_non_existing_raises(self):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1238 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1239 self.assertRaises(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1240 KeyError, cfg.jailed, rootpath=[u"tree-non-existing"])
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1241
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1242 def test_root_empty(self):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1243 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
416
2abde0d3c735 FIX: Handle .jailed() with an empty "root" properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 412
diff changeset
1244 jcfg = cfg.jailed(root=u"")
395
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1245
417
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1246 self.assertFalse(jcfg._path)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1247 self.assertFalse(jcfg._pathstr)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1248 self.assertTrue(jcfg._path is not None)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1249 self.assertTrue(jcfg._pathstr is not None)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1250
395
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1251 self.assertTrue(jcfg.getvarl(u"tree1", u"tree2", u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1252 self.assertTrue(jcfg.getvarl_s(u"tree1", u"tree2", u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1253 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1254 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1255 jcfg.getvarl_s(u"tree1", u"tree2", u"key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1256
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1257 self.assertTrue(jcfg.getvar(u"tree1.tree2.key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1258 self.assertTrue(jcfg.getvar_s(u"tree1.tree2.key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1259 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1260 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1261 jcfg.getvar_s(u"tree1.tree2.key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1262
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1263 def test_rootpath_empty(self):
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1264 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1265 jcfg = cfg.jailed(rootpath=tuple())
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1266
417
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1267 self.assertFalse(jcfg._path)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1268 self.assertFalse(jcfg._pathstr)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1269 self.assertTrue(jcfg._path is not None)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1270 self.assertTrue(jcfg._pathstr is not None)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1271
395
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1272 self.assertTrue(jcfg.getvarl(u"tree1", u"tree2", u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1273 self.assertTrue(jcfg.getvarl_s(u"tree1", u"tree2", u"key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1274 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1275 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1276 jcfg.getvarl_s(u"tree1", u"tree2", u"key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1277
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1278 self.assertTrue(jcfg.getvar(u"tree1.tree2.key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1279 self.assertTrue(jcfg.getvar_s(u"tree1.tree2.key5"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1280 self.assertEqual(
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1281 u"get this as `tree1.tree2.key4'",
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1282 jcfg.getvar_s(u"tree1.tree2.key4"))
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1283
398
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1284 def test_rootpath_getfirstvar_nonexisting(self):
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1285 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1286 jcfg = cfg.jailed(rootpath=(u"tree1",))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1287
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1288 self.assertIsNone(jcfg.getfirstvarl(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1289 *[(u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1290 (u"tree2", u"no-key")],
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1291 default=None))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1292 self.assertIsNone(jcfg.getfirstvarl_s(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1293 *[(u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1294 (u"tree2", u"no-key")],
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1295 default=None))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1296 self.assertIsNone(jcfg.getfirstvar(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1297 u"a.b", u"tree2.no-key",
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1298 default=None))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1299 self.assertIsNone(jcfg.getfirstvar_s(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1300 u"a.b", u"tree2.no-key",
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1301 default=None))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1302
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1303 def test_rootpath_getfirstvar_raising(self):
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1304 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1305 jcfg = cfg.jailed(rootpath=(u"tree1",))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1306
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1307 self.assertRaises(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1308 KeyError,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1309 jcfg.getfirstvarl,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1310 (u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1311 (u"tree2", u"no-key"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1312 self.assertRaises(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1313 KeyError,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1314 jcfg.getfirstvarl_s,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1315 (u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1316 (u"tree2", u"no-key"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1317 self.assertRaises(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1318 KeyError,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1319 jcfg.getfirstvar,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1320 u"a.b", u"tree2.no-key")
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1321 self.assertRaises(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1322 KeyError,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1323 jcfg.getfirstvar_s,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1324 u"a.b", u"tree2.no-key")
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1325
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1326 def test_rootpath_getfirstvar_existing(self):
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1327 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1328 jcfg = cfg.jailed(rootpath=(u"tree1",))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1329
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1330 self.assertEqual(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1331 u"get this as `tree1.tree2.key4'",
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1332 jcfg.getfirstvarl(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1333 *[(u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1334 (u"tree2", u"key4")]))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1335 self.assertEqual(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1336 0x20,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1337 jcfg.getfirstvarl_s(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1338 *[(u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1339 (u"key3", ),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1340 (u"tree2", u"key4")]))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1341 self.assertEqual(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1342 0x20,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1343 jcfg.getfirstvar(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1344 u"key1", u"key3"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1345 self.assertEqual(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1346 u"get this as `tree1.tree2.key4'",
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1347 jcfg.getfirstvar_s(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1348 u"a.b", u"tree2.key4", u"tree2.key5"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1349
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1350 def test_root_getfirstvar_nonexisting(self):
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1351 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1352 jcfg = cfg.jailed(root=u"tree1")
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1353
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1354 self.assertIsNone(jcfg.getfirstvarl(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1355 *[(u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1356 (u"tree2", u"no-key")],
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1357 default=None))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1358 self.assertIsNone(jcfg.getfirstvarl_s(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1359 *[(u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1360 (u"tree2", u"no-key")],
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1361 default=None))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1362 self.assertIsNone(jcfg.getfirstvarl_s(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1363 *[(u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1364 (u"tree2", u"no-key")],
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1365 default=None))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1366 self.assertIsNone(jcfg.getfirstvar_s(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1367 u"a.b", u"tree2.no-key",
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1368 default=None))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1369
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1370 def test_root_getfirstvar_raising(self):
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1371 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1372 jcfg = cfg.jailed(root=u"tree1")
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1373
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1374 self.assertRaises(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1375 KeyError,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1376 jcfg.getfirstvarl,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1377 (u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1378 (u"tree2", u"no-key"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1379 self.assertRaises(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1380 KeyError,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1381 jcfg.getfirstvarl_s,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1382 (u"a", u"b"),
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1383 (u"tree2", u"no-key"))
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1384 self.assertRaises(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1385 KeyError,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1386 jcfg.getfirstvar,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1387 u"a.b", u"tree2.no-key")
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1388 self.assertRaises(
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1389 KeyError,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1390 jcfg.getfirstvar_s,
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1391 u"a.b", u"tree2.no-key")
b1f82b853290 Jailed configuration: implement more methods: getfirstvarl, getfirstvarl_s, getfirstvar and getfirstvar_s
Franz Glasner <fzglas.hg@dom66.de>
parents: 395
diff changeset
1392
407
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1393 def test_base_rebind(self):
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1394 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1395 self.assertFalse(cfg.is_jail)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1396
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1397 jcfg = cfg.jailed(rootpath=[])
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1398 self.assertTrue(jcfg.is_jail)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1399
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1400 self.assertTrue(jcfg.base is cfg)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1401
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1402 self.assertRaises(
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1403 KeyError,
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1404 jcfg.getvarl,
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1405 u"tree1", u"tree2", u"no-key")
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1406 self.assertEqual(
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1407 0x20,
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1408 jcfg.getvar(u"tree1.key3"))
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1409 self.assertEqual(
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1410 u"in the root namespace",
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1411 jcfg.getvar("key1"))
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1412
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1413 cfg2 = configmix.load(os.path.join(TESTDATADIR, "conf2.py"))
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1414 self.assertFalse(cfg2.is_jail)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1415
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1416 jcfg.rebind(cfg2)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1417 self.assertTrue(jcfg.base is cfg2)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1418
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1419 self.assertRaises(
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1420 KeyError,
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1421 jcfg.getvar,
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1422 u"tree1.key3")
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1423 self.assertEqual(
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1424 u"the next value",
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1425 jcfg.getvar("key1"))
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1426
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1427 def test_rebind_no_nesting(self):
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1428 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1429 self.assertFalse(cfg.is_jail)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1430
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1431 jcfg1 = cfg.jailed(rootpath=[])
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1432 self.assertTrue(jcfg1.is_jail)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1433 jcfg2 = cfg.jailed(rootpath=[u"tree1"])
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1434 self.assertTrue(jcfg2.is_jail)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1435
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1436 self.assertRaises(
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1437 TypeError,
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1438 jcfg1.rebind,
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1439 jcfg2)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1440
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1441 # base is not because rebind() failed
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1442 self.assertTrue(cfg is jcfg1.base)
1bec7f5fafe8 Unittests for the new base and rebind features
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 404
diff changeset
1443
412
816327e178b0 Provide coercing methods for the jailed configuration: getintXXX(), getboolXXX(), getfloatXXX() and friends.
Franz Glasner <fzglas.hg@dom66.de>
parents: 407
diff changeset
1444 def test_getbool(self):
816327e178b0 Provide coercing methods for the jailed configuration: getintXXX(), getboolXXX(), getfloatXXX() and friends.
Franz Glasner <fzglas.hg@dom66.de>
parents: 407
diff changeset
1445 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
816327e178b0 Provide coercing methods for the jailed configuration: getintXXX(), getboolXXX(), getfloatXXX() and friends.
Franz Glasner <fzglas.hg@dom66.de>
parents: 407
diff changeset
1446 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2"))
816327e178b0 Provide coercing methods for the jailed configuration: getintXXX(), getboolXXX(), getfloatXXX() and friends.
Franz Glasner <fzglas.hg@dom66.de>
parents: 407
diff changeset
1447
816327e178b0 Provide coercing methods for the jailed configuration: getintXXX(), getboolXXX(), getfloatXXX() and friends.
Franz Glasner <fzglas.hg@dom66.de>
parents: 407
diff changeset
1448 self.assertFalse(jcfg.getboolvar_s(u"key6"))
816327e178b0 Provide coercing methods for the jailed configuration: getintXXX(), getboolXXX(), getfloatXXX() and friends.
Franz Glasner <fzglas.hg@dom66.de>
parents: 407
diff changeset
1449 self.assertEqual(u"off", jcfg.getvarl_s(u"key6"))
816327e178b0 Provide coercing methods for the jailed configuration: getintXXX(), getboolXXX(), getfloatXXX() and friends.
Franz Glasner <fzglas.hg@dom66.de>
parents: 407
diff changeset
1450 self.assertTrue(jcfg.getvar_s(u"key6"))
816327e178b0 Provide coercing methods for the jailed configuration: getintXXX(), getboolXXX(), getfloatXXX() and friends.
Franz Glasner <fzglas.hg@dom66.de>
parents: 407
diff changeset
1451
417
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1452 def test_subjail_from_rootpath_empty(self):
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1453 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1454 jcfg = cfg.jailed(rootpath=tuple())
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1455
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1456 sjcfg = jcfg.jailed(rootpath=(u"tree1",))
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1457
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1458 self.assertTrue(sjcfg._path)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1459 self.assertTrue(sjcfg._pathstr)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1460
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1461 self.assertEqual(0x20, sjcfg.getintvar_s(u"key3"))
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1462
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1463 def test_subjail_from_root_empty(self):
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1464 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1465 jcfg = cfg.jailed(root=u"")
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1466
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1467 sjcfg = jcfg.jailed(root=u"tree1")
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1468
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1469 self.assertTrue(sjcfg._path)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1470 self.assertTrue(sjcfg._pathstr)
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1471
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1472 self.assertEqual(0x20, sjcfg.getintvar_s(u"key3"))
83d537f1dfbb Implement sub-jails: allow to get a jailed configuration from a jail
Franz Glasner <fzglas.hg@dom66.de>
parents: 416
diff changeset
1473
395
0b3ffc34fa5c Begin a jailed configuration with access to a sub-tree of the original configuration
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 390
diff changeset
1474
93
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
1475 if __name__ == "__main__":
84b9578cacce Start with unit tests
Franz Glasner <hg@dom66.de>
parents:
diff changeset
1476 unittest.main()