def test_equals(self):
        from mbed_tools.devices._internal.windows.usb_device_identifier import UsbIdentifier, KEY_UID

        # Checks that two unset identifiers are equal
        a = UsbIdentifier()
        b = UsbIdentifier()
        self.assertEqual(a, a)
        self.assertEqual(a, b)
        self.assertEqual(b, a)
        # Checks that two different identifiers are not equal
        a_dict = data_object_to_dict(a)
        a_dict[KEY_UID] = generateUID()
        b_dict = data_object_to_dict(a)
        b_dict[KEY_UID] = generateUID()
        a = UsbIdentifier(**a_dict)
        b = UsbIdentifier(**b_dict)
        self.assertEqual(a, a)
        self.assertNotEqual(a.uid, b.uid)
        self.assertNotEqual(a, b)
        self.assertNotEqual(b, a)
        # Checks that two identifiers with same fields are equal
        b = UsbIdentifier(**a_dict)
        self.assertEqual(a.uid, b.uid)
        self.assertEqual(a, a)
        self.assertEqual(a, b)
        self.assertEqual(b, a)
    def test_hashing(self):
        from mbed_tools.devices._internal.windows.usb_device_identifier import UsbIdentifier, KEY_UID

        # Generates two different USB identifiers
        a = UsbIdentifier()
        a_dict = data_object_to_dict(a)
        a_dict[KEY_UID] = generateUID()
        b_dict = data_object_to_dict(a)
        b_dict[KEY_UID] = generateUID()
        a = UsbIdentifier(**a_dict)
        b = UsbIdentifier(**b_dict)

        self.assertNotEqual(hash(a), hash(b))
        self.assertNotEqual(a, b)
        # Checks dictionary lookup
        self.assertNotIn(a, dict())
        self.assertNotIn(a, {b: ""})
        self.assertIn(b, {b: ""})

        # Creates c so that a and c have the same fields.
        c = UsbIdentifier(**a_dict)

        # Checks dictionary lookup
        self.assertIn(c, {c: ""})
        self.assertIn(a, {c: ""})
    def test_uid_linking_between_usb_and_disk(self):
        from mbed_tools.devices._internal.windows.usb_device_identifier import UsbIdentifier, WindowsUID

        disk_uid = WindowsUID(
            uid="000440112138",
            raw_uid="9&DBDECF6&0&000440112138&0",
            serial_number="                         134657890",
        )

        usb_uid = UsbIdentifier(
            UID=WindowsUID(uid="000440112138", raw_uid="000440112138", serial_number="8&2f125ec6&0"),
            VID="1366",
            PID="1015",
            REV=None,
            MI=None,
        )
        self.assertEqual(disk_uid.presumed_serial_number, usb_uid.uid.presumed_serial_number)
        self.assertEqual(usb_uid.uid.presumed_serial_number, disk_uid.presumed_serial_number)