|
@@ -2,9 +2,14 @@
|
2
|
2
|
|
3
|
3
|
import unittest
|
4
|
4
|
|
5
|
|
-import tests.loader_utils
|
|
5
|
+#import tests.loader_utils
|
6
|
6
|
from lodel.settings.settings_loader import SettingsLoader
|
7
|
7
|
|
|
8
|
+#A dummy validator that only returns the value
|
|
9
|
+def dummy_validator(value): return value
|
|
10
|
+#A dummy validator that always fails
|
|
11
|
+def dummy_validator_fails(value): raise ValueError("Fake validaion error")
|
|
12
|
+
|
8
|
13
|
class SettingsLoaderTestCase(unittest.TestCase):
|
9
|
14
|
|
10
|
15
|
def test_merge_getsection(self):
|
|
@@ -40,5 +45,32 @@ class SettingsLoaderTestCase(unittest.TestCase):
|
40
|
45
|
g=settings.getremains()
|
41
|
46
|
self.assertEqual(g,[])
|
42
|
47
|
|
|
48
|
+
|
|
49
|
+ def test_getoption_simple(self):
|
|
50
|
+ """ Testing behavior of getoption """
|
|
51
|
+ loader = SettingsLoader('tests/settings/settings_examples/simple.conf.d')
|
|
52
|
+ value = loader.getoption('lodel2.foo.bar', 'foo', dummy_validator)
|
|
53
|
+ self.assertEqual(value, "42")
|
|
54
|
+ value = loader.getoption('lodel2.foo.bar', 'foobar', dummy_validator)
|
|
55
|
+ self.assertEqual(value, "hello world")
|
|
56
|
+
|
|
57
|
+ def test_variable_sections(self):
|
|
58
|
+ """ Testing variable section recognition """
|
|
59
|
+ loader = SettingsLoader('tests/settings/settings_examples/var_sections.conf.d')
|
|
60
|
+ sections = loader.getsection('lodel2.tests')
|
|
61
|
+ self.assertEqual( set(sections),
|
|
62
|
+ set(( 'lodel2.tests.section1',
|
|
63
|
+ 'lodel2.tests.section2')))
|
|
64
|
+
|
|
65
|
+ def test_variable_sections_default(self):
|
|
66
|
+ """ Testing variable section default value handling """
|
|
67
|
+ loader = SettingsLoader('tests/settings/settings_examples/var_sections.conf.d')
|
|
68
|
+ sections = loader.getsection('lodel2.notexisting', 'foobar')
|
|
69
|
+ self.assertEqual(set(sections), set(('lodel2.foobar',)))
|
43
|
70
|
|
44
|
|
-
|
|
71
|
+ def test_variable_sections_fails(self):
|
|
72
|
+ """ Testing behavior when no default section given for a non existing variable section """
|
|
73
|
+ loader = SettingsLoader('tests/settings/settings_examples/var_sections.conf.d')
|
|
74
|
+ with self.assertRaises(NameError):
|
|
75
|
+ sections = loader.getsection('lodel2.notexisting')
|
|
76
|
+
|