diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2012-10-22 01:31:25 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2012-10-22 01:31:25 (GMT) |
commit | 3ebef36eeaef414642df120341b30ec27966e353 (patch) | |
tree | 0ec69aff61b9b48f7487cc411c214d170aeb0837 /Lib/test/test_urllib.py | |
parent | 1348747052def615eeacb6e9be341b2b21ef5e97 (diff) | |
download | cpython-3ebef36eeaef414642df120341b30ec27966e353.zip cpython-3ebef36eeaef414642df120341b30ec27966e353.tar.gz cpython-3ebef36eeaef414642df120341b30ec27966e353.tar.bz2 |
Issue #16250: Fix the invocations of URLError which had misplaced filename attribute for exception
Diffstat (limited to 'Lib/test/test_urllib.py')
-rw-r--r-- | Lib/test/test_urllib.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 5721296..85e54bf 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -270,8 +270,36 @@ Content-Type: text/html; charset=iso-8859-1 def test_missing_localfile(self): # Test for #10836 - with self.assertRaises(urllib.error.URLError): + with self.assertRaises(urllib.error.URLError) as e: urlopen('file://localhost/a/file/which/doesnot/exists.py') + self.assertTrue(e.exception.filename) + self.assertTrue(e.exception.reason) + + def test_file_notexists(self): + fd, tmp_file = tempfile.mkstemp() + tmp_fileurl = 'file://' + tmp_file + + self.assertTrue(os.path.exists(tmp_file)) + self.assertTrue(urlopen(tmp_fileurl)) + + os.unlink(tmp_file) + self.assertFalse(os.path.exists(tmp_file)) + with self.assertRaises(urllib.error.URLError): + urlopen(tmp_fileurl) + + def test_ftp_nohost(self): + test_ftp_url = 'ftp:///path' + with self.assertRaises(urllib.error.URLError) as e: + urlopen(test_ftp_url) + self.assertFalse(e.exception.filename) + self.assertTrue(e.exception.reason) + + def test_ftp_nonexisting(self): + with self.assertRaises(urllib.error.URLError) as e: + urlopen('ftp://localhost/a/file/which/doesnot/exists.py') + self.assertFalse(e.exception.filename) + self.assertTrue(e.exception.reason) + def test_userpass_inurl(self): self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!") @@ -305,7 +333,7 @@ Content-Type: text/html; charset=iso-8859-1 def test_URLopener_deprecation(self): with support.check_warnings(('',DeprecationWarning)): - warn = urllib.request.URLopener() + urllib.request.URLopener() class urlretrieve_FileTests(unittest.TestCase): """Test urllib.urlretrieve() on local files""" |