Skip to content

Commit

Permalink
tests: tests-umockdev.py code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpitt committed Jul 14, 2023
1 parent b22e2e5 commit dee9939
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions tests/test-umockdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.

import sys
import os.path
import unittest
import fcntl
import os.path
import struct
import sys
import unittest
import warnings

try:
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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))

0 comments on commit dee9939

Please sign in to comment.