MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_http_closed

Method test_http_closed

Lib/test/test_urllib2.py:1822–1837  ·  view source on GitHub ↗

Test the connection is cleaned up when the response is closed

(self)

Source from the content-addressed store, hash-verified

1820 self.assertTrue(http_handler.has_auth_header)
1821
1822 def test_http_closed(self):
1823 """Test the connection is cleaned up when the response is closed"""
1824 for (transfer, data) in (
1825 ("Connection: close", b"data"),
1826 ("Transfer-Encoding: chunked", b"4\r\ndata\r\n0\r\n\r\n"),
1827 ("Content-Length: 4", b"data"),
1828 ):
1829 header = "HTTP/1.1 200 OK\r\n{}\r\n\r\n".format(transfer)
1830 conn = test_urllib.fakehttp(header.encode() + data)
1831 handler = urllib.request.AbstractHTTPHandler()
1832 req = Request("http://dummy/")
1833 req.timeout = None
1834 with handler.do_open(conn, req) as resp:
1835 resp.read()
1836 self.assertTrue(conn.fakesock.closed,
1837 "Connection not closed with {!r}".format(transfer))
1838
1839 def test_invalid_closed(self):
1840 """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