Przeglądaj źródła

More tests on SettingsLoader

Yann Weber 8 lat temu
rodzic
commit
8dbe6b6234

+ 5
- 0
tests/settings/settings_examples/bad_merge.conf.d/file1.ini Wyświetl plik

@@ -0,0 +1,5 @@
1
+[lodel2.merge.fails.duplicate]
2
+duplicated = foobar
3
+foo = 1337
4
+bar = 42
5
+foobar = hello world !

+ 2
- 0
tests/settings/settings_examples/bad_merge.conf.d/file2.ini Wyświetl plik

@@ -0,0 +1,2 @@
1
+[lodel2.merge.fails.duplicate]
2
+duplicated = wrong

+ 4
- 0
tests/settings/settings_examples/merge.conf.d/file1.ini Wyświetl plik

@@ -0,0 +1,4 @@
1
+[lodel2]
2
+a = a
3
+b = b
4
+c = c

+ 10
- 0
tests/settings/settings_examples/merge.conf.d/file2.ini Wyświetl plik

@@ -0,0 +1,10 @@
1
+[lodel2]
2
+d = d
3
+e = e
4
+f = f
5
+
6
+[lodel2.othersection]
7
+a = a
8
+b = b
9
+c = c
10
+d = d

+ 3
- 0
tests/settings/settings_examples/merge.conf.d/file3.ini Wyświetl plik

@@ -0,0 +1,3 @@
1
+[lodel2.othersection]
2
+e = e
3
+f = f

+ 11
- 0
tests/settings/settings_examples/remains.conf.d/file1.ini Wyświetl plik

@@ -0,0 +1,11 @@
1
+[lodel2]
2
+a = a
3
+b = b
4
+c = c
5
+
6
+[lodel2.othersection]
7
+a = a
8
+b = b
9
+c = c
10
+d = d
11
+e = e

+ 3
- 0
tests/settings/settings_examples/remains.conf.d/file2.ini Wyświetl plik

@@ -0,0 +1,3 @@
1
+[lodel2]
2
+d = d
3
+e = e

+ 30
- 25
tests/settings/test_settings_loader.py Wyświetl plik

@@ -2,7 +2,7 @@
2 2
 
3 3
 import unittest
4 4
 
5
-#import tests.loader_utils
5
+from lodel.settings.utils import *
6 6
 from lodel.settings.settings_loader import SettingsLoader
7 7
 
8 8
 #A dummy validator that only returns the value
@@ -15,36 +15,36 @@ class SettingsLoaderTestCase(unittest.TestCase):
15 15
     def test_merge_getsection(self):
16 16
         """Tests merge and getSection functions """
17 17
         settings = SettingsLoader('tests/settings/conf.d')
18
-        a = settings.getsection('A')
19
-        self.assertEqual(a,dict({"a":"a1","b":"b1,b2,b3","c":"toto","fhui":"njl"}))
20
-        b = settings.getsection('B')
21
-        self.assertEqual(b,dict({"ab":"art","bb":"bj,kl,mn","cb":"tatat"}))
22
-        c = settings.getsection('C')
23
-        self.assertEqual(c,dict({"ca":"a2","cb":"b4,b2,b3","cc":"titi"}))
24
-        d = settings.getsection('D')
25
-        
26
-        for v in a:
27
-            assert ('A','{"a":"a1","b":"b1,b2,b3","c":"toto","fhui":"njl"}')
28
-        def maFonction(a):
29
-            return a
30
-        e=settings.getoption('A','a',maFonction)
18
+
19
+        e=settings.getoption('A','a',dummy_validator)
31 20
         self.assertEqual(e,'a1')
32
-        f=settings.getoption('B','bb',maFonction)
21
+        f=settings.getoption('B','bb',dummy_validator)
33 22
         self.assertEqual(f,"bj,kl,mn")
34 23
         g=settings.getremains()
35 24
         self.assertIsNotNone(g)
36
-        e=settings.getoption('A','b',maFonction)
37
-        e=settings.getoption('A','c',maFonction)
38
-        e=settings.getoption('A','fhui',maFonction)
39
-        f=settings.getoption('B','ab',maFonction)
40
-        f=settings.getoption('B','cb',maFonction)
41
-        f=settings.getoption('C','cb',maFonction)
42
-        f=settings.getoption('C','ca',maFonction)
43
-        f=settings.getoption('C','cc',maFonction)
25
+        e=settings.getoption('A','b',dummy_validator)
26
+        e=settings.getoption('A','c',dummy_validator)
27
+        e=settings.getoption('A','fhui',dummy_validator)
28
+        f=settings.getoption('B','ab',dummy_validator)
29
+        f=settings.getoption('B','cb',dummy_validator)
30
+        f=settings.getoption('C','cb',dummy_validator)
31
+        f=settings.getoption('C','ca',dummy_validator)
32
+        f=settings.getoption('C','cc',dummy_validator)
44 33
        
45 34
         g=settings.getremains()
46 35
         self.assertEqual(g,[])
47
-        
36
+    
37
+    def test_merge(self):
38
+        """ Test merge of multiple configuration files """
39
+        loader = SettingsLoader('tests/settings/settings_examples/merge.conf.d')
40
+        for value in ('a','b','c','d','e','f'):
41
+            self.assertEqual(loader.getoption('lodel2', value, dummy_validator), value)
42
+            self.assertEqual(loader.getoption('lodel2.othersection', value, dummy_validator), value)
43
+
44
+    def test_merge_conflict(self):
45
+        """ Test merge fails because of duplicated keys """
46
+        with self.assertRaises(SettingsError):
47
+            loader = SettingsLoader('tests/settings/settings_examples/bad_merge.conf.d')
48 48
      
49 49
     def test_getoption_simple(self):
50 50
         """ Testing behavior of getoption """
@@ -73,4 +73,9 @@ class SettingsLoaderTestCase(unittest.TestCase):
73 73
         loader = SettingsLoader('tests/settings/settings_examples/var_sections.conf.d')
74 74
         with self.assertRaises(NameError):
75 75
             sections = loader.getsection('lodel2.notexisting')
76
-
76
+    
77
+    @unittest.skip("Waiting implementation")
78
+    def test_remains(self):
79
+        """ Testing the remains method of SettingsLoader """
80
+        loader = SettingsLoader('tests/settings/settings_examples/remains.conf.d')
81
+        pass #TO BE DONE LATER

Loading…
Anuluj
Zapisz