summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urllib2.py
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2013-03-19 19:07:43 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2013-03-19 19:07:43 (GMT)
commite9853daff9b42f9167d55640e52cff9b89f589eb (patch)
treefea485db5dfd4dc0f17be46060a89fb1f6247d48 /Lib/test/test_urllib2.py
parent660e89b163b52de6fbcdb4b0d963b2baf4da1d9d (diff)
downloadcpython-e9853daff9b42f9167d55640e52cff9b89f589eb.zip
cpython-e9853daff9b42f9167d55640e52cff9b89f589eb.tar.gz
cpython-e9853daff9b42f9167d55640e52cff9b89f589eb.tar.bz2
Refactor test_urllib2. Include test_HTTPError_interface under MiscTests
Diffstat (limited to 'Lib/test/test_urllib2.py')
-rw-r--r--Lib/test/test_urllib2.py41
1 files changed, 20 insertions, 21 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index f16dc08..b56877a 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1387,6 +1387,10 @@ class HandlerTests(unittest.TestCase):
class MiscTests(unittest.TestCase):
+ def opener_has_handler(self, opener, handler_class):
+ self.assertTrue(any(h.__class__ == handler_class
+ for h in opener.handlers))
+
def test_build_opener(self):
class MyHTTPHandler(urllib.request.HTTPHandler): pass
class FooHandler(urllib.request.BaseHandler):
@@ -1439,10 +1443,22 @@ class MiscTests(unittest.TestCase):
self.assertEqual(b"1234567890", request.data)
self.assertEqual("10", request.get_header("Content-length"))
-
- def opener_has_handler(self, opener, handler_class):
- self.assertTrue(any(h.__class__ == handler_class
- for h in opener.handlers))
+ def test_HTTPError_interface(self):
+ """
+ Issue 13211 reveals that HTTPError didn't implement the URLError
+ interface even though HTTPError is a subclass of URLError.
+
+ >>> msg = 'something bad happened'
+ >>> url = code = fp = None
+ >>> hdrs = 'Content-Length: 42'
+ >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp)
+ >>> assert hasattr(err, 'reason')
+ >>> err.reason
+ 'something bad happened'
+ >>> assert hasattr(err, 'headers')
+ >>> err.headers
+ 'Content-Length: 42'
+ """
class RequestTests(unittest.TestCase):
@@ -1514,23 +1530,6 @@ class RequestTests(unittest.TestCase):
req = Request(url)
self.assertEqual(req.get_full_url(), url)
-def test_HTTPError_interface():
- """
- Issue 13211 reveals that HTTPError didn't implement the URLError
- interface even though HTTPError is a subclass of URLError.
-
- >>> msg = 'something bad happened'
- >>> url = code = fp = None
- >>> hdrs = 'Content-Length: 42'
- >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp)
- >>> assert hasattr(err, 'reason')
- >>> err.reason
- 'something bad happened'
- >>> assert hasattr(err, 'headers')
- >>> err.headers
- 'Content-Length: 42'
- """
-
def test_main(verbose=None):
from test import test_urllib2
support.run_doctest(test_urllib2, verbose)