-
Notifications
You must be signed in to change notification settings - Fork 169
/
test_device_matcher_udev.py
36 lines (32 loc) · 1.19 KB
/
test_device_matcher_udev.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
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))