1
0
Fork 0
tuned/tests/unit/profiles/test_profile.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

58 lines
1.6 KiB
Python

import unittest
import tuned.profiles
import collections
class MockProfile(tuned.profiles.profile.Profile):
def _create_unit(self, name, config):
return (name, config)
class ProfileTestCase(unittest.TestCase):
def test_init(self):
MockProfile("test", {})
def test_create_units(self):
profile = MockProfile("test", {
"main": { "anything": 10 },
"network" : { "type": "net", "devices": "*" },
"storage" : { "type": "disk" },
})
self.assertIs(type(profile.units), collections.OrderedDict)
self.assertEqual(len(profile.units), 2)
self.assertListEqual(sorted([name_config for name_config in profile.units]), sorted(["network", "storage"]))
def test_create_units_empty(self):
profile = MockProfile("test", {"main":{}})
self.assertIs(type(profile.units), collections.OrderedDict)
self.assertEqual(len(profile.units), 0)
def test_sets_name(self):
profile1 = MockProfile("test_one", {})
profile2 = MockProfile("test_two", {})
self.assertEqual(profile1.name, "test_one")
self.assertEqual(profile2.name, "test_two")
def test_change_name(self):
profile = MockProfile("oldname", {})
self.assertEqual(profile.name, "oldname")
profile.name = "newname"
self.assertEqual(profile.name, "newname")
def test_sets_options(self):
profile = MockProfile("test", {
"main": { "anything": 10 },
"network" : { "type": "net", "devices": "*" },
})
self.assertIs(type(profile.options), dict)
self.assertEqual(profile.options["anything"], 10)
def test_sets_options_empty(self):
profile = MockProfile("test", {
"storage" : { "type": "disk" },
})
self.assertIs(type(profile.options), dict)
self.assertEqual(len(profile.options), 0)