Ejemplo n.º 1
0
    def testUSBPollerThreadException(self):
        """
        USBPollerThread exception handling.
        """
        class FakeEventPoll(PollDetector):
            # pylint: disable=method-hidden
            def poll(self, *args, **kw):
                self.poll = super(FakeEventPoll, self).poll
                return ['dummy']

            # pylint: enable=method-hidden

        with USBContext() as context:

            def fakeHandleEventsLocked():
                raise usb1.USBError(0)

            context.handleEventsLocked = fakeHandleEventsLocked
            exception_event = threading.Event()
            exception_list = []

            def exceptionHandler(exc):
                exception_list.append(exc)
                exception_event.set()

            try:
                poller = usb1.USBPollerThread(context, FakeEventPoll(),
                                              exceptionHandler)
            except OSError:
                raise unittest.SkipTest(
                    'libusb without file descriptor events')
            poller.start()
            exception_event.wait(1)
            self.assertTrue(exception_list, exception_list)
            self.assertTrue(poller.is_alive())
Ejemplo n.º 2
0
 def __init__(self, scope_id=0):
     self.device = None
     self.device_handle = None
     self.context = usb1.USBContext()
     self.usb_poller = usb1.USBPollerThread(self.context, select.poll())
     # TODO: Should the poller be started on initialization?
     self.usb_poller.start()
     self.is_device_firmware_present = False
     self.supports_single_channel = False
     self.is_iso = False
     self.packetsize = None
     self.num_channels = 2
     self.scope_id = scope_id
Ejemplo n.º 3
0
 def testUSBPollerThreadExit(self):
     """
     USBPollerThread must exit by itself when context is destroyed.
     """
     with USBContext() as context:
         poll_detector = PollDetector()
         try:
             poller = usb1.USBPollerThread(context, poll_detector)
         except OSError:
             raise unittest.SkipTest('libusb without file descriptor events')
         poller.start()
         poll_detector.wait(1)
     poller.join(1)
     self.assertFalse(poller.is_alive())