Skip to content

bpo-36019: Use pythontest.net instead of example.com #11941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/library/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ 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.



The :mod:`test.support` module defines the following functions:
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,10 @@ def dec(*args, **kwargs):
# module name.
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(),
# or None if there is no such character.
FS_NONASCII = None
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_urllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(support.TEST_HTTP_URL,
reporthook=_reporthook)
finally:
self.unfakehttp()
Expand All @@ -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(support.TEST_HTTP_URL)
finally:
self.unfakehttp()

Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_urllib2net.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = support.TEST_HTTP_URL
with support.transient_internet(url):
response = _urlopen_with_retry(url)
sock = response.fp
Expand Down Expand Up @@ -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 = support.TEST_HTTP_URL
with support.transient_internet(url):
opener = urllib.request.build_opener()
request = urllib.request.Request(url)
Expand Down Expand Up @@ -259,15 +259,15 @@ def _extra_handlers(self):
class TimeoutTest(unittest.TestCase):
def test_http_basic(self):
self.assertIsNone(socket.getdefaulttimeout())
url = "http://www.example.com"
url = support.TEST_HTTP_URL
with support.transient_internet(url, timeout=None):
u = _urlopen_with_retry(url)
self.addCleanup(u.close)
self.assertIsNone(u.fp.raw._sock.gettimeout())

def test_http_default_timeout(self):
self.assertIsNone(socket.getdefaulttimeout())
url = "http://www.example.com"
url = support.TEST_HTTP_URL
with support.transient_internet(url):
socket.setdefaulttimeout(60)
try:
Expand All @@ -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 = support.TEST_HTTP_URL
with support.transient_internet(url):
socket.setdefaulttimeout(60)
try:
Expand All @@ -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 = support.TEST_HTTP_URL
with support.transient_internet(url):
u = _urlopen_with_retry(url, timeout=120)
self.addCleanup(u.close)
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_urllibnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using support.TEST_HTTP_URL here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because support.transient_internet uses a hostname and not scheme+hostname.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for that, I have introduced support.TEST_HOSTNAME

f = urllib.request.urlopen("http://www.pythontest.net")
f.read()


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Replace http://example.com by http://pythontest.net for some tests.
Contributed by Stéphane Wirtel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One NEWS entry is enough. Please merge both NEWS entries.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add test.support.TEST_HTTP_URL (http://www.pythontest.net) for the tests.
Contributed by Stéphane Wirtel.