Esempio n. 1
0
    def test_io_readinto(self):
        # This test is necessary because in py2.6, `readinto` doesn't get called
        # in `test_io_bufferedreader` like it does for all the other python
        # versions.  Probably this is because the `io` module in py2.6 is an
        # old version that has a different underlying implementation.

        fp = self._fake_fp(b'foo')
        #fp = BytesIO(b'foo')
        resp = HTTPResponse(fp, preload_content=False)

        barr = bytearray(3)
        amtRead = yield From(resp.readinto(barr))
        assert amtRead == 3
        assert b'foo' == barr

        # The reader should already be empty, so this should read nothing.
        amtRead = yield From(resp.readinto(barr))
        assert amtRead == 0
        assert b'foo' == barr