This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
executable file
·65 lines (46 loc) · 1.73 KB
/
test.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/env python
# pylint: disable=missing-docstring
from io import StringIO
from unittest import TestCase, main
from bios_pnp import pnp
class TestSplitN(TestCase):
def test_too_small(self):
with self.assertRaises(ValueError):
pnp.split_n('abc', 4)
def test_valid(self):
self.assertEqual(pnp.split_n('abc', 2), ('ab', 'c'))
class TestPnpDeviceId(TestCase):
def test_repr(self):
self.assertEqual(repr(pnp.DeviceId('ABC', 0x1, 0x1)),
'DeviceId(vendor=ABC, product=0x001, revision=0x1)')
def test_str(self):
self.assertEqual(str(pnp.DeviceId('ABC', 0x1, 0x2)), 'ABC0012')
def test_vendor_case(self):
self.assertEqual(pnp.DeviceId('ifx', 0, 0).vendor, 'IFX')
class TestPnpDevice(TestCase):
def test_str(self):
self.assertEqual(
str(
pnp.Device([
pnp.DeviceId('ABC', 0x1, 0x2),
pnp.DeviceId('DEF', 0x3, 0x4)
])), 'Device(ABC0012, DEF0034)')
class TestParse(TestCase):
def test_parse_hex(self):
self.assertEqual(pnp.parse_hex('10'), 16)
def test_invalid_device_id(self):
with self.assertRaises(ValueError):
pnp.parse_device_id('ifx000')
def test_valid_device_id(self):
self.assertEqual(pnp.parse_device_id('IFX0101'),
pnp.DeviceId('ifx', 16, 1))
def test_parse_id_file(self):
id_file = StringIO('INT3f0d\nPNP0c02\n')
self.assertEqual(
pnp.parse_sysfs_pnp_id_file(id_file),
pnp.Device(ids=[
pnp.DeviceId('INT', 0x3f0, 0xd),
pnp.DeviceId('PNP', 0x0c0, 0x2)
]))
if __name__ == '__main__':
main()