summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urllib.py
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-10-27 09:48:21 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-10-27 09:48:21 (GMT)
commitcc2f0421c70d6a68e026d074b7d1c7fa4d96e6b8 (patch)
tree05de9f6d7fdfcfd39d836696e2d9d8d2cc631d7b /Lib/test/test_urllib.py
parent5f9459fbedae091bff5b87189014a996f1352b1c (diff)
parentcad7b314674588f0a079de78945f8fc28d38af8c (diff)
downloadcpython-cc2f0421c70d6a68e026d074b7d1c7fa4d96e6b8.zip
cpython-cc2f0421c70d6a68e026d074b7d1c7fa4d96e6b8.tar.gz
cpython-cc2f0421c70d6a68e026d074b7d1c7fa4d96e6b8.tar.bz2
Issue #16250: Fix URLError invocation with proper args
Diffstat (limited to 'Lib/test/test_urllib.py')
-rw-r--r--Lib/test/test_urllib.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index 22ada56..623eb5e 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -268,6 +268,39 @@ Content-Type: text/html; charset=iso-8859-1
finally:
self.unfakehttp()
+ def test_missing_localfile(self):
+ # Test for #10836
+ # 3.3 - URLError is not captured, explicit IOError is raised.
+ with self.assertRaises(IOError):
+ urlopen('file://localhost/a/file/which/doesnot/exists.py')
+
+ 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))
+ # 3.3 - IOError instead of URLError
+ with self.assertRaises(IOError):
+ urlopen(tmp_fileurl)
+
+ def test_ftp_nohost(self):
+ test_ftp_url = 'ftp:///path'
+ # 3.3 - IOError instead of URLError
+ with self.assertRaises(IOError):
+ urlopen(test_ftp_url)
+
+ def test_ftp_nonexisting(self):
+ # 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:
@@ -300,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"""