|
@@ -1,10 +1,13 @@
|
1
|
1
|
#-*- coding: utf-8 -*-
|
2
|
2
|
|
3
|
3
|
import unittest
|
|
4
|
+import os.path
|
4
|
5
|
|
5
|
6
|
from lodel.settings.utils import *
|
6
|
7
|
from lodel.settings.settings_loader import SettingsLoader
|
7
|
8
|
|
|
9
|
+
|
|
10
|
+
|
8
|
11
|
#A dummy validator that only returns the value
|
9
|
12
|
def dummy_validator(value): return value
|
10
|
13
|
#A dummy validator that always fails
|
|
@@ -86,8 +89,8 @@ class SettingsLoaderTestCase(unittest.TestCase):
|
86
|
89
|
value = loader.getoption('lodel2.foo.bar', 'foofoofoo', dummy_validator, 'hello 42', False)
|
87
|
90
|
self.assertEqual(value, 'hello 42')
|
88
|
91
|
# for non existing section in file
|
89
|
|
- # value = loader.getoption('lodel2.foofoo', 'foofoofoo', dummy_validator, 'hello 42', False)
|
90
|
|
- # self.assertEqual(value, 'hello 42')
|
|
92
|
+ value = loader.getoption('lodel2.foofoo', 'foofoofoo', dummy_validator, 'hello 42', False)
|
|
93
|
+ self.assertEqual(value, 'hello 42')
|
91
|
94
|
|
92
|
95
|
def test_getoption_complex(self):
|
93
|
96
|
""" Testing behavior of getoption with less simple files & confs """
|
|
@@ -226,3 +229,26 @@ class SettingsLoaderTestCase(unittest.TestCase):
|
226
|
229
|
self.assertEqual(option,'toto')
|
227
|
230
|
option=loader.getoption('lodel2.A.e','a',dummy_validator)
|
228
|
231
|
self.assertEqual(option,'ft')
|
|
232
|
+
|
|
233
|
+ def test_setoption_default_value(self):
|
|
234
|
+ loader = SettingsLoader('tests/settings/settings_examples/conf_setdef.d')
|
|
235
|
+
|
|
236
|
+ # for non existing keys in file
|
|
237
|
+ value = loader.getoption('lodel2.foo.bar', 'foofoofoo', dummy_validator, 'hello 42', False)
|
|
238
|
+ self.assertEqual(value, 'hello 42')
|
|
239
|
+ # for non existing section in file
|
|
240
|
+ value = loader.getoption('lodel2.foofoo', 'foofoofoo', dummy_validator, 'hello 42', False)
|
|
241
|
+ self.assertEqual(value, 'hello 42')
|
|
242
|
+
|
|
243
|
+ loader.setoption('lodel2.foo.bar', 'foofoofoo', 'test ok', dummy_validator)
|
|
244
|
+ loader.setoption('lodel2.foofoo', 'foofoofoo', 'test ok', dummy_validator)
|
|
245
|
+ self.assertTrue(os.path.isfile('tests/settings/settings_examples/conf_setdef.d/generated.ini'))
|
|
246
|
+
|
|
247
|
+ loader = SettingsLoader('tests/settings/settings_examples/conf_setdef.d')
|
|
248
|
+ value = loader.getoption('lodel2.foofoo', 'foofoofoo', dummy_validator)
|
|
249
|
+ self.assertEqual(value, 'test ok')
|
|
250
|
+ value = loader.getoption('lodel2.foo.bar', 'foofoofoo', dummy_validator)
|
|
251
|
+ self.assertEqual(value, 'test ok')
|
|
252
|
+
|
|
253
|
+ os.remove('tests/settings/settings_examples/conf_setdef.d/generated.ini')
|
|
254
|
+
|