summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-03-02 04:01:37 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2015-03-02 04:01:37 (GMT)
commitfc080fcc7cb4bcb08b076e819fe6e7aadc2a1c13 (patch)
tree2417a7c8540b2af44f65ae720a93bd8b60d1d30f
parentf2d4e5773a5fb2e6e58ad758ba5266fe82a86edf (diff)
parentbcdfc6a1fa9eabb06b886a82218ebae3384784d0 (diff)
downloadcpython-fc080fcc7cb4bcb08b076e819fe6e7aadc2a1c13.zip
cpython-fc080fcc7cb4bcb08b076e819fe6e7aadc2a1c13.tar.gz
cpython-fc080fcc7cb4bcb08b076e819fe6e7aadc2a1c13.tar.bz2
Issue #23387: Skip test_issue16464 if it raises an 5xx error.
Also, remove support.run_doctest() since there is no doctests in test_urllib2 and urllib.request.
-rw-r--r--Lib/test/support/__init__.py2
-rw-r--r--Lib/test/test_urllib2.py32
2 files changed, 13 insertions, 21 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 7bfa12c..0ef2e8a 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -1325,6 +1325,8 @@ def transient_internet(resource_name, *, timeout=30.0, errnos=()):
n = getattr(err, 'errno', None)
if (isinstance(err, socket.timeout) or
(isinstance(err, socket.gaierror) and n in gai_errnos) or
+ (isinstance(err, urllib.error.HTTPError) and
+ 500 <= err.code <= 599) or
(isinstance(err, urllib.error.URLError) and
"ConnectionRefusedError" in err.reason) or
n in captured_errnos):
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 3182390..36d7e87 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1484,17 +1484,18 @@ class MiscTests(unittest.TestCase):
@unittest.skipUnless(support.is_resource_enabled('network'),
'test requires network access')
def test_issue16464(self):
- opener = urllib.request.build_opener()
- request = urllib.request.Request("http://www.example.com/")
- self.assertEqual(None, request.data)
+ with support.transient_internet("http://www.example.com/"):
+ opener = urllib.request.build_opener()
+ request = urllib.request.Request("http://www.example.com/")
+ self.assertEqual(None, request.data)
- opener.open(request, "1".encode("us-ascii"))
- self.assertEqual(b"1", request.data)
- self.assertEqual("1", request.get_header("Content-length"))
+ opener.open(request, "1".encode("us-ascii"))
+ self.assertEqual(b"1", request.data)
+ self.assertEqual("1", request.get_header("Content-length"))
- opener.open(request, "1234567890".encode("us-ascii"))
- self.assertEqual(b"1234567890", request.data)
- self.assertEqual("10", request.get_header("Content-length"))
+ opener.open(request, "1234567890".encode("us-ascii"))
+ self.assertEqual(b"1234567890", request.data)
+ self.assertEqual("10", request.get_header("Content-length"))
def test_HTTPError_interface(self):
"""
@@ -1645,17 +1646,6 @@ class RequestTests(unittest.TestCase):
req = Request(url)
self.assertEqual(req.get_full_url(), req.full_url)
-def test_main(verbose=None):
- from test import test_urllib2
- support.run_doctest(test_urllib2, verbose)
- support.run_doctest(urllib.request, verbose)
- tests = (TrivialTests,
- OpenerDirectorTests,
- HandlerTests,
- MiscTests,
- RequestTests,
- RequestHdrsTests)
- support.run_unittest(*tests)
if __name__ == "__main__":
- test_main(verbose=True)
+ unittest.main()