mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Move test_httplib over to file context managers.
This commit is contained in:
parent
7f462fc835
commit
77b7de6d18
1 changed files with 25 additions and 27 deletions
|
@ -189,7 +189,7 @@ class BasicTest(TestCase):
|
|||
expected = (b'GET /foo HTTP/1.1\r\nHost: example.com\r\n'
|
||||
b'Accept-Encoding: identity\r\nContent-Length:')
|
||||
|
||||
body = open(__file__, 'rb')
|
||||
with open(__file__, 'rb') as body:
|
||||
conn = client.HTTPConnection('example.com')
|
||||
sock = FakeSocket(body)
|
||||
conn.sock = sock
|
||||
|
@ -519,10 +519,9 @@ class RequestBodyTest(TestCase):
|
|||
self.assertEqual(b'body\xc1', f.read())
|
||||
|
||||
def test_file_body(self):
|
||||
f = open(support.TESTFN, "w")
|
||||
with open(support.TESTFN, "w") as f:
|
||||
f.write("body")
|
||||
f.close()
|
||||
f = open(support.TESTFN)
|
||||
with open(support.TESTFN) as f:
|
||||
self.conn.request("PUT", "/url", f)
|
||||
message, f = self.get_headers_and_fp()
|
||||
self.assertEqual("text/plain", message.get_content_type())
|
||||
|
@ -531,10 +530,9 @@ class RequestBodyTest(TestCase):
|
|||
self.assertEqual(b'body', f.read())
|
||||
|
||||
def test_binary_file_body(self):
|
||||
f = open(support.TESTFN, "wb")
|
||||
with open(support.TESTFN, "wb") as f:
|
||||
f.write(b"body\xc1")
|
||||
f.close()
|
||||
f = open(support.TESTFN, "rb")
|
||||
with open(support.TESTFN, "rb") as f:
|
||||
self.conn.request("PUT", "/url", f)
|
||||
message, f = self.get_headers_and_fp()
|
||||
self.assertEqual("text/plain", message.get_content_type())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue