(self)
| 1962 | self.assertEqual(conn.connections, 1 if reuse else 2) |
| 1963 | |
| 1964 | def test_disconnected(self): |
| 1965 | |
| 1966 | def make_reset_reader(text): |
| 1967 | """Return BufferedReader that raises ECONNRESET at EOF""" |
| 1968 | stream = io.BytesIO(text) |
| 1969 | def readinto(buffer): |
| 1970 | size = io.BytesIO.readinto(stream, buffer) |
| 1971 | if size == 0: |
| 1972 | raise ConnectionResetError() |
| 1973 | return size |
| 1974 | stream.readinto = readinto |
| 1975 | return io.BufferedReader(stream) |
| 1976 | |
| 1977 | tests = ( |
| 1978 | (io.BytesIO, client.RemoteDisconnected), |
| 1979 | (make_reset_reader, ConnectionResetError), |
| 1980 | ) |
| 1981 | for stream_factory, exception in tests: |
| 1982 | with self.subTest(exception=exception): |
| 1983 | conn = FakeSocketHTTPConnection(b'', stream_factory) |
| 1984 | conn.request('GET', '/eof-response') |
| 1985 | self.assertRaises(exception, conn.getresponse) |
| 1986 | self.assertIsNone(conn.sock) |
| 1987 | # HTTPConnection.connect() should be automatically invoked |
| 1988 | conn.request('GET', '/reconnect') |
| 1989 | self.assertEqual(conn.connections, 2) |
| 1990 | |
| 1991 | def test_100_close(self): |
| 1992 | conn = FakeSocketHTTPConnection( |
nothing calls this directly
no test coverage detected