Browse Source

Add a loader for tests in order to bootstrap settings

Yann Weber 8 years ago
parent
commit
2404c53fef

+ 3
- 0
globconf.d/global.ini View File

@@ -0,0 +1,3 @@
1
+[lodel2]
2
+lib_path = /home/yannweb/dev/lodel2/lodel2-git
3
+plugins_path = /home/yannweb/dev/lodel2/lodel2-git/plugins

+ 4
- 0
globconf.d/loggers.ini View File

@@ -0,0 +1,4 @@
1
+[lodel2.logging.default]
2
+level = DEBUG
3
+context = True
4
+filename = -

+ 3
- 3
lodel/settings/__init__.py View File

@@ -1,5 +1,5 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
-#from .settings import Settings as SettingsHandler
4
-
5
-#Settings = SettingsHandler(conf_file = './settings.ini')
3
+from lodel.settings.settings import Settings as SettingsHandler
4
+settings = SettingsHandler.bootstrap()
5
+Settings = settings.confs

+ 10
- 3
lodel/settings/settings.py View File

@@ -31,6 +31,7 @@ from lodel.settings.settings_loader import SettingsLoader
31 31
 # - value validation/cast (see @ref Lodel.settings.validator.ConfValidator )
32 32
33 33
 
34
+## @brief A default python system lib path
34 35
 PYTHON_SYS_LIB_PATH = '/usr/local/lib/python{major}.{minor}/'.format(
35 36
 
36 37
                                                                         major = sys.version_info.major,
@@ -73,7 +74,9 @@ class Settings(object):
73 74
             'plugins_path': (   PYTHON_SYS_LIB_PATH+'lodel2/plugins/',
74 75
                                 SettingValidator('directory_list')),
75 76
     }
77
+    instance = None
76 78
     
79
+    ## @brief Should be called only by the boostrap classmethod
77 80
     def __init__(self, conf_file = '/etc/lodel2/lodel2.conf', conf_dir = 'conf.d'):
78 81
         self.__confs = dict()
79 82
         self.__conf_dir = conf_dir
@@ -82,6 +85,13 @@ class Settings(object):
82 85
         #   and self.__confs['lodel2']['lib_path'] set
83 86
         self.__bootstrap()
84 87
     
88
+    ## @brief Stores as class attribute a Settings instance
89
+    @classmethod
90
+    def bootstrap(cls, conf_file = None, conf_dir = None):
91
+        if cls.instance is None:
92
+            cls.instance = cls(conf_file, conf_dir)
93
+        return cls.instance
94
+
85 95
     ## @brief Configuration keys accessor
86 96
     # @return All confs organised into named tuples
87 97
     @property
@@ -140,12 +150,9 @@ class Settings(object):
140 150
         # Construct final specs dict replacing variable sections
141 151
         # by the actual existing sections
142 152
         variable_sections = [ section for section in specs if section.endswith('.*') ]
143
-        print("DEBUG VARIABLE SECTIONS : ")
144 153
         for vsec in variable_sections:
145 154
             preffix = vsec[:-2]
146
-            print("PREFFIX =  ", preffix)
147 155
             for section in loader.getsection(preffix, 'default'): #WARNING : hardcoded default section
148
-                print("SECTIONs = ", section)
149 156
                 specs[section] = copy.copy(specs[vsec])
150 157
             del(specs[vsec])
151 158
         # Fetching valuds for sections

+ 1
- 0
tests/editorial_model/test_model.py View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 import unittest
4 4
 
5
+import tests.loader_utils
5 6
 from lodel.editorial_model.model import EditorialModel
6 7
 from lodel.editorial_model.components import EmComponent, EmClass, EmField, EmGroup
7 8
 from lodel.utils.mlstring import MlString

+ 1
- 0
tests/editorial_model/test_translator_picklefile.py View File

@@ -4,6 +4,7 @@ import unittest
4 4
 import tempfile
5 5
 import os
6 6
 
7
+import tests.loader_utils
7 8
 from lodel.editorial_model.translator import picklefile
8 9
 from lodel.editorial_model.model import EditorialModel
9 10
 from lodel.editorial_model.components import *

+ 1
- 0
tests/leapi/test_lefactory.py View File

@@ -3,6 +3,7 @@
3 3
 import unittest
4 4
 import random
5 5
 
6
+import tests.loader_utils
6 7
 from lodel.editorial_model.model import EditorialModel
7 8
 from lodel.leapi import lefactory
8 9
 

+ 8
- 0
tests/loader_utils.py View File

@@ -0,0 +1,8 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+#
4
+# This file should be imported in every tests files
5
+#
6
+
7
+from lodel.settings.settings import Settings
8
+Settings.bootstrap(conf_file = 'settings.ini', conf_dir = 'globconf.d')

+ 1
- 0
tests/settings/test_settings.py View File

@@ -3,6 +3,7 @@
3 3
 import unittest
4 4
 from unittest import mock
5 5
 
6
+import tests.loader_utils
6 7
 from lodel.settings.settings import Settings
7 8
 
8 9
 class SettingsTestCase(unittest.TestCase):

+ 4
- 2
tests/settings/test_settings_loader.py View File

@@ -1,13 +1,15 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3 3
 import unittest
4
+
5
+import tests.loader_utils
4 6
 from lodel.settings.settings_loader import SettingsLoader
5 7
 
6 8
 class SettingsLoaderTestCase(unittest.TestCase):
7 9
 
8 10
     def test_merge_getsection(self):
9 11
         """Tests merge and getSection functions """
10
-        settings = SettingsLoader('/home/helene/lodel2/tests/settings/conf.d')
12
+        settings = SettingsLoader('tests/settings/conf.d')
11 13
         a = settings.getsection('A')
12 14
         self.assertEqual(a,dict({"a":"a1","b":"b1,b2,b3","c":"toto","fhui":"njl"}))
13 15
         b = settings.getsection('B')
@@ -39,4 +41,4 @@ class SettingsLoaderTestCase(unittest.TestCase):
39 41
         self.assertEqual(g,[])
40 42
         
41 43
         
42
-        
44
+        

+ 2
- 0
tests/test_utils_mlstrings.py View File

@@ -3,6 +3,8 @@
3 3
 import unittest
4 4
 import copy
5 5
 
6
+
7
+import tests.loader_utils
6 8
 from lodel.utils.mlstring import MlString
7 9
 
8 10
 class MlStringTestCase(unittest.TestCase):

Loading…
Cancel
Save