]> granicus.if.org Git - python/commitdiff
Issue #16250: Fix URLError invocation with proper args
authorSenthil Kumaran <senthil@uthcode.com>
Sat, 27 Oct 2012 09:48:21 +0000 (02:48 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Sat, 27 Oct 2012 09:48:21 +0000 (02:48 -0700)
1  2 
Lib/test/test_urllib.py
Lib/urllib/request.py
Misc/NEWS

index 22ada56d0c8d15087535c78900c634f40e68eb31,3fc499ec0762fdff3085e052e85bf08825a6aa64..623eb5ef2f948b839fb0099b86aab9e14fc9d387
@@@ -268,6 -268,41 +268,39 @@@ Content-Type: text/html; charset=iso-88
          finally:
              self.unfakehttp()
  
 -        with self.assertRaises(urllib.error.URLError) as e:
+     def test_missing_localfile(self):
+         # Test for #10836
 -        self.assertTrue(e.exception.filename)
 -        self.assertTrue(e.exception.reason)
++        # 3.3 - URLError is not captured, explicit IOError is raised.
++        with self.assertRaises(IOError):
+             urlopen('file://localhost/a/file/which/doesnot/exists.py')
 -        with self.assertRaises(urllib.error.URLError):
+     def test_file_notexists(self):
+         fd, tmp_file = tempfile.mkstemp()
+         tmp_fileurl = 'file://localhost/' + tmp_file.replace(os.path.sep, '/')
+         try:
+             self.assertTrue(os.path.exists(tmp_file))
+             with urlopen(tmp_fileurl) as fobj:
+                 self.assertTrue(fobj)
+         finally:
+             os.close(fd)
+             os.unlink(tmp_file)
+         self.assertFalse(os.path.exists(tmp_file))
 -        with self.assertRaises(urllib.error.URLError) as e:
++        # 3.3 - IOError instead of URLError
++        with self.assertRaises(IOError):
+             urlopen(tmp_fileurl)
+     def test_ftp_nohost(self):
+         test_ftp_url = 'ftp:///path'
 -        self.assertFalse(e.exception.filename)
 -        self.assertTrue(e.exception.reason)
++        # 3.3 - IOError instead of URLError
++        with self.assertRaises(IOError):
+             urlopen(test_ftp_url)
 -        with self.assertRaises(urllib.error.URLError) as e:
+     def test_ftp_nonexisting(self):
 -        self.assertFalse(e.exception.filename)
 -        self.assertTrue(e.exception.reason)
++        # 3.3 - IOError instead of URLError
++        with self.assertRaises(IOError):
+             urlopen('ftp://localhost/a/file/which/doesnot/exists.py')
      def test_userpass_inurl(self):
          self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!")
          try:
          finally:
              self.unfakehttp()
  
-             warn = urllib.request.URLopener()
 +    def test_URLopener_deprecation(self):
 +        with support.check_warnings(('',DeprecationWarning)):
++            urllib.request.URLopener()
 +
  class urlretrieve_FileTests(unittest.TestCase):
      """Test urllib.urlretrieve() on local files"""
  
Simple merge
diff --cc Misc/NEWS
index da227f7382901104b03b282db6408d7356fe8020,a7af2ccf3df3dddbf70c1df69f6bc7216fbe77ec..e0a54cbe016becd9277c6b6c21d6df5cd8c06458
+++ b/Misc/NEWS
@@@ -49,10 -132,10 +49,12 @@@ Core and Builtin
  Library
  -------
  
 -- Issue #16305: Fix a segmentation fault occurring when interrupting
 -  math.factorial.
+ - Issue #16250: Fix URLError invocation with proper args.
 +- Issue #16116: Fix include and library paths to be correct when building C
 +  extensions in venvs.
 +
 +- Issue #16245: Fix the value of a few entities in html.entities.html5.
  
  - Issue #14398: Fix size truncation and overflow bugs in the bz2 module.