summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urllib.py
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-10-27 09:26:46 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-10-27 09:26:46 (GMT)
commitcad7b314674588f0a079de78945f8fc28d38af8c (patch)
tree5589bee9e5985719e466cd004065f33f40aca381 /Lib/test/test_urllib.py
parent45c41494bf4992d6c2a0bd1fca3d0dff164ec4ba (diff)
downloadcpython-cad7b314674588f0a079de78945f8fc28d38af8c.zip
cpython-cad7b314674588f0a079de78945f8fc28d38af8c.tar.gz
cpython-cad7b314674588f0a079de78945f8fc28d38af8c.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, 35 insertions, 0 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index c6f6f61..3fc499e 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -268,6 +268,41 @@ Content-Type: text/html; charset=iso-8859-1
finally:
self.unfakehttp()
+ def test_missing_localfile(self):
+ # Test for #10836
+ 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://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):
+ 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!")
try: