Skip to content

Commit e558181

Browse files
committed
Issue python#20939: Use www.example.com instead of www.python.org to avoid test
failures when ssl is not present.
1 parent fd9262c commit e558181

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

Lib/test/test_urllib2net.py

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_close(self):
8484
# calling .close() on urllib2's response objects should close the
8585
# underlying socket
8686

87-
response = _urlopen_with_retry("http://www.python.org/")
87+
response = _urlopen_with_retry("http://www.example.com/")
8888
sock = response.fp
8989
self.assertTrue(not sock.closed)
9090
response.close()
@@ -254,15 +254,15 @@ def _extra_handlers(self):
254254
class TimeoutTest(unittest.TestCase):
255255
def test_http_basic(self):
256256
self.assertTrue(socket.getdefaulttimeout() is None)
257-
url = "http://www.python.org"
257+
url = "http://www.example.com"
258258
with support.transient_internet(url, timeout=None):
259259
u = _urlopen_with_retry(url)
260260
self.addCleanup(u.close)
261261
self.assertTrue(u.fp.raw._sock.gettimeout() is None)
262262

263263
def test_http_default_timeout(self):
264264
self.assertTrue(socket.getdefaulttimeout() is None)
265-
url = "http://www.python.org"
265+
url = "http://www.example.com"
266266
with support.transient_internet(url):
267267
socket.setdefaulttimeout(60)
268268
try:
@@ -274,7 +274,7 @@ def test_http_default_timeout(self):
274274

275275
def test_http_no_timeout(self):
276276
self.assertTrue(socket.getdefaulttimeout() is None)
277-
url = "http://www.python.org"
277+
url = "http://www.example.com"
278278
with support.transient_internet(url):
279279
socket.setdefaulttimeout(60)
280280
try:
@@ -285,7 +285,7 @@ def test_http_no_timeout(self):
285285
self.assertTrue(u.fp.raw._sock.gettimeout() is None)
286286

287287
def test_http_timeout(self):
288-
url = "http://www.python.org"
288+
url = "http://www.example.com"
289289
with support.transient_internet(url):
290290
u = _urlopen_with_retry(url, timeout=120)
291291
self.addCleanup(u.close)

Lib/test/test_urllibnet.py

100644100755
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def tearDown(self):
2424
socket.setdefaulttimeout(None)
2525

2626
def testURLread(self):
27-
with support.transient_internet("www.python.org"):
28-
f = urllib.request.urlopen("http://www.python.org/")
27+
with support.transient_internet("www.example.com"):
28+
f = urllib.request.urlopen("http://www.example.com/")
2929
x = f.read()
3030

3131

@@ -38,7 +38,7 @@ class urlopenNetworkTests(unittest.TestCase):
3838
for transparent redirection have been written.
3939
4040
setUp is not used for always constructing a connection to
41-
http://www.python.org/ since there a few tests that don't use that address
41+
http://www.example.com/ since there a few tests that don't use that address
4242
and making a connection is expensive enough to warrant minimizing unneeded
4343
connections.
4444
@@ -56,7 +56,7 @@ def urlopen(self, *args, **kwargs):
5656

