MCPcopy Index your code
hub / github.com/python/cpython / test_http_closed

Method test_http_closed

Lib/test/test_urllib2.py:1839–1854  ·  view source on GitHub ↗

Test the connection is cleaned up when the response is closed

(self)

Source from the content-addressed store, hash-verified

1837 self.assertTrue(http_handler.has_auth_header)
1838
1839 def test_http_closed(self):
1840 """Test the connection is cleaned up when the response is closed"""
1841 for (transfer, data) in (
1842 ("Connection: close", b"data"),
1843 ("Transfer-Encoding: chunked", b"4\r\ndata\r\n0\r\n\r\n"),
1844 ("Content-Length: 4", b"data"),
1845 ):
1846 header = "HTTP/1.1 200 OK\r\n{}\r\n\r\n".format(transfer)
1847 conn = test_urllib.fakehttp(header.encode() + data)
1848 handler = urllib.request.AbstractHTTPHandler()
1849 req = Request("http://dummy/")
1850 req.timeout = None
1851 with handler.do_open(conn, req) as resp:
1852 resp.read()
1853 self.assertTrue(conn.fakesock.closed,
1854 "Connection not closed with {!r}".format(transfer))
1855
1856 def test_invalid_closed(self):
1857 """Test the connection is cleaned up after an invalid response"""

Callers

nothing calls this directly

Calls 7

do_openMethod · 0.95
RequestClass · 0.90
fakehttpMethod · 0.80
assertTrueMethod · 0.80
formatMethod · 0.45
encodeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected