Esempio n. 1
0
 def test_dev_file_stat(self, mock_minor, mock_major, _):
     mock_major.return_value = 123
     mock_minor.return_value = 987
     device = usb_device.USBDevice(self.libusb_device)
     self.assertEquals(str(device), 'serial1')
     self.assertEquals(device.minor, 987)
     self.assertEquals(device.major, 123)
Esempio n. 2
0
    def test_unexpected_hub_list(self):
        # Give the 7th device a crazy port list.
        self.libusb_devices[6].port_list = [1, 2, 4, 4, 1]
        devices = [usb_device.USBDevice(d) for d in self.libusb_devices]

        usb_device.assign_physical_ports(devices)
        for d in devices:
            self.assertEquals(d.physical_port, None)
Esempio n. 3
0
    def test_duplicate_physical_ports(self):
        # Give the 1st and 2nd devices the same port list.
        self.libusb_devices[0].port_list = [1, 2, 1]
        self.libusb_devices[1].port_list = [1, 2, 1]
        devices = [usb_device.USBDevice(d) for d in self.libusb_devices]

        usb_device.assign_physical_ports(devices)
        for d in devices:
            self.assertEquals(d.physical_port, None)
Esempio n. 4
0
    def test_incomplete_hub_list_2(self):
        # Skip all but the first 2 devices.
        devices = []
        for i in range(0, 2):
            devices.append(usb_device.USBDevice(self.libusb_devices[i]))

        usb_device.assign_physical_ports(devices)
        for d in devices:
            self.assertEquals(d.physical_port, None)
Esempio n. 5
0
    def test_full_hub(self):
        devices = [usb_device.USBDevice(d) for d in self.libusb_devices]

        usb_device.assign_physical_ports(devices)

        self.assertEquals(devices[0].physical_port, 1)
        self.assertEquals(devices[1].physical_port, 2)
        self.assertEquals(devices[2].physical_port, 3)
        self.assertEquals(devices[3].physical_port, 4)
        self.assertEquals(devices[4].physical_port, 5)
        self.assertEquals(devices[5].physical_port, 6)
        self.assertEquals(devices[6].physical_port, 7)
Esempio n. 6
0
    def test_known_hub(self, mock_physical_ports):
        mock_physical_ports.return_value = [self.port_mappings]
        devices = [usb_device.USBDevice(d) for d in self.libusb_devices]
        usb_device.assign_physical_ports(devices)

        self.assertEquals(devices[0].physical_port, 1)
        self.assertEquals(devices[1].physical_port, 2)
        self.assertEquals(devices[2].physical_port, 3)
        self.assertEquals(devices[3].physical_port, 4)
        self.assertEquals(devices[4].physical_port, 5)
        self.assertEquals(devices[5].physical_port, 6)
        self.assertEquals(devices[6].physical_port, 7)
Esempio n. 7
0
    def test_incomplete_hub_list_1(self):
        # Skip the 5th device and make sure the physical ports stay the same.
        devices = []
        for i in range(0, 4) + range(5, 7):
            devices.append(usb_device.USBDevice(self.libusb_devices[i]))

        usb_device.assign_physical_ports(devices)

        self.assertEquals(devices[0].physical_port, 1)
        self.assertEquals(devices[1].physical_port, 2)
        self.assertEquals(devices[2].physical_port, 3)
        self.assertEquals(devices[3].physical_port, 4)
        self.assertEquals(devices[4].physical_port, 6)
        self.assertEquals(devices[5].physical_port, 7)
Esempio n. 8
0
 def test_get_port_list(self):
     self.libusb_device.port_list = [1, 2, 3]
     device = usb_device.USBDevice(self.libusb_device)
     self.assertEquals(device.port_list, [1, 2, 3])
     self.assertEquals(device.port_list, [1, 2, 3])
Esempio n. 9
0
 def test_dev_faulty_port_list(self):
     self.libusb_device.port_list = None
     device = usb_device.USBDevice(self.libusb_device)
     self.assertEquals(device.port_list, None)
Esempio n. 10
0
 def test_dev_faulty_serial(self):
     self.libusb_device.serial = None
     device = usb_device.USBDevice(self.libusb_device)
     self.assertEquals(device.serial, None)
Esempio n. 11
0
 def test_many_unknown_hubs(self, mock_physical_ports):
     mock_physical_ports.return_value = [{}, {}, {}]
     devices = [usb_device.USBDevice(d) for d in self.libusb_devices]
     usb_device.assign_physical_ports(devices)
     for d in devices:
         self.assertEquals(d.physical_port, None)