-
Notifications
You must be signed in to change notification settings - Fork 169
/
test_merger.py
62 lines (55 loc) · 2.31 KB
/
test_merger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import unittest
from tuned.profiles.merger import Merger
from tuned.profiles.profile import Profile
from collections import OrderedDict
class MergerTestCase(unittest.TestCase):
def test_merge_without_replace(self):
merger = Merger()
config1 = OrderedDict([
("main", {"test_option" : "test_value1"}),
("net", { "devices": "em0", "custom": "custom_value"}),
])
profile1 = Profile('test_profile1',config1)
config2 = OrderedDict([
('main', {'test_option' : 'test_value2'}),
('net', { 'devices': 'em1' }),
])
profile2 = Profile("test_profile2",config2)
merged_profile = merger.merge([profile1, profile2])
self.assertEqual(merged_profile.options["test_option"],"test_value2")
self.assertIn("net", merged_profile.units)
self.assertEqual(merged_profile.units["net"].options["custom"],\
"custom_value")
self.assertEqual(merged_profile.units["net"].devices, "em1")
def test_merge_with_replace(self):
merger = Merger()
config1 = OrderedDict([
("main", {"test_option" : "test_value1"}),
("net", { "devices": "em0", "custom": "option"}),
])
profile1 = Profile('test_profile1',config1)
config2 = OrderedDict([
("main", {"test_option" : "test_value2"}),
("net", { "devices": "em1", "replace": True }),
])
profile2 = Profile('test_profile2',config2)
merged_profile = merger.merge([profile1, profile2])
self.assertEqual(merged_profile.options["test_option"],"test_value2")
self.assertIn("net", merged_profile.units)
self.assertNotIn("custom", merged_profile.units["net"].options)
self.assertEqual(merged_profile.units["net"].devices, "em1")
def test_merge_multiple_order(self):
merger = Merger()
config1 = OrderedDict([ ("main", {"test_option" : "test_value1"}),\
("net", { "devices": "em0" }) ])
profile1 = Profile('test_profile1',config1)
config2 = OrderedDict([ ("main", {"test_option" : "test_value2"}),\
("net", { "devices": "em1" }) ])
profile2 = Profile('test_profile2',config2)
config3 = OrderedDict([ ("main", {"test_option" : "test_value3"}),\
("net", { "devices": "em2" }) ])
profile3 = Profile('test_profile3',config3)
merged_profile = merger.merge([profile1, profile2, profile3])
self.assertEqual(merged_profile.options["test_option"],"test_value3")
self.assertIn("net", merged_profile.units)
self.assertEqual(merged_profile.units["net"].devices, "em2")