Exemplo n.º 1
0
    def test_io_closed_consistently(self):
        hlr = httplib.HTTPResponse(socket.socket())
        hlr.fp = BytesIO(b'foo')
        hlr.chunked = 0
        hlr.length = 3
        resp = HTTPResponse(hlr, preload_content=False)

        self.assertEqual(resp.closed, False)
        self.assertEqual(resp._fp.isclosed(), False)
        self.assertEqual(is_fp_closed(resp._fp), False)
        resp.read()
        self.assertEqual(resp.closed, True)
        self.assertEqual(resp._fp.isclosed(), True)
        self.assertEqual(is_fp_closed(resp._fp), True)
Exemplo n.º 2
0
 def test_io_closed_consistently(self, sock):
     try:
         hlr = httplib.HTTPResponse(sock)
         hlr.fp = BytesIO(b'foo')
         hlr.chunked = 0
         hlr.length = 3
         with HTTPResponse(hlr, preload_content=False) as resp:
             assert not resp.closed
             assert not resp._fp.isclosed()
             assert not is_fp_closed(resp._fp)
             resp.read()
             assert resp.closed
             assert resp._fp.isclosed()
             assert is_fp_closed(resp._fp)
     finally:
         hlr.close()
Exemplo n.º 3
0
 def test_io_closed_consistently(self, sock):
     try:
         hlr = httplib.HTTPResponse(sock)
         hlr.fp = BytesIO(b'foo')
         hlr.chunked = 0
         hlr.length = 3
         with HTTPResponse(hlr, preload_content=False) as resp:
             assert not resp.closed
             assert not resp._fp.isclosed()
             assert not is_fp_closed(resp._fp)
             resp.read()
             assert resp.closed
             assert resp._fp.isclosed()
             assert is_fp_closed(resp._fp)
     finally:
         hlr.close()
Exemplo n.º 4
0
 def test_io_closed_consistently(self, sock: socket.socket) -> None:
     try:
         hlr = httplib.HTTPResponse(sock)
         hlr.fp = BytesIO(b"foo")  # type: ignore[assignment]
         hlr.chunked = 0  # type: ignore[assignment]
         hlr.length = 3
         with HTTPResponse(hlr, preload_content=False) as resp:
             assert not resp.closed
             assert resp._fp is not None
             assert not resp._fp.isclosed()
             assert not is_fp_closed(resp._fp)
             assert not resp.isclosed()
             resp.read()
             assert resp.closed
             assert resp._fp.isclosed()
             assert is_fp_closed(resp._fp)
             assert resp.isclosed()
     finally:
         hlr.close()