diff options
| author | Facundo Batista <facundobatista@gmail.com> | 2008-05-29 16:39:26 (GMT) |
|---|---|---|
| committer | Facundo Batista <facundobatista@gmail.com> | 2008-05-29 16:39:26 (GMT) |
| commit | 4f1b1ed975fe25170d00559e63f992c9bf8e9b8a (patch) | |
| tree | 0f2a0434dc9ad0181633f649611e417aa4a6ea61 /Lib/test/test_urllib2net.py | |
| parent | f18a70720542268586e271bbadab3fb0332b8a39 (diff) | |
| download | cpython-4f1b1ed975fe25170d00559e63f992c9bf8e9b8a.zip cpython-4f1b1ed975fe25170d00559e63f992c9bf8e9b8a.tar.gz cpython-4f1b1ed975fe25170d00559e63f992c9bf8e9b8a.tar.bz2 | |
Fixed the semantic of timeout for socket.create_connection and
all the upper level libraries that use it, including urllib2.
Added and fixed some tests, and changed docs correspondingly.
Thanks to John J Lee for the patch and the pusing, :)
Diffstat (limited to 'Lib/test/test_urllib2net.py')
| -rw-r--r-- | Lib/test/test_urllib2net.py | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index 1ebaf8f..ee21c55 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -189,46 +189,58 @@ class OtherNetworkTests(unittest.TestCase): class TimeoutTest(unittest.TestCase): def test_http_basic(self): + self.assertTrue(socket.getdefaulttimeout() is None) u = _urlopen_with_retry("http://www.python.org") self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None) - def test_http_NoneWithdefault(self): - prev = socket.getdefaulttimeout() + def test_http_default_timeout(self): + self.assertTrue(socket.getdefaulttimeout() is None) + socket.setdefaulttimeout(60) + try: + u = _urlopen_with_retry("http://www.python.org") + finally: + socket.setdefaulttimeout(None) + self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 60) + + def test_http_no_timeout(self): + self.assertTrue(socket.getdefaulttimeout() is None) socket.setdefaulttimeout(60) try: u = _urlopen_with_retry("http://www.python.org", timeout=None) - self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 60) finally: - socket.setdefaulttimeout(prev) + socket.setdefaulttimeout(None) + self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None) - def test_http_Value(self): + def test_http_timeout(self): u = _urlopen_with_retry("http://www.python.org", timeout=120) self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 120) - def test_http_NoneNodefault(self): - u = _urlopen_with_retry("http://www.python.org", timeout=None) - self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None) - FTP_HOST = "ftp://ftp.mirror.nl/pub/mirror/gnu/" def test_ftp_basic(self): + self.assertTrue(socket.getdefaulttimeout() is None) u = _urlopen_with_retry(self.FTP_HOST) self.assertTrue(u.fp.fp._sock.gettimeout() is None) - def test_ftp_NoneWithdefault(self): - prev = socket.getdefaulttimeout() + def test_ftp_default_timeout(self): + self.assertTrue(socket.getdefaulttimeout() is None) socket.setdefaulttimeout(60) try: - u = _urlopen_with_retry(self.FTP_HOST, timeout=None) - self.assertEqual(u.fp.fp._sock.gettimeout(), 60) + u = _urlopen_with_retry(self.FTP_HOST) finally: - socket.setdefaulttimeout(prev) + socket.setdefaulttimeout(None) + self.assertEqual(u.fp.fp._sock.gettimeout(), 60) - def test_ftp_NoneNodefault(self): - u = _urlopen_with_retry(self.FTP_HOST, timeout=None) + def test_ftp_no_timeout(self): + self.assertTrue(socket.getdefaulttimeout() is None) + socket.setdefaulttimeout(60) + try: + u = _urlopen_with_retry(self.FTP_HOST, timeout=None) + finally: + socket.setdefaulttimeout(None) self.assertTrue(u.fp.fp._sock.gettimeout() is None) - def test_ftp_Value(self): + def test_ftp_timeout(self): u = _urlopen_with_retry(self.FTP_HOST, timeout=60) self.assertEqual(u.fp.fp._sock.gettimeout(), 60) |
