diff --git a/tests/test-umockdev.py b/tests/test-umockdev.py index 5b8c1e2..a7e5b71 100644 --- a/tests/test-umockdev.py +++ b/tests/test-umockdev.py @@ -18,11 +18,11 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program; If not, see . -import sys -import os.path -import unittest import fcntl +import os.path import struct +import sys +import unittest import warnings try: @@ -41,6 +41,7 @@ warnings.filterwarnings('ignore', category=DeprecationWarning) from gi.repository import UMockdev + class Testbed(unittest.TestCase): def setUp(self): self.testbed = UMockdev.Testbed.new() @@ -180,7 +181,7 @@ def on_uevent(client, action, device, counters): self.assertEqual(counter, [0, 0, 1, syspath, '0815', '1']) def test_add_from_string(self): - self.assertTrue(self.testbed.add_from_string ('''P: /devices/dev1 + self.assertTrue(self.testbed.add_from_string('''P: /devices/dev1 E: SIMPLE_PROP=1 E: SUBSYSTEM=pci H: binary_attr=41FF0005FF00 @@ -193,13 +194,13 @@ def test_add_from_string(self): devices = enum.execute() self.assertEqual([d.get_sysfs_path() for d in devices], ['/sys/devices/dev1']) - device = client.query_by_sysfs_path ('/sys/devices/dev1') - self.assertEqual (device.get_subsystem(), 'pci') - #self.assertEqual (device.get_parent(), None) - self.assertEqual (device.get_sysfs_attr('simple_attr'), '1') - self.assertEqual (device.get_sysfs_attr('multiline_attr'), - 'a\\b\nc\\d\nlast') - self.assertEqual (device.get_property('SIMPLE_PROP'), '1') + device = client.query_by_sysfs_path('/sys/devices/dev1') + self.assertEqual(device.get_subsystem(), 'pci') + # self.assertEqual(device.get_parent(), None) + self.assertEqual(device.get_sysfs_attr('simple_attr'), '1') + self.assertEqual(device.get_sysfs_attr('multiline_attr'), + 'a\\b\nc\\d\nlast') + self.assertEqual(device.get_property('SIMPLE_PROP'), '1') with open(os.path.join(self.testbed.get_root_dir(), '/sys/devices/dev1/binary_attr'), 'rb') as f: self.assertEqual(f.read(), b'\x41\xFF\x00\x05\xFF\x00') @@ -213,12 +214,12 @@ def test_add_from_string_errors(self): assertRaisesRegex = self.assertRaisesRegexp # does not start with P: - with assertRaisesRegex(GLib.GError, 'must start with.*P:') as cm: - self.testbed.add_from_string ('E: SIMPLE_PROP=1\n') + with assertRaisesRegex(GLib.GError, 'must start with.*P:'): + self.testbed.add_from_string('E: SIMPLE_PROP=1\n') # no value - with assertRaisesRegex(GLib.GError, 'malformed attribute') as cm: - self.testbed.add_from_string ('P: /devices/dev1\nE: SIMPLE_PROP\n') + with assertRaisesRegex(GLib.GError, 'malformed attribute'): + self.testbed.add_from_string('P: /devices/dev1\nE: SIMPLE_PROP\n') def test_custom_ioctl(self): handler = UMockdev.IoctlBase() @@ -240,7 +241,7 @@ def handle_ioctl(handler, client): handler.connect("handle-ioctl", handle_ioctl) - self.testbed.add_from_string ('P: /devices/test\nN: test\nE: SUBSYSTEM=test') + self.testbed.add_from_string('P: /devices/test\nN: test\nE: SUBSYSTEM=test') self.testbed.attach_ioctl('/dev/test', handler) fd = os.open('/dev/test', os.O_RDONLY) @@ -253,4 +254,5 @@ def handle_ioctl(handler, client): self.testbed.detach_ioctl('/dev/test') self.testbed.attach_ioctl('/dev/test', handler) + unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))