55
66"""
77import unittest
8+ import test .support
89from test .support import run_unittest , TESTFN , EnvironmentVarGuard
910from test .support import captured_stderr
1011import 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+
408432def test_main ():
409- run_unittest (HelperFunctionsTests , ImportSideEffectTests )
433+ run_unittest (HelperFunctionsTests , ImportSideEffectTests , LicenseURL )
410434
411435if __name__ == "__main__" :
412436 test_main ()
0 commit comments