Merge #18206: Fix test for existence of license URL.
This test will fail because a previous attempt to fix a merge error in site.py was incorrect, but the test wasn't running so it wasn't caught. The next commit will fix the site.py bug.
This commit is contained in:
commit
f11caa0bba
|
@ -13,6 +13,8 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import encodings
|
import encodings
|
||||||
|
import urllib.request
|
||||||
|
import urllib.error
|
||||||
import subprocess
|
import subprocess
|
||||||
import sysconfig
|
import sysconfig
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
@ -403,27 +405,19 @@ class ImportSideEffectTests(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
self.fail("sitecustomize not imported automatically")
|
self.fail("sitecustomize not imported automatically")
|
||||||
|
|
||||||
|
@test.support.requires_resource('network')
|
||||||
class LicenseURL(unittest.TestCase):
|
def test_license_exists_at_url(self):
|
||||||
"""Test accessibility of the license."""
|
# This test is a bit fragile since it depends on the format of the
|
||||||
|
# string displayed by license in the absence of a LICENSE file.
|
||||||
@unittest.skipUnless(str(license).startswith('See http://'),
|
url = license._Printer__data.split()[1]
|
||||||
'license is available as a file')
|
req = urllib.request.Request(url, method='HEAD')
|
||||||
def test_license_page(self):
|
|
||||||
"""urlopen should return the license page"""
|
|
||||||
pat = r'^See (http://www\.python\.org/download/releases/[^/]+/license/)$'
|
|
||||||
mo = re.search(pat, str(license))
|
|
||||||
self.assertIsNotNone(mo, msg='can\'t find appropriate url in license')
|
|
||||||
if mo is not None:
|
|
||||||
url = mo.group(1)
|
|
||||||
with test.support.transient_internet(url):
|
|
||||||
import urllib.request, urllib.error
|
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(url) as data:
|
with test.support.transient_internet(url):
|
||||||
|
with urllib.request.urlopen(req) as data:
|
||||||
code = data.getcode()
|
code = data.getcode()
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
code = e.code
|
code = e.code
|
||||||
self.assertEqual(code, 200, msg=url)
|
self.assertEqual(code, 200, msg="Can't find " + url)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue