From 72049215352b25fa0dda023b7103fda3c1db3812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Tue, 19 Feb 2019 17:29:08 +0100 Subject: [PATCH 01/17] bpo-36019: Use pythontest.net instead of example.com --- Lib/test/test_urllib.py | 4 ++-- Lib/test/test_urllib2net.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index c292d74f84a93c..8c4b47720b803a 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -712,7 +712,7 @@ def _reporthook(par1, par2, par3): with self.assertRaises(urllib.error.ContentTooShortError): try: - urllib.request.urlretrieve('http://example.com/', + urllib.request.urlretrieve('http://www.pythontest.net/', reporthook=_reporthook) finally: self.unfakehttp() @@ -729,7 +729,7 @@ def test_short_content_raises_ContentTooShortError_without_reporthook(self): ''') with self.assertRaises(urllib.error.ContentTooShortError): try: - urllib.request.urlretrieve('http://example.com/') + urllib.request.urlretrieve('http://www.pythontest.net/') finally: self.unfakehttp() diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index 1aa64cbee1ca4b..026d6d9c82c162 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -84,7 +84,7 @@ class CloseSocketTest(unittest.TestCase): def test_close(self): # calling .close() on urllib2's response objects should close the # underlying socket - url = "http://www.example.com/" + url = "http://www.pythontest.net/" with support.transient_internet(url): response = _urlopen_with_retry(url) sock = response.fp @@ -173,7 +173,7 @@ def test_redirect_url_withfrag(self): "http://www.pythontest.net/elsewhere/#frag") def test_custom_headers(self): - url = "http://www.example.com" + url = "http://www.pythontest.net" with support.transient_internet(url): opener = urllib.request.build_opener() request = urllib.request.Request(url) @@ -259,7 +259,7 @@ def _extra_handlers(self): class TimeoutTest(unittest.TestCase): def test_http_basic(self): self.assertIsNone(socket.getdefaulttimeout()) - url = "http://www.example.com" + url = "http://www.pythontest.net" with support.transient_internet(url, timeout=None): u = _urlopen_with_retry(url) self.addCleanup(u.close) @@ -267,7 +267,7 @@ def test_http_basic(self): def test_http_default_timeout(self): self.assertIsNone(socket.getdefaulttimeout()) - url = "http://www.example.com" + url = "http://www.pythontest.net" with support.transient_internet(url): socket.setdefaulttimeout(60) try: @@ -279,7 +279,7 @@ def test_http_default_timeout(self): def test_http_no_timeout(self): self.assertIsNone(socket.getdefaulttimeout()) - url = "http://www.example.com" + url = "http://www.pythontest.net" with support.transient_internet(url): socket.setdefaulttimeout(60) try: @@ -290,7 +290,7 @@ def test_http_no_timeout(self): self.assertIsNone(u.fp.raw._sock.gettimeout()) def test_http_timeout(self): - url = "http://www.example.com" + url = "http://www.pythontest.net" with support.transient_internet(url): u = _urlopen_with_retry(url, timeout=120) self.addCleanup(u.close) From 5f726be40d495ccf7dc052e75a883b6d933d1dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Tue, 19 Feb 2019 18:30:50 +0100 Subject: [PATCH 02/17] Add blurb entry --- Misc/NEWS.d/next/Tests/2019-02-19-18-30-40.bpo-36019._hBHx7.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2019-02-19-18-30-40.bpo-36019._hBHx7.rst diff --git a/Misc/NEWS.d/next/Tests/2019-02-19-18-30-40.bpo-36019._hBHx7.rst b/Misc/NEWS.d/next/Tests/2019-02-19-18-30-40.bpo-36019._hBHx7.rst new file mode 100644 index 00000000000000..d4fc96fe0c97d3 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-02-19-18-30-40.bpo-36019._hBHx7.rst @@ -0,0 +1,2 @@ +Replace http://example.com by http://pythontest.net for some tests. +Contributed by Stéphane Wirtel From 039455eee2840c16def3d30b10e22730446ab708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Tue, 19 Feb 2019 19:14:02 +0100 Subject: [PATCH 03/17] Fix test_urllibnet --- Lib/test/test_urllibnet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index 4103b6c07505d5..4f06fbf5e6733a 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -24,8 +24,8 @@ def tearDown(self): socket.setdefaulttimeout(None) def testURLread(self): - with support.transient_internet("www.example.com"): - f = urllib.request.urlopen("http://www.example.com/") + with support.transient_internet("www.pythontest.net"): + f = urllib.request.urlopen("http://www.pythontest.net/") f.read() From e885ac72c640c08e55e318e3f019c395b2883e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 14:24:18 +0100 Subject: [PATCH 04/17] Add test.support.TEST_HTTP_URL for the tests --- Doc/library/test.rst | 5 +++++ Lib/test/support/__init__.py | 3 +++ Lib/test/test_codecmaps_cn.py | 7 ++++--- Lib/test/test_codecmaps_hk.py | 3 ++- Lib/test/test_codecmaps_jp.py | 11 +++++----- Lib/test/test_codecmaps_kr.py | 7 ++++--- Lib/test/test_codecmaps_tw.py | 5 +++-- Lib/test/test_hashlib.py | 4 ++-- Lib/test/test_normalization.py | 4 ++-- Lib/test/test_robotparser.py | 2 +- Lib/test/test_ucn.py | 4 ++-- Lib/test/test_urllib.py | 4 ++-- Lib/test/test_urllib2net.py | 20 +++++++++---------- Lib/test/test_urllibnet.py | 8 ++++---- .../2019-02-21-14-23-51.bpo-36019.zS_OUi.rst | 2 ++ 15 files changed, 52 insertions(+), 37 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2019-02-21-14-23-51.bpo-36019.zS_OUi.rst diff --git a/Doc/library/test.rst b/Doc/library/test.rst index b5057c0ace562c..61dc6367c62932 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -356,6 +356,11 @@ The :mod:`test.support` module defines the following constants: Check for presence of docstrings. +.. data:: TEST_HTTP_URL + + Define the URL of a dedicated HTTP server for the network tests + (http://www.pythontest.net). + The :mod:`test.support` module defines the following functions: diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 9b75a211bea02f..005203d7e2a0b4 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -835,6 +835,9 @@ def dec(*args, **kwargs): # module name. TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid()) +# Define the URL of a dedicated HTTP server for the network test. +TEST_HTTP_URL = "http://www.pythontest.net" + # FS_NONASCII: non-ASCII character encodable by os.fsencode(), # or None if there is no such character. FS_NONASCII = None diff --git a/Lib/test/test_codecmaps_cn.py b/Lib/test/test_codecmaps_cn.py index 89e51c6e2a193d..a9e7170c2f4ffc 100644 --- a/Lib/test/test_codecmaps_cn.py +++ b/Lib/test/test_codecmaps_cn.py @@ -4,22 +4,23 @@ # from test import multibytecodec_support +from test import support import unittest class TestGB2312Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'gb2312' - mapfileurl = 'http://www.pythontest.net/unicode/EUC-CN.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/EUC-CN.TXT' class TestGBKMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'gbk' - mapfileurl = 'http://www.pythontest.net/unicode/CP936.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/CP936.TXT' class TestGB18030Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'gb18030' - mapfileurl = 'http://www.pythontest.net/unicode/gb-18030-2000.xml' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/gb-18030-2000.xml' if __name__ == "__main__": diff --git a/Lib/test/test_codecmaps_hk.py b/Lib/test/test_codecmaps_hk.py index 7a48d24fddbb86..499a893031cc95 100644 --- a/Lib/test/test_codecmaps_hk.py +++ b/Lib/test/test_codecmaps_hk.py @@ -4,12 +4,13 @@ # from test import multibytecodec_support +from test import support import unittest class TestBig5HKSCSMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'big5hkscs' - mapfileurl = 'http://www.pythontest.net/unicode/BIG5HKSCS-2004.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/BIG5HKSCS-2004.TXT' if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_codecmaps_jp.py b/Lib/test/test_codecmaps_jp.py index fdfec8085b24e4..7d1a36b9da33eb 100644 --- a/Lib/test/test_codecmaps_jp.py +++ b/Lib/test/test_codecmaps_jp.py @@ -4,12 +4,13 @@ # from test import multibytecodec_support +from test import support import unittest class TestCP932Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'cp932' - mapfileurl = 'http://www.pythontest.net/unicode/CP932.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/CP932.TXT' supmaps = [ (b'\x80', '\u0080'), (b'\xa0', '\uf8f0'), @@ -25,14 +26,14 @@ class TestEUCJPCOMPATMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'euc_jp' mapfilename = 'EUC-JP.TXT' - mapfileurl = 'http://www.pythontest.net/unicode/EUC-JP.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/EUC-JP.TXT' class TestSJISCOMPATMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'shift_jis' mapfilename = 'SHIFTJIS.TXT' - mapfileurl = 'http://www.pythontest.net/unicode/SHIFTJIS.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/SHIFTJIS.TXT' pass_enctest = [ (b'\x81_', '\\'), ] @@ -46,14 +47,14 @@ class TestEUCJISX0213Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'euc_jisx0213' mapfilename = 'EUC-JISX0213.TXT' - mapfileurl = 'http://www.pythontest.net/unicode/EUC-JISX0213.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/EUC-JISX0213.TXT' class TestSJISX0213Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'shift_jisx0213' mapfilename = 'SHIFT_JISX0213.TXT' - mapfileurl = 'http://www.pythontest.net/unicode/SHIFT_JISX0213.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/SHIFT_JISX0213.TXT' if __name__ == "__main__": diff --git a/Lib/test/test_codecmaps_kr.py b/Lib/test/test_codecmaps_kr.py index 1b6f5ca3080f72..5f3ba5d2791b1e 100644 --- a/Lib/test/test_codecmaps_kr.py +++ b/Lib/test/test_codecmaps_kr.py @@ -4,18 +4,19 @@ # from test import multibytecodec_support +from test import support import unittest class TestCP949Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'cp949' - mapfileurl = 'http://www.pythontest.net/unicode/CP949.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/CP949.TXT' class TestEUCKRMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'euc_kr' - mapfileurl = 'http://www.pythontest.net/unicode/EUC-KR.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/EUC-KR.TXT' # A4D4 HANGUL FILLER indicates the begin of 8-bytes make-up sequence. pass_enctest = [(b'\xa4\xd4', '\u3164')] @@ -25,7 +26,7 @@ class TestEUCKRMap(multibytecodec_support.TestBase_Mapping, class TestJOHABMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'johab' - mapfileurl = 'http://www.pythontest.net/unicode/JOHAB.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/JOHAB.TXT' # KS X 1001 standard assigned 0x5c as WON SIGN. # But the early 90s is the only era that used johab widely, # most software implements it as REVERSE SOLIDUS. diff --git a/Lib/test/test_codecmaps_tw.py b/Lib/test/test_codecmaps_tw.py index 145a97d511ea9d..e714c11d64ea19 100644 --- a/Lib/test/test_codecmaps_tw.py +++ b/Lib/test/test_codecmaps_tw.py @@ -4,17 +4,18 @@ # from test import multibytecodec_support +from test import support import unittest class TestBIG5Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'big5' - mapfileurl = 'http://www.pythontest.net/unicode/BIG5.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/BIG5.TXT' class TestCP950Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'cp950' - mapfileurl = 'http://www.pythontest.net/unicode/CP950.TXT' + mapfileurl = f'{support.TEST_HTTP_URL}/unicode/CP950.TXT' pass_enctest = [ (b'\xa2\xcc', '\u5341'), (b'\xa2\xce', '\u5345'), diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index f83f73a0cc4531..890b02ca6be540 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -17,7 +17,7 @@ import unittest import warnings from test import support -from test.support import _4G, bigmemtest, import_fresh_module +from test.support import _4G, bigmemtest, import_fresh_module, TEST_HTTP_URL from http.client import HTTPException # Were we compiled --with-pydebug or with #define Py_DEBUG? @@ -50,7 +50,7 @@ def hexstr(s): return r -URL = "http://www.pythontest.net/hashlib/{}.txt" +URL = f"{TEST_HTTP_URL}/hashlib/{{}}.txt" def read_vectors(hash_name): url = URL.format(hash_name) diff --git a/Lib/test/test_normalization.py b/Lib/test/test_normalization.py index ba877e73f7d9e6..455bb4203d0666 100644 --- a/Lib/test/test_normalization.py +++ b/Lib/test/test_normalization.py @@ -1,4 +1,4 @@ -from test.support import open_urlresource +from test.support import open_urlresource, TEST_HTTP_URL import unittest from http.client import HTTPException @@ -6,7 +6,7 @@ from unicodedata import normalize, is_normalized, unidata_version TESTDATAFILE = "NormalizationTest.txt" -TESTDATAURL = "http://www.pythontest.net/unicode/" + unidata_version + "/" + TESTDATAFILE +TESTDATAURL = f"{TEST_HTTP_URL}/unicode/{unidata_version}/{TESTDATAFILE}" def check_version(testfile): hdr = testfile.readline() diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py index 84a267ad9567ee..28ff6624ea3056 100644 --- a/Lib/test/test_robotparser.py +++ b/Lib/test/test_robotparser.py @@ -335,7 +335,7 @@ def testPasswordProtectedSite(self): class NetworkTestCase(unittest.TestCase): - base_url = 'http://www.pythontest.net/' + base_url = f'{support.TEST_HTTP_URL}/' robots_txt = '{}elsewhere/robots.txt'.format(base_url) @classmethod diff --git a/Lib/test/test_ucn.py b/Lib/test/test_ucn.py index 8febf0af8627b4..ff569b3e61326c 100644 --- a/Lib/test/test_ucn.py +++ b/Lib/test/test_ucn.py @@ -172,8 +172,8 @@ def test_named_sequences_sample(self): def test_named_sequences_full(self): # Check all the named sequences - url = ("http://www.pythontest.net/unicode/%s/NamedSequences.txt" % - unicodedata.unidata_version) + url = (f"{support.TEST_HTTP_URL}/unicode/" + f"{unicodedata.unidata_version}/NamedSequences.txt") try: testdata = support.open_urlresource(url, encoding="utf-8", check=check_version) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 8c4b47720b803a..ed393742ffd0e2 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -712,7 +712,7 @@ def _reporthook(par1, par2, par3): with self.assertRaises(urllib.error.ContentTooShortError): try: - urllib.request.urlretrieve('http://www.pythontest.net/', + urllib.request.urlretrieve(f'{support.TEST_HTTP_URL}/', reporthook=_reporthook) finally: self.unfakehttp() @@ -729,7 +729,7 @@ def test_short_content_raises_ContentTooShortError_without_reporthook(self): ''') with self.assertRaises(urllib.error.ContentTooShortError): try: - urllib.request.urlretrieve('http://www.pythontest.net/') + urllib.request.urlretrieve(f'{support.TEST_HTTP_URL}/') finally: self.unfakehttp() diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index 026d6d9c82c162..b7f054e571ca8f 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -84,7 +84,7 @@ class CloseSocketTest(unittest.TestCase): def test_close(self): # calling .close() on urllib2's response objects should close the # underlying socket - url = "http://www.pythontest.net/" + url = f"{support.TEST_HTTP_URL}/" with support.transient_internet(url): response = _urlopen_with_retry(url) sock = response.fp @@ -157,23 +157,23 @@ def test_file(self): ## self._test_urls(urls, self._extra_handlers()+[bauth, dauth]) def test_urlwithfrag(self): - urlwith_frag = "http://www.pythontest.net/index.html#frag" + urlwith_frag = f"{support.TEST_HTTP_URL}/index.html#frag" with support.transient_internet(urlwith_frag): req = urllib.request.Request(urlwith_frag) res = urllib.request.urlopen(req) self.assertEqual(res.geturl(), - "http://www.pythontest.net/index.html#frag") + f"{support.TEST_HTTP_URL}/index.html#frag") def test_redirect_url_withfrag(self): - redirect_url_with_frag = "http://www.pythontest.net/redir/with_frag/" + redirect_url_with_frag = f"{support.TEST_HTTP_URL}/redir/with_frag/" with support.transient_internet(redirect_url_with_frag): req = urllib.request.Request(redirect_url_with_frag) res = urllib.request.urlopen(req) self.assertEqual(res.geturl(), - "http://www.pythontest.net/elsewhere/#frag") + f"{support.TEST_HTTP_URL}/elsewhere/#frag") def test_custom_headers(self): - url = "http://www.pythontest.net" + url = support.TEST_HTTP_URL with support.transient_internet(url): opener = urllib.request.build_opener() request = urllib.request.Request(url) @@ -259,7 +259,7 @@ def _extra_handlers(self): class TimeoutTest(unittest.TestCase): def test_http_basic(self): self.assertIsNone(socket.getdefaulttimeout()) - url = "http://www.pythontest.net" + url = support.TEST_HTTP_URL with support.transient_internet(url, timeout=None): u = _urlopen_with_retry(url) self.addCleanup(u.close) @@ -267,7 +267,7 @@ def test_http_basic(self): def test_http_default_timeout(self): self.assertIsNone(socket.getdefaulttimeout()) - url = "http://www.pythontest.net" + url = support.TEST_HTTP_URL with support.transient_internet(url): socket.setdefaulttimeout(60) try: @@ -279,7 +279,7 @@ def test_http_default_timeout(self): def test_http_no_timeout(self): self.assertIsNone(socket.getdefaulttimeout()) - url = "http://www.pythontest.net" + url = support.TEST_HTTP_URL with support.transient_internet(url): socket.setdefaulttimeout(60) try: @@ -290,7 +290,7 @@ def test_http_no_timeout(self): self.assertIsNone(u.fp.raw._sock.gettimeout()) def test_http_timeout(self): - url = "http://www.pythontest.net" + url = support.TEST_HTTP_URL with support.transient_internet(url): u = _urlopen_with_retry(url, timeout=120) self.addCleanup(u.close) diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index 4f06fbf5e6733a..c62ff65cf95ada 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -25,7 +25,7 @@ def tearDown(self): def testURLread(self): with support.transient_internet("www.pythontest.net"): - f = urllib.request.urlopen("http://www.pythontest.net/") + f = urllib.request.urlopen(f"{support.HTTP_TEST_URL}/") f.read() @@ -38,13 +38,13 @@ class urlopenNetworkTests(unittest.TestCase): for transparent redirection have been written. setUp is not used for always constructing a connection to - http://www.pythontest.net/ since there a few tests that don't use that address + :data:`test.support.TEST_HTTP_URL` since there a few tests that don't use that address and making a connection is expensive enough to warrant minimizing unneeded connections. """ - url = 'http://www.pythontest.net/' + url = f'{support.TEST_HTTP_URL}/' @contextlib.contextmanager def urlopen(self, *args, **kwargs): @@ -176,7 +176,7 @@ def test_header(self): self.assertIsInstance(info, email.message.Message, "info is not an instance of email.message.Message") - logo = "http://www.pythontest.net/" + logo = f"{support.TEST_HTTP_URL}/" def test_data_header(self): with self.urlretrieve(self.logo) as (file_location, fileheaders): diff --git a/Misc/NEWS.d/next/Tests/2019-02-21-14-23-51.bpo-36019.zS_OUi.rst b/Misc/NEWS.d/next/Tests/2019-02-21-14-23-51.bpo-36019.zS_OUi.rst new file mode 100644 index 00000000000000..4dbd2740d58041 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-02-21-14-23-51.bpo-36019.zS_OUi.rst @@ -0,0 +1,2 @@ +Add test.support.TEST_HTTP_URL (http://www.pythontest.net) for the tests. +Contributed by Stéphane Wirtel. From 689fdc6a39778e4717696d03b8fedbe9948ad7e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 15:31:59 +0100 Subject: [PATCH 05/17] Fix a test --- Lib/test/test_urllibnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index c62ff65cf95ada..5af994023cfb81 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -25,7 +25,7 @@ def tearDown(self): def testURLread(self): with support.transient_internet("www.pythontest.net"): - f = urllib.request.urlopen(f"{support.HTTP_TEST_URL}/") + f = urllib.request.urlopen(f"{support.TEST_HTTP_TEST}/") f.read() From a507631b62aa672426257ecf0d9897b055b51eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 16:26:02 +0100 Subject: [PATCH 06/17] Revert the changes in the tests with pythontest.net/unicode/ --- Lib/test/test_codecmaps_cn.py | 7 +++---- Lib/test/test_codecmaps_hk.py | 3 +-- Lib/test/test_codecmaps_jp.py | 11 +++++------ Lib/test/test_codecmaps_kr.py | 7 +++---- Lib/test/test_codecmaps_tw.py | 5 ++--- Lib/test/test_normalization.py | 4 ++-- Lib/test/test_ucn.py | 4 ++-- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Lib/test/test_codecmaps_cn.py b/Lib/test/test_codecmaps_cn.py index a9e7170c2f4ffc..89e51c6e2a193d 100644 --- a/Lib/test/test_codecmaps_cn.py +++ b/Lib/test/test_codecmaps_cn.py @@ -4,23 +4,22 @@ # from test import multibytecodec_support -from test import support import unittest class TestGB2312Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'gb2312' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/EUC-CN.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/EUC-CN.TXT' class TestGBKMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'gbk' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/CP936.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/CP936.TXT' class TestGB18030Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'gb18030' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/gb-18030-2000.xml' + mapfileurl = 'http://www.pythontest.net/unicode/gb-18030-2000.xml' if __name__ == "__main__": diff --git a/Lib/test/test_codecmaps_hk.py b/Lib/test/test_codecmaps_hk.py index 499a893031cc95..7a48d24fddbb86 100644 --- a/Lib/test/test_codecmaps_hk.py +++ b/Lib/test/test_codecmaps_hk.py @@ -4,13 +4,12 @@ # from test import multibytecodec_support -from test import support import unittest class TestBig5HKSCSMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'big5hkscs' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/BIG5HKSCS-2004.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/BIG5HKSCS-2004.TXT' if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_codecmaps_jp.py b/Lib/test/test_codecmaps_jp.py index 7d1a36b9da33eb..fdfec8085b24e4 100644 --- a/Lib/test/test_codecmaps_jp.py +++ b/Lib/test/test_codecmaps_jp.py @@ -4,13 +4,12 @@ # from test import multibytecodec_support -from test import support import unittest class TestCP932Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'cp932' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/CP932.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/CP932.TXT' supmaps = [ (b'\x80', '\u0080'), (b'\xa0', '\uf8f0'), @@ -26,14 +25,14 @@ class TestEUCJPCOMPATMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'euc_jp' mapfilename = 'EUC-JP.TXT' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/EUC-JP.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/EUC-JP.TXT' class TestSJISCOMPATMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'shift_jis' mapfilename = 'SHIFTJIS.TXT' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/SHIFTJIS.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/SHIFTJIS.TXT' pass_enctest = [ (b'\x81_', '\\'), ] @@ -47,14 +46,14 @@ class TestEUCJISX0213Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'euc_jisx0213' mapfilename = 'EUC-JISX0213.TXT' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/EUC-JISX0213.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/EUC-JISX0213.TXT' class TestSJISX0213Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'shift_jisx0213' mapfilename = 'SHIFT_JISX0213.TXT' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/SHIFT_JISX0213.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/SHIFT_JISX0213.TXT' if __name__ == "__main__": diff --git a/Lib/test/test_codecmaps_kr.py b/Lib/test/test_codecmaps_kr.py index 5f3ba5d2791b1e..1b6f5ca3080f72 100644 --- a/Lib/test/test_codecmaps_kr.py +++ b/Lib/test/test_codecmaps_kr.py @@ -4,19 +4,18 @@ # from test import multibytecodec_support -from test import support import unittest class TestCP949Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'cp949' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/CP949.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/CP949.TXT' class TestEUCKRMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'euc_kr' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/EUC-KR.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/EUC-KR.TXT' # A4D4 HANGUL FILLER indicates the begin of 8-bytes make-up sequence. pass_enctest = [(b'\xa4\xd4', '\u3164')] @@ -26,7 +25,7 @@ class TestEUCKRMap(multibytecodec_support.TestBase_Mapping, class TestJOHABMap(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'johab' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/JOHAB.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/JOHAB.TXT' # KS X 1001 standard assigned 0x5c as WON SIGN. # But the early 90s is the only era that used johab widely, # most software implements it as REVERSE SOLIDUS. diff --git a/Lib/test/test_codecmaps_tw.py b/Lib/test/test_codecmaps_tw.py index e714c11d64ea19..145a97d511ea9d 100644 --- a/Lib/test/test_codecmaps_tw.py +++ b/Lib/test/test_codecmaps_tw.py @@ -4,18 +4,17 @@ # from test import multibytecodec_support -from test import support import unittest class TestBIG5Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'big5' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/BIG5.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/BIG5.TXT' class TestCP950Map(multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'cp950' - mapfileurl = f'{support.TEST_HTTP_URL}/unicode/CP950.TXT' + mapfileurl = 'http://www.pythontest.net/unicode/CP950.TXT' pass_enctest = [ (b'\xa2\xcc', '\u5341'), (b'\xa2\xce', '\u5345'), diff --git a/Lib/test/test_normalization.py b/Lib/test/test_normalization.py index 455bb4203d0666..ba877e73f7d9e6 100644 --- a/Lib/test/test_normalization.py +++ b/Lib/test/test_normalization.py @@ -1,4 +1,4 @@ -from test.support import open_urlresource, TEST_HTTP_URL +from test.support import open_urlresource import unittest from http.client import HTTPException @@ -6,7 +6,7 @@ from unicodedata import normalize, is_normalized, unidata_version TESTDATAFILE = "NormalizationTest.txt" -TESTDATAURL = f"{TEST_HTTP_URL}/unicode/{unidata_version}/{TESTDATAFILE}" +TESTDATAURL = "http://www.pythontest.net/unicode/" + unidata_version + "/" + TESTDATAFILE def check_version(testfile): hdr = testfile.readline() diff --git a/Lib/test/test_ucn.py b/Lib/test/test_ucn.py index ff569b3e61326c..8febf0af8627b4 100644 --- a/Lib/test/test_ucn.py +++ b/Lib/test/test_ucn.py @@ -172,8 +172,8 @@ def test_named_sequences_sample(self): def test_named_sequences_full(self): # Check all the named sequences - url = (f"{support.TEST_HTTP_URL}/unicode/" - f"{unicodedata.unidata_version}/NamedSequences.txt") + url = ("http://www.pythontest.net/unicode/%s/NamedSequences.txt" % + unicodedata.unidata_version) try: testdata = support.open_urlresource(url, encoding="utf-8", check=check_version) From b1c00ebd649752908c808c874f5cde8d969b7bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 16:26:33 +0100 Subject: [PATCH 07/17] Fix typo with TEST_HTTP_URL --- Lib/test/test_urllibnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index 5af994023cfb81..ce978ead1840be 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -25,7 +25,7 @@ def tearDown(self): def testURLread(self): with support.transient_internet("www.pythontest.net"): - f = urllib.request.urlopen(f"{support.TEST_HTTP_TEST}/") + f = urllib.request.urlopen(f"{support.TEST_HTTP_URL}/") f.read() From 8fec9c6bfde4b76a7ffb641c4a60c04e26705db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 16:28:12 +0100 Subject: [PATCH 08/17] Remove the ReST role --- Lib/test/test_urllibnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index ce978ead1840be..b60d27149478e6 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -38,7 +38,7 @@ class urlopenNetworkTests(unittest.TestCase): for transparent redirection have been written. setUp is not used for always constructing a connection to - :data:`test.support.TEST_HTTP_URL` since there a few tests that don't use that address + test.support.TEST_HTTP_URL since there a few tests that don't use that address and making a connection is expensive enough to warrant minimizing unneeded connections. From e90553c99ea8229b382e253e5f92f1eb1bd80dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 17:12:57 +0100 Subject: [PATCH 09/17] Fix with the recommenation of Victor Stinner --- Doc/library/test.rst | 3 +-- Lib/test/support/__init__.py | 1 + Lib/test/test_hashlib.py | 4 ++-- Lib/test/test_robotparser.py | 6 +++--- Lib/test/test_urllib.py | 4 ++-- Lib/test/test_urllib2net.py | 10 +++++----- Lib/test/test_urllibnet.py | 8 ++++---- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 61dc6367c62932..054521dcc5d3eb 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -358,8 +358,7 @@ The :mod:`test.support` module defines the following constants: .. data:: TEST_HTTP_URL - Define the URL of a dedicated HTTP server for the network tests - (http://www.pythontest.net). + Define the URL of a dedicated HTTP server for the network tests. diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 005203d7e2a0b4..b442070b35f3f4 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -836,6 +836,7 @@ def dec(*args, **kwargs): TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid()) # Define the URL of a dedicated HTTP server for the network test. +# The URL must use clear-text HTTP: no redirection to encrypted HTTPS. TEST_HTTP_URL = "http://www.pythontest.net" # FS_NONASCII: non-ASCII character encodable by os.fsencode(), diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index 890b02ca6be540..f83f73a0cc4531 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -17,7 +17,7 @@ import unittest import warnings from test import support -from test.support import _4G, bigmemtest, import_fresh_module, TEST_HTTP_URL +from test.support import _4G, bigmemtest, import_fresh_module from http.client import HTTPException # Were we compiled --with-pydebug or with #define Py_DEBUG? @@ -50,7 +50,7 @@ def hexstr(s): return r -URL = f"{TEST_HTTP_URL}/hashlib/{{}}.txt" +URL = "http://www.pythontest.net/hashlib/{}.txt" def read_vectors(hash_name): url = URL.format(hash_name) diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py index 28ff6624ea3056..b068d39361bfc0 100644 --- a/Lib/test/test_robotparser.py +++ b/Lib/test/test_robotparser.py @@ -335,8 +335,8 @@ def testPasswordProtectedSite(self): class NetworkTestCase(unittest.TestCase): - base_url = f'{support.TEST_HTTP_URL}/' - robots_txt = '{}elsewhere/robots.txt'.format(base_url) + base_url = support.TEST_HTTP_URL + robots_txt = '{}/elsewhere/robots.txt'.format(base_url) @classmethod def setUpClass(cls): @@ -346,7 +346,7 @@ def setUpClass(cls): cls.parser.read() def url(self, path): - return '{}{}{}'.format( + return '{}/{}{}'.format( self.base_url, path, '/' if not os.path.splitext(path)[1] else '' ) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index ed393742ffd0e2..2ac73b58d83206 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -712,7 +712,7 @@ def _reporthook(par1, par2, par3): with self.assertRaises(urllib.error.ContentTooShortError): try: - urllib.request.urlretrieve(f'{support.TEST_HTTP_URL}/', + urllib.request.urlretrieve(support.TEST_HTTP_URL, reporthook=_reporthook) finally: self.unfakehttp() @@ -729,7 +729,7 @@ def test_short_content_raises_ContentTooShortError_without_reporthook(self): ''') with self.assertRaises(urllib.error.ContentTooShortError): try: - urllib.request.urlretrieve(f'{support.TEST_HTTP_URL}/') + urllib.request.urlretrieve(support.TEST_HTTP_URL) finally: self.unfakehttp() diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index b7f054e571ca8f..9497d09693831d 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -84,7 +84,7 @@ class CloseSocketTest(unittest.TestCase): def test_close(self): # calling .close() on urllib2's response objects should close the # underlying socket - url = f"{support.TEST_HTTP_URL}/" + url = support.TEST_HTTP_URL with support.transient_internet(url): response = _urlopen_with_retry(url) sock = response.fp @@ -157,20 +157,20 @@ def test_file(self): ## self._test_urls(urls, self._extra_handlers()+[bauth, dauth]) def test_urlwithfrag(self): - urlwith_frag = f"{support.TEST_HTTP_URL}/index.html#frag" + urlwith_frag = f"http://www.pythontest.net/index.html#frag" with support.transient_internet(urlwith_frag): req = urllib.request.Request(urlwith_frag) res = urllib.request.urlopen(req) self.assertEqual(res.geturl(), - f"{support.TEST_HTTP_URL}/index.html#frag") + f"http://www.pythontest.net/index.html#frag") def test_redirect_url_withfrag(self): - redirect_url_with_frag = f"{support.TEST_HTTP_URL}/redir/with_frag/" + redirect_url_with_frag = f"http://www.pythontest.net/redir/with_frag/" with support.transient_internet(redirect_url_with_frag): req = urllib.request.Request(redirect_url_with_frag) res = urllib.request.urlopen(req) self.assertEqual(res.geturl(), - f"{support.TEST_HTTP_URL}/elsewhere/#frag") + f"http://www.pythontest.net/elsewhere/#frag") def test_custom_headers(self): url = support.TEST_HTTP_URL diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index b60d27149478e6..66e9c8a9855f13 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -25,7 +25,7 @@ def tearDown(self): def testURLread(self): with support.transient_internet("www.pythontest.net"): - f = urllib.request.urlopen(f"{support.TEST_HTTP_URL}/") + f = urllib.request.urlopen(support.TEST_HTTP_URL) f.read() @@ -44,7 +44,7 @@ class urlopenNetworkTests(unittest.TestCase): """ - url = f'{support.TEST_HTTP_URL}/' + url = support.TEST_HTTP_URL @contextlib.contextmanager def urlopen(self, *args, **kwargs): @@ -90,7 +90,7 @@ def test_geturl(self): def test_getcode(self): # test getcode() with the fancy opener to get 404 error codes - URL = self.url + "XXXinvalidXXX" + URL = self.url + "/XXXinvalidXXX" with support.transient_internet(URL): with self.assertWarns(DeprecationWarning): open_url = urllib.request.FancyURLopener().open(URL) @@ -176,7 +176,7 @@ def test_header(self): self.assertIsInstance(info, email.message.Message, "info is not an instance of email.message.Message") - logo = f"{support.TEST_HTTP_URL}/" + logo = support.TEST_HTTP_URL def test_data_header(self): with self.urlretrieve(self.logo) as (file_location, fileheaders): From 65593610a3b37593acdcb597b5e14b87fcdda283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 17:14:25 +0100 Subject: [PATCH 10/17] Remove useless f-string --- Lib/test/test_urllib2net.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index 9497d09693831d..0f43d71ea67b55 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -157,20 +157,20 @@ def test_file(self): ## self._test_urls(urls, self._extra_handlers()+[bauth, dauth]) def test_urlwithfrag(self): - urlwith_frag = f"http://www.pythontest.net/index.html#frag" + urlwith_frag = "http://www.pythontest.net/index.html#frag" with support.transient_internet(urlwith_frag): req = urllib.request.Request(urlwith_frag) res = urllib.request.urlopen(req) self.assertEqual(res.geturl(), - f"http://www.pythontest.net/index.html#frag") + "http://www.pythontest.net/index.html#frag") def test_redirect_url_withfrag(self): - redirect_url_with_frag = f"http://www.pythontest.net/redir/with_frag/" + redirect_url_with_frag = "http://www.pythontest.net/redir/with_frag/" with support.transient_internet(redirect_url_with_frag): req = urllib.request.Request(redirect_url_with_frag) res = urllib.request.urlopen(req) self.assertEqual(res.geturl(), - f"http://www.pythontest.net/elsewhere/#frag") + "http://www.pythontest.net/elsewhere/#frag") def test_custom_headers(self): url = support.TEST_HTTP_URL From 37b5de3589d52012a816ced79a7c3e39b246f8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 17:37:26 +0100 Subject: [PATCH 11/17] Use http://www.pythontest.net --- Lib/test/support/__init__.py | 2 +- Lib/test/test_robotparser.py | 6 +++--- Lib/test/test_urllibnet.py | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index b442070b35f3f4..db8cd37297d611 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -837,7 +837,7 @@ def dec(*args, **kwargs): # Define the URL of a dedicated HTTP server for the network test. # The URL must use clear-text HTTP: no redirection to encrypted HTTPS. -TEST_HTTP_URL = "http://www.pythontest.net" +TEST_HTTP_URL = "http://www.example.com" # FS_NONASCII: non-ASCII character encodable by os.fsencode(), # or None if there is no such character. diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py index b068d39361bfc0..8012d12a5811f8 100644 --- a/Lib/test/test_robotparser.py +++ b/Lib/test/test_robotparser.py @@ -335,8 +335,8 @@ def testPasswordProtectedSite(self): class NetworkTestCase(unittest.TestCase): - base_url = support.TEST_HTTP_URL - robots_txt = '{}/elsewhere/robots.txt'.format(base_url) + base_url = "http://www.pythontest.net/" + robots_txt = '{}elsewhere/robots.txt'.format(base_url) @classmethod def setUpClass(cls): @@ -346,7 +346,7 @@ def setUpClass(cls): cls.parser.read() def url(self, path): - return '{}/{}{}'.format( + return '{}{}{}'.format( self.base_url, path, '/' if not os.path.splitext(path)[1] else '' ) diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index 66e9c8a9855f13..b151595f2a9ae0 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -25,7 +25,7 @@ def tearDown(self): def testURLread(self): with support.transient_internet("www.pythontest.net"): - f = urllib.request.urlopen(support.TEST_HTTP_URL) + f = urllib.request.urlopen("http://www.pythontest.net") f.read() @@ -38,13 +38,13 @@ class urlopenNetworkTests(unittest.TestCase): for transparent redirection have been written. setUp is not used for always constructing a connection to - test.support.TEST_HTTP_URL since there a few tests that don't use that address + http://www.pythontest.net since there a few tests that don't use that address and making a connection is expensive enough to warrant minimizing unneeded connections. """ - url = support.TEST_HTTP_URL + url = "http://www.pythontest.net/" @contextlib.contextmanager def urlopen(self, *args, **kwargs): @@ -90,7 +90,7 @@ def test_geturl(self): def test_getcode(self): # test getcode() with the fancy opener to get 404 error codes - URL = self.url + "/XXXinvalidXXX" + URL = self.url + "XXXinvalidXXX" with support.transient_internet(URL): with self.assertWarns(DeprecationWarning): open_url = urllib.request.FancyURLopener().open(URL) @@ -176,7 +176,7 @@ def test_header(self): self.assertIsInstance(info, email.message.Message, "info is not an instance of email.message.Message") - logo = support.TEST_HTTP_URL + logo = "http://www.pythontest.net/" def test_data_header(self): with self.urlretrieve(self.logo) as (file_location, fileheaders): From 25bf689e0aef78fa9d12c502f835ec16ab4aa0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 17:39:10 +0100 Subject: [PATCH 12/17] Remove useless modifications for the review --- Lib/test/test_robotparser.py | 2 +- Lib/test/test_urllibnet.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py index 8012d12a5811f8..84a267ad9567ee 100644 --- a/Lib/test/test_robotparser.py +++ b/Lib/test/test_robotparser.py @@ -335,7 +335,7 @@ def testPasswordProtectedSite(self): class NetworkTestCase(unittest.TestCase): - base_url = "http://www.pythontest.net/" + base_url = 'http://www.pythontest.net/' robots_txt = '{}elsewhere/robots.txt'.format(base_url) @classmethod diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index b151595f2a9ae0..d4a2443922dd14 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -38,13 +38,13 @@ class urlopenNetworkTests(unittest.TestCase): for transparent redirection have been written. setUp is not used for always constructing a connection to - http://www.pythontest.net since there a few tests that don't use that address + http://www.pythontest.net/ since there a few tests that don't use that address and making a connection is expensive enough to warrant minimizing unneeded connections. """ - url = "http://www.pythontest.net/" + url = 'http://www.pythontest.net/' @contextlib.contextmanager def urlopen(self, *args, **kwargs): From 53292868612fe2fa81ec0f32b2a7497f1294e3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 17:39:58 +0100 Subject: [PATCH 13/17] Reset TEST_HTTP_URL to http://www.pythontest.test - sorry it's my fault maybe I am tired :/ --- Lib/test/support/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index db8cd37297d611..b442070b35f3f4 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -837,7 +837,7 @@ def dec(*args, **kwargs): # Define the URL of a dedicated HTTP server for the network test. # The URL must use clear-text HTTP: no redirection to encrypted HTTPS. -TEST_HTTP_URL = "http://www.example.com" +TEST_HTTP_URL = "http://www.pythontest.net" # FS_NONASCII: non-ASCII character encodable by os.fsencode(), # or None if there is no such character. From c0622245d47f6b275a37073ca81fbdf58195232c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 20:16:42 +0100 Subject: [PATCH 14/17] Update with the remarks of Victor Stinner --- Lib/test/test_urllibnet.py | 2 +- .../next/Tests/2019-02-19-18-30-40.bpo-36019._hBHx7.rst | 2 -- .../next/Tests/2019-02-21-14-23-51.bpo-36019.zS_OUi.rst | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 Misc/NEWS.d/next/Tests/2019-02-19-18-30-40.bpo-36019._hBHx7.rst diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index d4a2443922dd14..3080b2dbcbe28c 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -25,7 +25,7 @@ def tearDown(self): def testURLread(self): with support.transient_internet("www.pythontest.net"): - f = urllib.request.urlopen("http://www.pythontest.net") + f = urllib.request.urlopen(support.TEST_HTTP_URL) f.read() diff --git a/Misc/NEWS.d/next/Tests/2019-02-19-18-30-40.bpo-36019._hBHx7.rst b/Misc/NEWS.d/next/Tests/2019-02-19-18-30-40.bpo-36019._hBHx7.rst deleted file mode 100644 index d4fc96fe0c97d3..00000000000000 --- a/Misc/NEWS.d/next/Tests/2019-02-19-18-30-40.bpo-36019._hBHx7.rst +++ /dev/null @@ -1,2 +0,0 @@ -Replace http://example.com by http://pythontest.net for some tests. -Contributed by Stéphane Wirtel diff --git a/Misc/NEWS.d/next/Tests/2019-02-21-14-23-51.bpo-36019.zS_OUi.rst b/Misc/NEWS.d/next/Tests/2019-02-21-14-23-51.bpo-36019.zS_OUi.rst index 4dbd2740d58041..b14d157ff49214 100644 --- a/Misc/NEWS.d/next/Tests/2019-02-21-14-23-51.bpo-36019.zS_OUi.rst +++ b/Misc/NEWS.d/next/Tests/2019-02-21-14-23-51.bpo-36019.zS_OUi.rst @@ -1,2 +1,2 @@ -Add test.support.TEST_HTTP_URL (http://www.pythontest.net) for the tests. -Contributed by Stéphane Wirtel. +Add test.support.TEST_HTTP_URL and replace references of http://www.example.com +by this new constant. Contributed by Stéphane Wirtel. From cfafca684344643b4096f628b19cc4012bcb36a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Thu, 21 Feb 2019 20:23:42 +0100 Subject: [PATCH 15/17] Define TEST_HOSTNAME and use it for TEST_HTTP_URL and use it in test_urllibnet --- Doc/library/test.rst | 4 ++++ Lib/test/support/__init__.py | 7 +++++-- Lib/test/test_urllibnet.py | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 054521dcc5d3eb..53c682e1ee505a 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -356,6 +356,10 @@ The :mod:`test.support` module defines the following constants: Check for presence of docstrings. +.. data:: TEST_HOSTNAME + + Define the hostname used for the network tests. + .. data:: TEST_HTTP_URL Define the URL of a dedicated HTTP server for the network tests. diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index b442070b35f3f4..223f9d1e0f3c26 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -835,9 +835,12 @@ def dec(*args, **kwargs): # module name. TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid()) -# Define the URL of a dedicated HTTP server for the network test. +# Define the hostname that we could use for the network tests. +TEST_HOSTNAME = "www.pythontest.net" + +# Define the URL of a dedicated HTTP server for the network tests. # The URL must use clear-text HTTP: no redirection to encrypted HTTPS. -TEST_HTTP_URL = "http://www.pythontest.net" +TEST_HTTP_URL = f"http://{TEST_HOSTNAME}" # FS_NONASCII: non-ASCII character encodable by os.fsencode(), # or None if there is no such character. diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index 3080b2dbcbe28c..d2da9fbfd43952 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -24,7 +24,7 @@ def tearDown(self): socket.setdefaulttimeout(None) def testURLread(self): - with support.transient_internet("www.pythontest.net"): + with support.transient_internet(support.TEST_HOSTNAME): f = urllib.request.urlopen(support.TEST_HTTP_URL) f.read() From 33a4744740da626bb9403da3b4ff0abedeadcf09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Fri, 22 Feb 2019 13:53:06 +0100 Subject: [PATCH 16/17] Revert the commit with the introduction of support.TEST_HOSTNAME --- Doc/library/test.rst | 4 ---- Lib/test/support/__init__.py | 7 ++----- Lib/test/test_urllibnet.py | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 53c682e1ee505a..054521dcc5d3eb 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -356,10 +356,6 @@ The :mod:`test.support` module defines the following constants: Check for presence of docstrings. -.. data:: TEST_HOSTNAME - - Define the hostname used for the network tests. - .. data:: TEST_HTTP_URL Define the URL of a dedicated HTTP server for the network tests. diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 223f9d1e0f3c26..b442070b35f3f4 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -835,12 +835,9 @@ def dec(*args, **kwargs): # module name. TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid()) -# Define the hostname that we could use for the network tests. -TEST_HOSTNAME = "www.pythontest.net" - -# Define the URL of a dedicated HTTP server for the network tests. +# Define the URL of a dedicated HTTP server for the network test. # The URL must use clear-text HTTP: no redirection to encrypted HTTPS. -TEST_HTTP_URL = f"http://{TEST_HOSTNAME}" +TEST_HTTP_URL = "http://www.pythontest.net" # FS_NONASCII: non-ASCII character encodable by os.fsencode(), # or None if there is no such character. diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index d2da9fbfd43952..3080b2dbcbe28c 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -24,7 +24,7 @@ def tearDown(self): socket.setdefaulttimeout(None) def testURLread(self): - with support.transient_internet(support.TEST_HOSTNAME): + with support.transient_internet("www.pythontest.net"): f = urllib.request.urlopen(support.TEST_HTTP_URL) f.read() From e4f81288cad219364b76d660d42a249ae2c60e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Wirtel?= Date: Fri, 22 Feb 2019 14:00:24 +0100 Subject: [PATCH 17/17] Compute the domain from supoort.TEST_HTTP_URL --- Lib/test/support/__init__.py | 2 +- Lib/test/test_urllibnet.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index b442070b35f3f4..c0938d90010a99 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -835,7 +835,7 @@ def dec(*args, **kwargs): # module name. TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid()) -# Define the URL of a dedicated HTTP server for the network test. +# Define the URL of a dedicated HTTP server for the network tests. # The URL must use clear-text HTTP: no redirection to encrypted HTTPS. TEST_HTTP_URL = "http://www.pythontest.net" diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index 3080b2dbcbe28c..d394ceddd080e7 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -3,6 +3,7 @@ import contextlib import socket +import urllib.parse import urllib.request import os import email.message @@ -24,7 +25,8 @@ def tearDown(self): socket.setdefaulttimeout(None) def testURLread(self): - with support.transient_internet("www.pythontest.net"): + domain = urllib.parse.urlparse(support.TEST_HTTP_URL).netloc + with support.transient_internet(domain): f = urllib.request.urlopen(support.TEST_HTTP_URL) f.read()