summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorXtreak <tir.karthi@gmail.com>2019-05-19 13:40:06 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2019-05-19 13:40:05 (GMT)
commitc661b30f89ffe7a7995538d3b1649469b184bee4 (patch)
tree9bed1700c823d8f1224b1f6968dfdf0d1b309dc1 /Lib/test
parenta5119e7d75c9729fc36c059d05f3d7132e7f6bb4 (diff)
downloadcpython-c661b30f89ffe7a7995538d3b1649469b184bee4.zip
cpython-c661b30f89ffe7a7995538d3b1649469b184bee4.tar.gz
cpython-c661b30f89ffe7a7995538d3b1649469b184bee4.tar.bz2
bpo-36948: Fix NameError in urllib.request.URLopener.retrieve (GH-13389)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_urllib.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index 7214492..74b19fb 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -1445,7 +1445,7 @@ class Utility_Tests(unittest.TestCase):
self.assertIsInstance(urllib.request.thishost(), tuple)
-class URLopener_Tests(unittest.TestCase):
+class URLopener_Tests(FakeHTTPMixin, unittest.TestCase):
"""Testcase to test the open method of URLopener class."""
def test_quoted_open(self):
@@ -1463,6 +1463,24 @@ class URLopener_Tests(unittest.TestCase):
"spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"),
"//c:|windows%/:=&?~#+!$,;'@()*[]|/path/")
+ @support.ignore_warnings(category=DeprecationWarning)
+ def test_urlopener_retrieve_file(self):
+ with support.temp_dir() as tmpdir:
+ fd, tmpfile = tempfile.mkstemp(dir=tmpdir)
+ os.close(fd)
+ fileurl = "file:" + urllib.request.pathname2url(tmpfile)
+ filename, _ = urllib.request.URLopener().retrieve(fileurl)
+ self.assertEqual(filename, tmpfile)
+
+ @support.ignore_warnings(category=DeprecationWarning)
+ def test_urlopener_retrieve_remote(self):
+ url = "http://www.python.org/file.txt"
+ self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello!")
+ self.addCleanup(self.unfakehttp)
+ filename, _ = urllib.request.URLopener().retrieve(url)
+ self.assertEqual(os.path.splitext(filename)[1], ".txt")
+
+
# Just commented them out.
# Can't really tell why keep failing in windows and sparc.
# Everywhere else they work ok, but on those machines, sometimes