diff -r e0bc42883ecd Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py Sun Jun 01 13:47:34 2014 -0700 +++ b/Lib/test/test_urllib.py Sat Jun 07 12:44:37 2014 -0700 @@ -89,6 +89,26 @@ http.client.HTTPConnection = self._connection_class +class FakeFTPMixin(object): + def fakeftp(self): + class FakeFtpWrapper(object): + def __init__(self, user, passwd, host, port, dirs, timeout=None, + persistent=True): + pass + + def retrfile(self, file, type): + return io.StringIO(), 0 + + def close(self): + pass + + self._ftpwrapper_class = urllib.request.ftpwrapper + urllib.request.ftpwrapper = FakeFtpWrapper + + def unfakeftp(self): + urllib.request.ftpwrapper = self._ftpwrapper_class + + class urlopen_FileTests(unittest.TestCase): """Test urlopen() opening a temporary file. @@ -195,7 +215,7 @@ self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com') self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com')) -class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin): +class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin, FakeFTPMixin): """Test urlopen() opening a fake http connection.""" def check_read(self, ver): @@ -309,6 +329,13 @@ self.assertFalse(e.exception.filename) self.assertTrue(e.exception.reason) + def test_ftp_cache_pruning(self): + urllib.request.MAXFTPCACHE = 0 + self.fakeftp() + urllib.request.ftpcache['test'] = urllib.request.ftpwrapper('user', 'pass', 'localhost', 21, []) + urlopen('ftp://localhost') + self.unfakeftp() + def test_userpass_inurl(self): self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!")