Beispiel #1
0
    def testClass(self):
        io_stream._FORCE_THREAD = False

        req_io = io_stream.RequestsIO(lambda c: None)
        if io_stream.GreenletRequestsIO is None:
            self.assertIsInstance(req_io, io_stream.ThreadRequestsIO)
        else:
            self.assertIsInstance(req_io, io_stream.GreenletRequestsIO)
        self.assertIsInstance(io_stream.ThreadRequestsIO(lambda c: None),
                              io_stream.ThreadRequestsIO)
        if io_stream.GreenletRequestsIO is not None:
            self.assertIsInstance(io_stream.GreenletRequestsIO(lambda c: None),
                                  io_stream.GreenletRequestsIO)

        io_stream._FORCE_THREAD = True

        req_io = io_stream.RequestsIO(lambda c: None)
        self.assertIsInstance(req_io, io_stream.ThreadRequestsIO)
        self.assertIsInstance(io_stream.ThreadRequestsIO(lambda c: None),
                              io_stream.ThreadRequestsIO)
        if io_stream.GreenletRequestsIO is not None:
            self.assertIsInstance(io_stream.GreenletRequestsIO(lambda c: None),
                                  io_stream.GreenletRequestsIO)
Beispiel #2
0
    def testRaises(self):
        exc_trace = [None]

        def raise_poster(it):
            exc_trace[0] = None
            next(it)
            try:
                raise AttributeError
            except:
                tb = traceback.format_exc().splitlines()
                exc_trace[0] = '\n'.join(tb[-3:])
                raise

        io_stream._FORCE_THREAD = True

        req_io = io_stream.ThreadRequestsIO(raise_poster)
        req_io.start()
        try:
            req_io.write(b'TEST_DATA')
            req_io.write(b'ANOTHER_PIECE')
            req_io.finish()
        except AttributeError:
            tb = traceback.format_exc().splitlines()
            self.assertEqual('\n'.join(tb[-3:]), exc_trace[0])

        if io_stream.GreenletRequestsIO is None:
            return

        req_io = io_stream.GreenletRequestsIO(raise_poster)
        req_io.start()
        try:
            req_io.write(b'TEST_DATA')
            req_io.write(b'ANOTHER_PIECE')
            req_io.finish()
        except AttributeError:
            tb = traceback.format_exc().splitlines()
            self.assertEqual('\n'.join(tb[-3:]), exc_trace[0])