Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ef519b

Browse files
committed
Fix License URL display and add test to check for license url presence.
Fixes issue #18206 Patch contributed by Berker Peksag and py.user
1 parent 1b90227 commit 8ef519b

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

Lib/site.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ def setcopyright():
451451
for supporting Python development. See www.python.org for more information.""")
452452
here = os.path.dirname(os.__file__)
453453
builtins.license = _Printer(
454-
"license", "See http://www.python.org/%.3s/license.html" % sys.version,
454+
"license",
455+
"See http://www.python.org/download/releases/%.5s/license/" % sys.version,
455456
["LICENSE.txt", "LICENSE"],
456457
[os.path.join(here, os.pardir), here, os.curdir])
457458

Lib/test/test_site.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
"""
77
import unittest
8+
import test.support
89
from test.support import run_unittest, TESTFN, EnvironmentVarGuard
910
from test.support import captured_stderr
1011
import builtins
@@ -377,9 +378,10 @@ def test_setting_quit(self):
377378
self.assertTrue(hasattr(builtins, "exit"))
378379

379380
def test_setting_copyright(self):
380-
# 'copyright' and 'credits' should be in builtins
381+
# 'copyright', 'credits', and 'license' should be in builtins
381382
self.assertTrue(hasattr(builtins, "copyright"))
382383
self.assertTrue(hasattr(builtins, "credits"))
384+
self.assertTrue(hasattr(builtins, "license"))
383385

384386
def test_setting_help(self):
385387
# 'help' should be set in builtins
@@ -405,8 +407,30 @@ def test_sitecustomize_executed(self):
405407
else:
406408
self.fail("sitecustomize not imported automatically")
407409

410+
411+
class LicenseURL(unittest.TestCase):
412+
"""Test accessibility of the license."""
413+
414+
@unittest.skipUnless(str(license).startswith('See http://'),
415+
'license is available as a file')
416+
def test_license_page(self):
417+
"""urlopen should return the license page"""
418+
pat = r'^See (http://www\.python\.org/download/releases/[^/]+/license/)$'
419+
mo = re.search(pat, str(license))
420+
self.assertIsNotNone(mo, msg='can\'t find appropriate url in license')
421+
if mo is not None:
422+
url = mo.group(1)
423+
with test.support.transient_internet(url):
424+
import urllib.request, urllib.error
425+
try:
426+
with urllib.request.urlopen(url) as data:
427+
code = data.getcode()
428+
except urllib.error.HTTPError as e:
429+
code = e.code
430+
self.assertEqual(code, 200, msg=url)
431+
408432
def test_main():
409-
run_unittest(HelperFunctionsTests, ImportSideEffectTests)
433+
run_unittest(HelperFunctionsTests, ImportSideEffectTests, LicenseURL)
410434

411435
if __name__ == "__main__":
412436
test_main()

0 commit comments

Comments
 (0)