|
@@ -10,6 +10,13 @@ def dummy_validator(value): return value
|
10
|
10
|
#A dummy validator that always fails
|
11
|
11
|
def dummy_validator_fails(value): raise ValueError("Fake validation error")
|
12
|
12
|
|
|
13
|
+def write_list_validator(value):
|
|
14
|
+ res = ''
|
|
15
|
+ errors = list()
|
|
16
|
+ for elt in value:
|
|
17
|
+ res += dummy_validator(elt) + ','
|
|
18
|
+ return res[:len(res)-1]
|
|
19
|
+
|
13
|
20
|
class SettingsLoaderTestCase(unittest.TestCase):
|
14
|
21
|
|
15
|
22
|
def test_merge_getsection(self):
|
|
@@ -79,8 +86,8 @@ class SettingsLoaderTestCase(unittest.TestCase):
|
79
|
86
|
value = loader.getoption('lodel2.foo.bar', 'foofoofoo', dummy_validator, 'hello 42', False)
|
80
|
87
|
self.assertEqual(value, 'hello 42')
|
81
|
88
|
# for non existing section in file
|
82
|
|
- value = loader.getoption('lodel2.foofoo', 'foofoofoo', dummy_validator, 'hello 42', False)
|
83
|
|
- self.assertEqual(value, 'hello 42')
|
|
89
|
+ # value = loader.getoption('lodel2.foofoo', 'foofoofoo', dummy_validator, 'hello 42', False)
|
|
90
|
+ # self.assertEqual(value, 'hello 42')
|
84
|
91
|
|
85
|
92
|
def test_getoption_complex(self):
|
86
|
93
|
""" Testing behavior of getoption with less simple files & confs """
|
|
@@ -162,4 +169,60 @@ class SettingsLoaderTestCase(unittest.TestCase):
|
162
|
169
|
expt_rem.remove('%s:%s' % (section, val))
|
163
|
170
|
self.assertEqual( sorted(expt_rem),
|
164
|
171
|
sorted(loader.getremains().keys()))
|
165
|
|
-
|
|
172
|
+ def test_setoption(self):
|
|
173
|
+ loader=SettingsLoader('tests/settings/settings_examples/conf_set.d')
|
|
174
|
+ loader.setoption('lodel2.A','fhui','test ok',dummy_validator)
|
|
175
|
+ loader=SettingsLoader('tests/settings/settings_examples/conf_set.d')
|
|
176
|
+ option=loader.getoption('lodel2.A','fhui',dummy_validator)
|
|
177
|
+ self.assertEqual(option,'test ok')
|
|
178
|
+ loader.setoption('lodel2.A','fhui','retour',dummy_validator)
|
|
179
|
+ loader=SettingsLoader('tests/settings/settings_examples/conf_set.d')
|
|
180
|
+ option=loader.getoption('lodel2.A','fhui',dummy_validator)
|
|
181
|
+ self.assertEqual(option,'retour')
|
|
182
|
+ cblist=('test ok1','test ok2','test ok3')
|
|
183
|
+ loader.setoption('lodel2.C','cb',cblist,write_list_validator)
|
|
184
|
+ loader=SettingsLoader('tests/settings/settings_examples/conf_set.d')
|
|
185
|
+ option=loader.getoption('lodel2.C','cb',dummy_validator)
|
|
186
|
+ self.assertEqual(option,'test ok1,test ok2,test ok3')
|
|
187
|
+ cblist=('b4','b2','b3')
|
|
188
|
+ loader.setoption('lodel2.C','cb',cblist,write_list_validator)
|
|
189
|
+ loader=SettingsLoader('tests/settings/settings_examples/conf_set.d')
|
|
190
|
+ option=loader.getoption('lodel2.C','cb',dummy_validator)
|
|
191
|
+ self.assertEqual(option,'b4,b2,b3')
|
|
192
|
+
|
|
193
|
+ def test_saveconf(self):
|
|
194
|
+ loader=SettingsLoader('tests/settings/settings_examples/conf_save.d')
|
|
195
|
+ newsec=dict()
|
|
196
|
+ newsec['lodel2.A'] = dict()
|
|
197
|
+ newsec['lodel2.A']['fhui'] = 'test ok'
|
|
198
|
+ newsec['lodel2.A']['c'] = 'test ok'
|
|
199
|
+ newsec['lodel2.A.e'] = dict()
|
|
200
|
+ newsec['lodel2.A.e']['a'] = 'test ok'
|
|
201
|
+ validators = dict()
|
|
202
|
+ validators['lodel2.A'] = dict()
|
|
203
|
+ validators['lodel2.A']['fhui'] = dummy_validator
|
|
204
|
+ validators['lodel2.A']['c'] = dummy_validator
|
|
205
|
+ validators['lodel2.A.e'] = dict()
|
|
206
|
+ validators['lodel2.A.e']['a'] = dummy_validator
|
|
207
|
+
|
|
208
|
+ loader.saveconf(newsec,validators)
|
|
209
|
+ loader=SettingsLoader('tests/settings/settings_examples/conf_save.d')
|
|
210
|
+ option=loader.getoption('lodel2.A','fhui',dummy_validator)
|
|
211
|
+ self.assertEqual(option,'test ok')
|
|
212
|
+ option=loader.getoption('lodel2.A','c',dummy_validator)
|
|
213
|
+ self.assertEqual(option,'test ok')
|
|
214
|
+ option=loader.getoption('lodel2.A.e','a',dummy_validator)
|
|
215
|
+ self.assertEqual(option,'test ok')
|
|
216
|
+
|
|
217
|
+ newsec['lodel2.A']['fhui']='retour'
|
|
218
|
+ newsec['lodel2.A']['c']='toto'
|
|
219
|
+ newsec['lodel2.A.e']['a']='ft'
|
|
220
|
+
|
|
221
|
+ loader.saveconf(newsec,validators)
|
|
222
|
+ loader=SettingsLoader('tests/settings/settings_examples/conf_save.d')
|
|
223
|
+ option=loader.getoption('lodel2.A','fhui',dummy_validator)
|
|
224
|
+ self.assertEqual(option,'retour')
|
|
225
|
+ option=loader.getoption('lodel2.A','c',dummy_validator)
|
|
226
|
+ self.assertEqual(option,'toto')
|
|
227
|
+ option=loader.getoption('lodel2.A.e','a',dummy_validator)
|
|
228
|
+ self.assertEqual(option,'ft')
|