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

34 lines
1.2 KiB
Python

import unittest
from tuned.hardware.device_matcher import DeviceMatcher
class DeviceMatcherTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.matcher = DeviceMatcher()
def test_one_positive_rule(self):
self.assertTrue(self.matcher.match("sd*", "sda"))
self.assertFalse(self.matcher.match("sd*", "hda"))
def test_multiple_positive_rules(self):
self.assertTrue(self.matcher.match("sd* hd*", "sda"))
self.assertTrue(self.matcher.match("sd* hd*", "hda"))
self.assertFalse(self.matcher.match("sd* hd*", "dm-0"))
def test_implicit_positive(self):
self.assertTrue(self.matcher.match("", "sda"))
self.assertTrue(self.matcher.match("!sd*", "hda"))
self.assertFalse(self.matcher.match("!sd*", "sda"))
def test_positve_negative_combination(self):
self.assertTrue(self.matcher.match("sd* !sdb", "sda"))
self.assertFalse(self.matcher.match("sd* !sdb", "sdb"))
def test_positive_first(self):
self.assertTrue(self.matcher.match("!sdb sd*", "sda"))
self.assertFalse(self.matcher.match("!sdb sd*", "sdb"))
def test_match_list(self):
devices = ["sda", "sdb", "sdc"]
self.assertListEqual(self.matcher.match_list("sd* !sdb", devices), ["sda", "sdc"])
self.assertListEqual(self.matcher.match_list("!sda", devices), ["sdb", "sdc"])