mirror of https://github.com/python/cpython
Merged revisions 85893 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r85893 | georg.brandl | 2010-10-28 16:55:02 +0200 (jeu., 28 oct. 2010) | 1 line #10116: wrap transient_internet() around net access in test_urllib2net. ........
This commit is contained in:
parent
a4f1afa640
commit
27683c954b
|
@ -154,6 +154,7 @@ class OtherNetworkTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_urlwithfrag(self):
|
def test_urlwithfrag(self):
|
||||||
urlwith_frag = "http://docs.python.org/glossary.html#glossary"
|
urlwith_frag = "http://docs.python.org/glossary.html#glossary"
|
||||||
|
with support.transient_internet(urlwith_frag):
|
||||||
req = urllib.request.Request(urlwith_frag)
|
req = urllib.request.Request(urlwith_frag)
|
||||||
res = urllib.request.urlopen(req)
|
res = urllib.request.urlopen(req)
|
||||||
self.assertEqual(res.geturl(),
|
self.assertEqual(res.geturl(),
|
||||||
|
@ -161,6 +162,7 @@ class OtherNetworkTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_custom_headers(self):
|
def test_custom_headers(self):
|
||||||
url = "http://www.example.com"
|
url = "http://www.example.com"
|
||||||
|
with support.transient_internet(url):
|
||||||
opener = urllib.request.build_opener()
|
opener = urllib.request.build_opener()
|
||||||
request = urllib.request.Request(url)
|
request = urllib.request.Request(url)
|
||||||
self.assertFalse(request.header_items())
|
self.assertFalse(request.header_items())
|
||||||
|
@ -186,6 +188,7 @@ class OtherNetworkTests(unittest.TestCase):
|
||||||
url, req, expected_err = url
|
url, req, expected_err = url
|
||||||
else:
|
else:
|
||||||
req = expected_err = None
|
req = expected_err = None
|
||||||
|
with support.transient_internet(url):
|
||||||
debug(url)
|
debug(url)
|
||||||
try:
|
try:
|
||||||
f = urlopen(url, req, TIMEOUT)
|
f = urlopen(url, req, TIMEOUT)
|
||||||
|
@ -227,40 +230,50 @@ class OtherNetworkTests(unittest.TestCase):
|
||||||
class TimeoutTest(unittest.TestCase):
|
class TimeoutTest(unittest.TestCase):
|
||||||
def test_http_basic(self):
|
def test_http_basic(self):
|
||||||
self.assertTrue(socket.getdefaulttimeout() is None)
|
self.assertTrue(socket.getdefaulttimeout() is None)
|
||||||
u = _urlopen_with_retry("http://www.python.org")
|
url = "http://www.python.org"
|
||||||
|
with support.transient_internet(url, timeout=None):
|
||||||
|
u = _urlopen_with_retry(url)
|
||||||
self.assertTrue(u.fp.raw._sock.gettimeout() is None)
|
self.assertTrue(u.fp.raw._sock.gettimeout() is None)
|
||||||
|
|
||||||
def test_http_default_timeout(self):
|
def test_http_default_timeout(self):
|
||||||
self.assertTrue(socket.getdefaulttimeout() is None)
|
self.assertTrue(socket.getdefaulttimeout() is None)
|
||||||
|
url = "http://www.python.org"
|
||||||
|
with support.transient_internet(url):
|
||||||
socket.setdefaulttimeout(60)
|
socket.setdefaulttimeout(60)
|
||||||
try:
|
try:
|
||||||
u = _urlopen_with_retry("http://www.python.org")
|
u = _urlopen_with_retry(url)
|
||||||
finally:
|
finally:
|
||||||
socket.setdefaulttimeout(None)
|
socket.setdefaulttimeout(None)
|
||||||
self.assertEqual(u.fp.raw._sock.gettimeout(), 60)
|
self.assertEqual(u.fp.raw._sock.gettimeout(), 60)
|
||||||
|
|
||||||
def test_http_no_timeout(self):
|
def test_http_no_timeout(self):
|
||||||
self.assertTrue(socket.getdefaulttimeout() is None)
|
self.assertTrue(socket.getdefaulttimeout() is None)
|
||||||
|
url = "http://www.python.org"
|
||||||
|
with support.transient_internet(url):
|
||||||
socket.setdefaulttimeout(60)
|
socket.setdefaulttimeout(60)
|
||||||
try:
|
try:
|
||||||
u = _urlopen_with_retry("http://www.python.org", timeout=None)
|
u = _urlopen_with_retry(url, timeout=None)
|
||||||
finally:
|
finally:
|
||||||
socket.setdefaulttimeout(None)
|
socket.setdefaulttimeout(None)
|
||||||
self.assertTrue(u.fp.raw._sock.gettimeout() is None)
|
self.assertTrue(u.fp.raw._sock.gettimeout() is None)
|
||||||
|
|
||||||
def test_http_timeout(self):
|
def test_http_timeout(self):
|
||||||
u = _urlopen_with_retry("http://www.python.org", timeout=120)
|
url = "http://www.python.org"
|
||||||
|
with support.transient_internet(url):
|
||||||
|
u = _urlopen_with_retry(url, timeout=120)
|
||||||
self.assertEqual(u.fp.raw._sock.gettimeout(), 120)
|
self.assertEqual(u.fp.raw._sock.gettimeout(), 120)
|
||||||
|
|
||||||
FTP_HOST = "ftp://ftp.mirror.nl/pub/mirror/gnu/"
|
FTP_HOST = "ftp://ftp.mirror.nl/pub/mirror/gnu/"
|
||||||
|
|
||||||
def test_ftp_basic(self):
|
def test_ftp_basic(self):
|
||||||
self.assertTrue(socket.getdefaulttimeout() is None)
|
self.assertTrue(socket.getdefaulttimeout() is None)
|
||||||
|
with support.transient_internet(self.FTP_HOST, timeout=None):
|
||||||
u = _urlopen_with_retry(self.FTP_HOST)
|
u = _urlopen_with_retry(self.FTP_HOST)
|
||||||
self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
|
self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
|
||||||
|
|
||||||
def test_ftp_default_timeout(self):
|
def test_ftp_default_timeout(self):
|
||||||
self.assertTrue(socket.getdefaulttimeout() is None)
|
self.assertTrue(socket.getdefaulttimeout() is None)
|
||||||
|
with support.transient_internet(self.FTP_HOST):
|
||||||
socket.setdefaulttimeout(60)
|
socket.setdefaulttimeout(60)
|
||||||
try:
|
try:
|
||||||
u = _urlopen_with_retry(self.FTP_HOST)
|
u = _urlopen_with_retry(self.FTP_HOST)
|
||||||
|
@ -270,6 +283,7 @@ class TimeoutTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_ftp_no_timeout(self):
|
def test_ftp_no_timeout(self):
|
||||||
self.assertTrue(socket.getdefaulttimeout() is None)
|
self.assertTrue(socket.getdefaulttimeout() is None)
|
||||||
|
with support.transient_internet(self.FTP_HOST):
|
||||||
socket.setdefaulttimeout(60)
|
socket.setdefaulttimeout(60)
|
||||||
try:
|
try:
|
||||||
u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
|
u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
|
||||||
|
@ -278,6 +292,7 @@ class TimeoutTest(unittest.TestCase):
|
||||||
self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
|
self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
|
||||||
|
|
||||||
def test_ftp_timeout(self):
|
def test_ftp_timeout(self):
|
||||||
|
with support.transient_internet(self.FTP_HOST):
|
||||||
u = _urlopen_with_retry(self.FTP_HOST, timeout=60)
|
u = _urlopen_with_retry(self.FTP_HOST, timeout=60)
|
||||||
self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
|
self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue