1
0
Fork 0
tuned/tests/unit/profiles/test_merger.py
Miro Hrončok 2399aa3b2d Remove usage of unittest2, use unittest from the standard library
Fixes https://github.com/redhat-performance/tuned/issues/241

Fedora is removing the unittest2 package: https://bugzilla.redhat.com/show_bug.cgi?id=1794222

tuned is not targeting Python 2.6: https://github.com/redhat-performance/tuned/issues/241#issuecomment-588320175

One thing not present in Python 2.7 is assertItemsEqual() -- renamed to assertCountEqual().

Related, mock was also listed as a requirement in the spec file,
but all the imports are from unittest.mock, hence removed.
2020-02-25 20:04:51 +01:00

62 lines
2.3 KiB
Python

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")