(self)
| 2008 | self.assertEqual(conn.connections, 1 if reuse else 2) |
| 2009 | |
| 2010 | def test_disconnected(self): |
| 2011 | |
| 2012 | def make_reset_reader(text): |
| 2013 | """Return BufferedReader that raises ECONNRESET at EOF""" |
| 2014 | stream = io.BytesIO(text) |
| 2015 | def readinto(buffer): |
| 2016 | size = io.BytesIO.readinto(stream, buffer) |
| 2017 | if size == 0: |
| 2018 | raise ConnectionResetError() |
| 2019 | return size |
| 2020 | stream.readinto = readinto |
| 2021 | return io.BufferedReader(stream) |
| 2022 | |
| 2023 | tests = ( |
| 2024 | (io.BytesIO, client.RemoteDisconnected), |
| 2025 | (make_reset_reader, ConnectionResetError), |
| 2026 | ) |
| 2027 | for stream_factory, exception in tests: |
| 2028 | with self.subTest(exception=exception): |
| 2029 | conn = FakeSocketHTTPConnection(b'', stream_factory) |
| 2030 | conn.request('GET', '/eof-response') |
| 2031 | self.assertRaises(exception, conn.getresponse) |
| 2032 | self.assertIsNone(conn.sock) |
| 2033 | # HTTPConnection.connect() should be automatically invoked |
| 2034 | conn.request('GET', '/reconnect') |
| 2035 | self.assertEqual(conn.connections, 2) |
| 2036 | |
| 2037 | def test_100_close(self): |
| 2038 | conn = FakeSocketHTTPConnection( |
nothing calls this directly
no test coverage detected