5757
def test_basic(self):
5858
# Simple test expected to pass.
59-
with self.urlopen("http://www.python.org/") as open_url:
59+
with self.urlopen("http://www.example.com/") as open_url:
6060
for attr in ("read", "readline", "readlines", "fileno", "close",
6161
"info", "geturl"):
6262
self.assertTrue(hasattr(open_url, attr), "object returned from "
@@ -65,15 +65,15 @@ def test_basic(self):
6565

6666
def test_readlines(self):
6767
# Test both readline and readlines.
68-
with self.urlopen("http://www.python.org/") as open_url:
68+
with self.urlopen("http://www.example.com/") as open_url:
6969
self.assertIsInstance(open_url.readline(), bytes,
7070
"readline did not return a string")
7171
self.assertIsInstance(open_url.readlines(), list,
7272
"readlines did not return a list")
7373

7474
def test_info(self):
7575
# Test 'info'.
76-
with self.urlopen("http://www.python.org/") as open_url:
76+
with self.urlopen("http://www.example.com/") as open_url:
7777
info_obj = open_url.info()
7878
self.assertIsInstance(info_obj, email.message.Message,
7979
"object returned by 'info' is not an "
@@ -82,14 +82,14 @@ def test_info(self):
8282

8383
def test_geturl(self):
8484
# Make sure same URL as opened is returned by geturl.
85-
URL = "http://www.python.org/"
85+
URL = "http://www.example.com/"
8686
with self.urlopen(URL) as open_url:
8787
gotten_url = open_url.geturl()
8888
self.assertEqual(gotten_url, URL)
8989

9090
def test_getcode(self):
9191
# test getcode() with the fancy opener to get 404 error codes
92-
URL = "http://www.python.org/XXXinvalidXXX"
92+
URL = "http://www.example.com/XXXinvalidXXX"
9393
with support.transient_internet(URL):
9494
open_url = urllib.request.FancyURLopener().open(URL)
9595
try:
@@ -104,7 +104,7 @@ def test_fileno(self):
104104
# test can't pass on Windows.
105105
return
106106
# Make sure fd returned by fileno is valid.
107-
with self.urlopen("http://www.python.org/", timeout=None) as open_url:
107+
with self.urlopen("http://www.example.com/", timeout=None) as open_url:
108108
fd = open_url.fileno()
109109
with os.fdopen(fd, 'rb') as f:
110110
self.assertTrue(f.read(), "reading from file created using fd "
@@ -148,7 +148,7 @@ def urlretrieve(self, *args):
148148

149149
def test_basic(self):
150150
# Test basic functionality.
151-
with self.urlretrieve("http://www.python.org/") as (file_location, info):
151+
with self.urlretrieve("http://www.example.com/") as (file_location, info):
152152
self.assertTrue(os.path.exists(file_location), "file location returned by"
153153
" urlretrieve is not a valid path")
154154
with open(file_location, 'rb') as f:
@@ -157,7 +157,7 @@ def test_basic(self):
157157

158158
def test_specified_path(self):
159159
# Make sure that specifying the location of the file to write to works.
160-
with self.urlretrieve("http://www.python.org/",
160+
with self.urlretrieve("http://www.example.com/",
161161
support.TESTFN) as (file_location, info):
162162
self.assertEqual(file_location, support.TESTFN)
163163
self.assertTrue(os.path.exists(file_location))
@@ -166,12 +166,12 @@ def test_specified_path(self):
166166

167167
def test_header(self):
168168
# Make sure header returned as 2nd value from urlretrieve is good.
169-
with self.urlretrieve("http://www.python.org/") as (file_location, info):
169+
with self.urlretrieve("http://www.example.com/") as (file_location, info):
170170
self.assertIsInstance(info, email.message.Message,
171171
"info is not an instance of email.message.Message")
172172

173173
def test_data_header(self):
174-
logo = "http://www.python.org/static/community_logos/python-logo-master-v3-TM.png"
174+
logo = "http://www.example.com/"
175175
with self.urlretrieve(logo) as (file_location, fileheaders):
176176
datevalue = fileheaders.get('Date')
177177
dateformat = '%a, %d %b %Y %H:%M:%S GMT'

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ Library
7676
- Issue #21323: Fix http.server to again handle scripts in CGI subdirectories,
7777
broken by the fix for security issue #19435. Patch by Zach Byrne.
7878

79+
Tests
80+
-----
81+
82+
- Issue #20939: Avoid various network test failures due to new
83+
redirect of http://www.python.org/ to https://www.python.org:
84+
use http://www.example.com instead.
85+
7986

8087
What's New in Python 3.2.5?
8188
===========================

0 commit comments

Comments
 (0)