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.
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import unittest
|
|
import pyudev
|
|
|
|
from tuned.hardware.device_matcher_udev import DeviceMatcherUdev
|
|
|
|
class DeviceMatcherUdevTestCase(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.udev_context = pyudev.Context()
|
|
cls.matcher = DeviceMatcherUdev()
|
|
|
|
def test_simple_search(self):
|
|
try:
|
|
device = pyudev.Devices.from_sys_path(self.udev_context,
|
|
"/sys/devices/virtual/tty/tty0")
|
|
except AttributeError:
|
|
device = pyudev.Device.from_sys_path(self.udev_context,
|
|
"/sys/devices/virtual/tty/tty0")
|
|
self.assertTrue(self.matcher.match("tty0", device))
|
|
try:
|
|
device = pyudev.Devices.from_sys_path(self.udev_context,
|
|
"/sys/devices/virtual/tty/tty1")
|
|
except AttributeError:
|
|
device = pyudev.Device.from_sys_path(self.udev_context,
|
|
"/sys/devices/virtual/tty/tty1")
|
|
self.assertFalse(self.matcher.match("tty0", device))
|
|
|
|
def test_regex_search(self):
|
|
try:
|
|
device = pyudev.Devices.from_sys_path(self.udev_context,
|
|
"/sys/devices/virtual/tty/tty0")
|
|
except AttributeError:
|
|
device = pyudev.Device.from_sys_path(self.udev_context,
|
|
"/sys/devices/virtual/tty/tty0")
|
|
self.assertTrue(self.matcher.match("tty.", device))
|
|
self.assertFalse(self.matcher.match("tty[1-9]", device))
|