prieto 8 years ago
parent
commit
59342cd315

+ 4
- 3
lodel/settings/settings_loader.py View File

@@ -28,8 +28,10 @@ class SettingsLoader(object):
28 28
         l_dir = glob.glob(self.__conf_path+'/*.ini')  
29 29
 
30 30
         for f_ini in l_dir:  
31
-            config = configparser.ConfigParser(default_section = 'lodel2')
31
+            #To avoid the DEFAULT section whose values are found in all sections, we have to give it an unsual name
32
+            config = configparser.ConfigParser(default_section = 'lodel2_default_passaway_tip',interpolation=None)
32 33
             config.read(f_ini)
34
+
33 35
             for sect in config:
34 36
                 if sect in conf:
35 37
                     for param in config[sect]:
@@ -37,13 +39,12 @@ class SettingsLoader(object):
37 39
                             conf[sect][param] = config[sect][param]
38 40
                             if sect != 'DEFAULT': self.__conf_sv[sect + ':' + param]=f_ini
39 41
                         else:
40
-                            print(conf)
41 42
                             raise SettingsError("Key attribute already defined : %s " % sect + '.' + param + ' dans ' + f_ini + ' et ' + self.__conf_sv[sect + ':' + param])                        
42 43
                 else:
43 44
                     opts={}
44 45
                     for key in config[sect]:
45 46
                         opts[key] = config[sect].get(key)
46
-                        if sect != 'DEFAULT': self.__conf_sv[sect + ':' + key]=f_ini
47
+                        if sect != 'lodel2_default_passaway_tip': self.__conf_sv[sect + ':' + key]=f_ini
47 48
                     conf.update({sect: opts})
48 49
         os.close(dir_conf)
49 50
         return conf

+ 8
- 0
tests/settings/settings_examples/conf.d/a.ini View File

@@ -0,0 +1,8 @@
1
+[lodel2.A]
2
+a=a1
3
+b=b1,b2,b3
4
+c=toto
5
+[lodel2.A.e]
6
+titi=tata
7
+[lodel2.C]
8
+a=test

+ 3
- 0
tests/settings/settings_examples/conf.d/b.ini View File

@@ -0,0 +1,3 @@
1
+[lodel2.A]
2
+fhui=njl
3
+

+ 2
- 0
tests/settings/settings_examples/conf.d/c.ini View File

@@ -0,0 +1,2 @@
1
+[lodel2.A.e]
2
+a=ft

+ 8
- 0
tests/settings/settings_examples/conf.d/d.ini View File

@@ -0,0 +1,8 @@
1
+[lodel2.C]
2
+ca=a2
3
+cb=b4,b2,b3
4
+cc=titi
5
+[lodel2.B]
6
+ab=art
7
+bb=bj,kl,mn
8
+cb=tatat

+ 8
- 0
tests/settings/settings_examples/conf_raise.d/a.ini View File

@@ -0,0 +1,8 @@
1
+[A]
2
+a=a1
3
+b=b1,b2,b3
4
+c=toto
5
+[C]
6
+ca=a2
7
+cb=b4,b2,b3
8
+cc=titi

+ 8
- 0
tests/settings/settings_examples/conf_raise.d/b.ini View File

@@ -0,0 +1,8 @@
1
+[B]
2
+ab=art
3
+bb=bj,kl,mn
4
+cb=tatat
5
+[A]
6
+fhui=njl
7
+a=gh
8
+

+ 16
- 14
tests/settings/test_settings_loader.py View File

@@ -8,34 +8,36 @@ from lodel.settings.settings_loader import SettingsLoader
8 8
 #A dummy validator that only returns the value
9 9
 def dummy_validator(value): return value
10 10
 #A dummy validator that always fails
11
-def dummy_validator_fails(value):  raise ValueError("Fake validaion error") 
11
+def dummy_validator_fails(value):  raise ValueError("Fake validation error") 
12 12
 
13 13
 class SettingsLoaderTestCase(unittest.TestCase):
14 14
 
15 15
     def test_merge_getsection(self):
16 16
         """Tests merge and getSection functions """
17
-        settings = SettingsLoader('tests/settings/conf.d')
17
+        settings = SettingsLoader('tests/settings/settings_examples/conf.d')
18 18
         def maFonction(a):
19 19
             return a
20
-        e=settings.getoption('A','a',maFonction)
20
+        e=settings.getoption('lodel2.A','a',maFonction)
21 21
         self.assertEqual(e,'a1')
22
-        f=settings.getoption('B','bb',maFonction)
22
+        f=settings.getoption('lodel2.B','bb',maFonction)
23 23
         self.assertEqual(f,"bj,kl,mn")
24 24
         g=settings.getremains()
25 25
         self.assertIsNotNone(g)
26
-        e=settings.getoption('A','b',maFonction)
27
-        e=settings.getoption('A','c',maFonction)
28
-        e=settings.getoption('A','fhui',maFonction)
29
-        f=settings.getoption('B','ab',maFonction)
30
-        f=settings.getoption('B','cb',maFonction)
31
-        f=settings.getoption('C','cb',maFonction)
32
-        f=settings.getoption('C','ca',maFonction)
33
-        f=settings.getoption('C','cc',maFonction)
34
-        f=settings.getoption('C','a',maFonction)
26
+        e=settings.getoption('lodel2.A','b',maFonction)
27
+        e=settings.getoption('lodel2.A','c',maFonction)
28
+        e=settings.getoption('lodel2.A','fhui',maFonction)
29
+        f=settings.getoption('lodel2.B','ab',maFonction)
30
+        f=settings.getoption('lodel2.B','cb',maFonction)
31
+        f=settings.getoption('lodel2.C','cb',maFonction)
32
+        f=settings.getoption('lodel2.C','ca',maFonction)
33
+        f=settings.getoption('lodel2.C','cc',maFonction)
34
+        f=settings.getoption('lodel2.C','a',maFonction)
35
+        f=settings.getoption('lodel2.A.e','a',maFonction)
36
+        f=settings.getoption('lodel2.A.e','titi',maFonction)
35 37
         g=settings.getremains()
36 38
         self.assertEqual(g,[])
37 39
         with self.assertRaises(SettingsError):
38
-            loader = SettingsLoader('tests/settings/conf_raise.d')
40
+            loader = SettingsLoader('tests/settings/settings_examples/conf_raise.d')
39 41
     
40 42
     def test_merge(self):
41 43
         """ Test merge of multiple configuration files """

Loading…
Cancel
Save