bpo-40275: Use new test.support helper submodules in tests by shihai1991 · Pull Request #21314 · python/cpython

Expand Up @@ -13,7 +13,10 @@ TestCase = unittest.TestCase
from test import support from test.support import os_helper from test.support import socket_helper from test.support import warnings_helper

here = os.path.dirname(__file__) # Self-signed cert file for 'localhost' Expand Down Expand Up @@ -1766,14 +1769,14 @@ def test_local_bad_hostname(self): with self.assertRaises(ssl.CertificateError): h.request('GET', '/') # Same with explicit check_hostname=True with support.check_warnings(('', DeprecationWarning)): with warnings_helper.check_warnings(('', DeprecationWarning)): h = client.HTTPSConnection('localhost', server.port, context=context, check_hostname=True) with self.assertRaises(ssl.CertificateError): h.request('GET', '/') # With check_hostname=False, the mismatching is ignored context.check_hostname = False with support.check_warnings(('', DeprecationWarning)): with warnings_helper.check_warnings(('', DeprecationWarning)): h = client.HTTPSConnection('localhost', server.port, context=context, check_hostname=False) h.request('GET', '/nonexistent') Expand All @@ -1792,7 +1795,7 @@ def test_local_bad_hostname(self): h.close() # Passing check_hostname to HTTPSConnection should override the # context's setting. with support.check_warnings(('', DeprecationWarning)): with warnings_helper.check_warnings(('', DeprecationWarning)): h = client.HTTPSConnection('localhost', server.port, context=context, check_hostname=True) with self.assertRaises(ssl.CertificateError): Expand Down Expand Up @@ -1908,10 +1911,10 @@ def test_bytes_body(self): self.assertEqual(b'body\xc1', f.read())
def test_text_file_body(self): self.addCleanup(support.unlink, support.TESTFN) with open(support.TESTFN, "w") as f: self.addCleanup(os_helper.unlink, os_helper.TESTFN) with open(os_helper.TESTFN, "w") as f: f.write("body") with open(support.TESTFN) as f: with open(os_helper.TESTFN) as f: self.conn.request("PUT", "/url", f) message, f = self.get_headers_and_fp() self.assertEqual("text/plain", message.get_content_type()) Expand All @@ -1923,10 +1926,10 @@ def test_text_file_body(self): self.assertEqual(b'4\r\nbody\r\n0\r\n\r\n', f.read())
def test_binary_file_body(self): self.addCleanup(support.unlink, support.TESTFN) with open(support.TESTFN, "wb") as f: self.addCleanup(os_helper.unlink, os_helper.TESTFN) with open(os_helper.TESTFN, "wb") as f: f.write(b"body\xc1") with open(support.TESTFN, "rb") as f: with open(os_helper.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()) Expand Down