mirror of
https://github.com/yweber/lodel2.git
synced 2026-03-14 15:22:02 +01:00
Merge branch 'newlodel' of git.labocleo.org:lodel2 into newlodel
This commit is contained in:
commit
4f542e0866
10 changed files with 41 additions and 30 deletions
|
|
@ -28,8 +28,10 @@ class SettingsLoader(object):
|
|||
l_dir = glob.glob(self.__conf_path+'/*.ini')
|
||||
|
||||
for f_ini in l_dir:
|
||||
config = configparser.ConfigParser(default_section = 'lodel2')
|
||||
#To avoid the DEFAULT section whose values are found in all sections, we have to give it an unsual name
|
||||
config = configparser.ConfigParser(default_section = 'lodel2_default_passaway_tip',interpolation=None)
|
||||
config.read(f_ini)
|
||||
|
||||
for sect in config:
|
||||
if sect in conf:
|
||||
for param in config[sect]:
|
||||
|
|
@ -42,7 +44,7 @@ class SettingsLoader(object):
|
|||
opts={}
|
||||
for key in config[sect]:
|
||||
opts[key] = config[sect].get(key)
|
||||
if sect != 'DEFAULT': self.__conf_sv[sect + ':' + key]=f_ini
|
||||
if sect != 'lodel2_default_passaway_tip': self.__conf_sv[sect + ':' + key]=f_ini
|
||||
conf.update({sect: opts})
|
||||
os.close(dir_conf)
|
||||
return conf
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
[B]
|
||||
ab=art
|
||||
bb=bj,kl,mn
|
||||
cb=tatat
|
||||
[A]
|
||||
fhui=njl
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[A]
|
||||
a=a1
|
||||
b=b1,b2,b3
|
||||
c=toto
|
||||
[C]
|
||||
ca=a2
|
||||
cb=b4,b2,b3
|
||||
cc=titi
|
||||
8
tests/settings/settings_examples/conf.d/a.ini
Normal file
8
tests/settings/settings_examples/conf.d/a.ini
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[lodel2.A]
|
||||
a=a1
|
||||
b=b1,b2,b3
|
||||
c=toto
|
||||
[lodel2.A.e]
|
||||
titi=tata
|
||||
[lodel2.C]
|
||||
a=test
|
||||
3
tests/settings/settings_examples/conf.d/b.ini
Normal file
3
tests/settings/settings_examples/conf.d/b.ini
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[lodel2.A]
|
||||
fhui=njl
|
||||
|
||||
2
tests/settings/settings_examples/conf.d/c.ini
Normal file
2
tests/settings/settings_examples/conf.d/c.ini
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[lodel2.A.e]
|
||||
a=ft
|
||||
8
tests/settings/settings_examples/conf.d/d.ini
Normal file
8
tests/settings/settings_examples/conf.d/d.ini
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[lodel2.C]
|
||||
ca=a2
|
||||
cb=b4,b2,b3
|
||||
cc=titi
|
||||
[lodel2.B]
|
||||
ab=art
|
||||
bb=bj,kl,mn
|
||||
cb=tatat
|
||||
|
|
@ -8,34 +8,36 @@ from lodel.settings.settings_loader import SettingsLoader
|
|||
#A dummy validator that only returns the value
|
||||
def dummy_validator(value): return value
|
||||
#A dummy validator that always fails
|
||||
def dummy_validator_fails(value): raise ValueError("Fake validaion error")
|
||||
def dummy_validator_fails(value): raise ValueError("Fake validation error")
|
||||
|
||||
class SettingsLoaderTestCase(unittest.TestCase):
|
||||
|
||||
def test_merge_getsection(self):
|
||||
"""Tests merge and getSection functions """
|
||||
settings = SettingsLoader('tests/settings/conf.d')
|
||||
settings = SettingsLoader('tests/settings/settings_examples/conf.d')
|
||||
def maFonction(a):
|
||||
return a
|
||||
e=settings.getoption('A','a',maFonction)
|
||||
e=settings.getoption('lodel2.A','a',maFonction)
|
||||
self.assertEqual(e,'a1')
|
||||
f=settings.getoption('B','bb',maFonction)
|
||||
f=settings.getoption('lodel2.B','bb',maFonction)
|
||||
self.assertEqual(f,"bj,kl,mn")
|
||||
g=settings.getremains()
|
||||
self.assertIsNotNone(g)
|
||||
e=settings.getoption('A','b',maFonction)
|
||||
e=settings.getoption('A','c',maFonction)
|
||||
e=settings.getoption('A','fhui',maFonction)
|
||||
f=settings.getoption('B','ab',maFonction)
|
||||
f=settings.getoption('B','cb',maFonction)
|
||||
f=settings.getoption('C','cb',maFonction)
|
||||
f=settings.getoption('C','ca',maFonction)
|
||||
f=settings.getoption('C','cc',maFonction)
|
||||
f=settings.getoption('C','a',maFonction)
|
||||
e=settings.getoption('lodel2.A','b',maFonction)
|
||||
e=settings.getoption('lodel2.A','c',maFonction)
|
||||
e=settings.getoption('lodel2.A','fhui',maFonction)
|
||||
f=settings.getoption('lodel2.B','ab',maFonction)
|
||||
f=settings.getoption('lodel2.B','cb',maFonction)
|
||||
f=settings.getoption('lodel2.C','cb',maFonction)
|
||||
f=settings.getoption('lodel2.C','ca',maFonction)
|
||||
f=settings.getoption('lodel2.C','cc',maFonction)
|
||||
f=settings.getoption('lodel2.C','a',maFonction)
|
||||
f=settings.getoption('lodel2.A.e','a',maFonction)
|
||||
f=settings.getoption('lodel2.A.e','titi',maFonction)
|
||||
g=settings.getremains()
|
||||
self.assertEqual(g,[])
|
||||
with self.assertRaises(SettingsError):
|
||||
loader = SettingsLoader('tests/settings/conf_raise.d')
|
||||
loader = SettingsLoader('tests/settings/settings_examples/conf_raise.d')
|
||||
|
||||
def test_merge(self):
|
||||
""" Test merge of multiple configuration files """
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue