def test_teensy_device_get_packet_size_must_never_fail(self): """ The Teensy's packet size is preset and must be available and non-zero even if the device is not connected. """ vendor_id = 0 product_id = 0 usage_page = 0 usage = 0 device = TeensyDevice(vendor_id, product_id, usage_page, usage) self.assertGreater(device.get_packet_size(), 0)
def test_teensy_device_get_vendor_and_product_ids(self): """ Test that the VID and PID supplied with the constructor is returned. """ vendor_id = 0xA1B2 product_id = 0xC3D4 usage_page = 0xE5F6 usage = 0x1AB2 device = TeensyDevice(vendor_id, product_id, usage_page, usage) self.assertEqual(device.get_vendor_id(), vendor_id) self.assertEqual(device.get_product_id(), product_id)
def test_teensy_device_no_such_device(self): """ Operations must fail if there's no such device. """ # So it seems TeensyRawhid will actually sometimes not raise an IOError # for an invalid VID and PID (i.e. it will return None as if it has # successfully opened the device). This is awkward and probably a # bug -- either in TeensyRawhid or in the kernel. Replicate this by # executing open(...) consecutively on an interactive Python terminal: # The first invocation will fail and the subsequent ones succeed. If # you then wait a while (a few minutes, but I don know exactly how # long) and try again it will again fail, before succeeding again. What # does seem to make a difference is to use values greater than zero. It # will then behave consistently. vendor_id = 0x1 product_id = 0x1 usage_page = 0x1 usage = 0x1 device = TeensyDevice(vendor_id, product_id, usage_page, usage) self.assertRaises(IOError, device.open) self.assertFalse(device.is_open()) self.assertRaises(IOError, device.send, "foo") self.assertRaises(IOError, device.receive)