summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_site.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-09-14 17:28:37 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-09-14 17:28:37 (GMT)
commit1bc6ceba923e41a85d529aefbc0bbb8c1dd4bd10 (patch)
tree6bdd27d218284e20de2f8389c2d80962593499c9 /Lib/test/test_site.py
parent0a9d05155c52456797e6875eb13a9bc463c25d31 (diff)
downloadcpython-1bc6ceba923e41a85d529aefbc0bbb8c1dd4bd10.zip
cpython-1bc6ceba923e41a85d529aefbc0bbb8c1dd4bd10.tar.gz
cpython-1bc6ceba923e41a85d529aefbc0bbb8c1dd4bd10.tar.bz2
#18206: Fix test for existence of license URL.
It now always checks, instead of only when the LICENSE file doesn't exist. It is also protected by the 'network' resource, and uses a HEAD request since we are only doing an existence check.
Diffstat (limited to 'Lib/test/test_site.py')
-rw-r--r--Lib/test/test_site.py38
1 files changed, 15 insertions, 23 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 2392d43..16081a1 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -13,6 +13,8 @@ import os
import sys
import re
import encodings
+import urllib.request
+import urllib.error
import subprocess
import sysconfig
from copy import copy
@@ -407,30 +409,20 @@ class ImportSideEffectTests(unittest.TestCase):
else:
self.fail("sitecustomize not imported automatically")
-
-class LicenseURL(unittest.TestCase):
- """Test accessibility of the license."""
-
- @unittest.skipUnless(str(license).startswith('See http://'),
- 'license is available as a file')
- 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)
+ @test.support.requires_resource('network')
+ def test_license_exists_at_url(self):
+ # 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.
+ url = license._Printer__data.split()[1]
+ req = urllib.request.Request(url, method='HEAD')
+ try:
with test.support.transient_internet(url):
- import urllib.request, urllib.error
- try:
- with urllib.request.urlopen(url) as data:
- code = data.getcode()
- except urllib.error.HTTPError as e:
- code = e.code
- self.assertEqual(code, 200, msg=url)
+ with urllib.request.urlopen(req) as data:
+ code = data.getcode()
+ except urllib.error.HTTPError as e:
+ code = e.code
+ self.assertEqual(code, 200, msg="Can't find " + url)
-def test_main():
- run_unittest(HelperFunctionsTests, ImportSideEffectTests, LicenseURL)
if __name__ == "__main__":
- test_main()
+ unittest.main()