Exemple #1
0
    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)
        # Checks that identifier and other type are not equal
        self.assertFalse(a == 1)
Exemple #2
0
    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: ""})