1import unittest 2 3from autotest_lib.client.common_lib.cros.cfm.usb import usb_device 4from autotest_lib.client.common_lib.cros.cfm.usb import usb_device_spec 5 6# pylint: disable=missing-docstring 7 8class UsbDeviceTest(unittest.TestCase): 9 """Unit tests for UsbDevice.""" 10 11 def setUp(self): 12 self._usb_device = usb_device.UsbDevice( 13 vid='vid', 14 pid='pid', 15 product='product', 16 interfaces=['a', 'b'], 17 bus=1, 18 level=1, 19 port=2) 20 21 def test_vendor_id(self): 22 self.assertEqual(self._usb_device.vendor_id, 'vid') 23 24 def test_product_id(self): 25 self.assertEqual(self._usb_device.product_id, 'pid') 26 27 def test_product(self): 28 self.assertEqual(self._usb_device.product, 'product') 29 30 def test_vid_pid(self): 31 self.assertEqual(self._usb_device.vid_pid, 'vid:pid') 32 33 def test_bus(self): 34 self.assertEqual(self._usb_device.bus, 1) 35 36 def test_port(self): 37 self.assertEqual(self._usb_device.port, 2) 38 39 def test_level(self): 40 self.assertEqual(self._usb_device.level, 1) 41 42 def test_get_parent(self): 43 child = usb_device.UsbDevice( 44 vid='vid1', 45 pid='pid1', 46 product='product', 47 interfaces=['a', 'b'], 48 bus=1, 49 level=2, 50 port=2, 51 parent=self._usb_device) 52 self.assertEquals(child.get_parent(1).vid_pid, 'vid:pid') 53 54 def test_get_parent_error(self): 55 self.assertRaises(ValueError, lambda: self._usb_device.get_parent(2)) 56 57 def test_interfaces_matches_spec(self): 58 device_spec = usb_device_spec.UsbDeviceSpec( 59 vid='vid', 60 pid='pid', 61 product='product', 62 interfaces=['a', 'b']) 63 self.assertTrue(self._usb_device.interfaces_match_spec(device_spec)) 64