|
1
|
|
|
import unittest |
|
2
|
|
|
import copy |
|
3
|
|
|
from synergine.core.config.ConfigurationManager import ConfigurationManager |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class TestConfigurationManager(unittest.TestCase): |
|
7
|
|
|
|
|
8
|
|
|
default_tested_config = { |
|
9
|
|
|
'my': { |
|
10
|
|
|
'great': { |
|
11
|
|
|
'config1': 1, |
|
12
|
|
|
'config2': 2 |
|
13
|
|
|
} |
|
14
|
|
|
} |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
def test_get_config(self): |
|
18
|
|
|
config = ConfigurationManager(copy.deepcopy(self.default_tested_config)) |
|
19
|
|
|
self.assertEqual(1, config.get('my.great.config1')) |
|
20
|
|
|
self.assertEqual(2, config.get('my.great.config2')) |
|
21
|
|
|
|
|
22
|
|
|
def test_update_config(self): |
|
23
|
|
|
config = ConfigurationManager(copy.deepcopy(self.default_tested_config)) |
|
24
|
|
|
config.update_config('my.great.config1', 11) |
|
25
|
|
|
self.assertEqual(11, config.get('my.great.config1')) |
|
26
|
|
|
self.assertEqual(2, config.get('my.great.config2')) |
|
27
|
|
|
|
|
28
|
|
|
config.update_config('my', { |
|
29
|
|
|
'great': { |
|
30
|
|
|
'config1': 9, |
|
31
|
|
|
'config2': 0 |
|
32
|
|
|
} |
|
33
|
|
|
}) |
|
34
|
|
|
self.assertEqual(9, config.get('my.great.config1')) |
|
35
|
|
|
self.assertEqual(0, config.get('my.great.config2')) |
|
36
|
|
|
|
|
37
|
|
|
def test_set_config(self): |
|
38
|
|
|
config = ConfigurationManager(copy.deepcopy(self.default_tested_config)) |
|
39
|
|
|
config.set_config('a.new.config', 'foo') |
|
40
|
|
|
self.assertEqual('foo', config.get('a.new.config')) |
|
41
|
|
|
|
|
42
|
|
|
def test_load_config(self): |
|
43
|
|
|
config = ConfigurationManager(copy.deepcopy(self.default_tested_config.copy())) |
|
44
|
|
|
config.load({ |
|
45
|
|
|
'my': { |
|
46
|
|
|
'great': { |
|
47
|
|
|
'config2': 22, |
|
48
|
|
|
'config3': 3 |
|
49
|
|
|
} |
|
50
|
|
|
}, |
|
51
|
|
|
'foo': 'bar' |
|
52
|
|
|
}) |
|
53
|
|
|
self.assertEqual(1, config.get('my.great.config1')) |
|
54
|
|
|
self.assertEqual(22, config.get('my.great.config2')) |
|
55
|
|
|
self.assertEqual(3, config.get('my.great.config3')) |
|
56
|
|
|
self.assertEqual('bar', config.get('foo')) |
|
57
|
|
|
|