Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9853da

Browse files
committed
Refactor test_urllib2. Include test_HTTPError_interface under MiscTests
1 parent 660e89b commit e9853da

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

Lib/test/test_urllib2.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,10 @@ def _test_basic_auth(self, opener, auth_handler, auth_header,
13871387

13881388
class MiscTests(unittest.TestCase):
13891389

1390+
def opener_has_handler(self, opener, handler_class):
1391+
self.assertTrue(any(h.__class__ == handler_class
1392+
for h in opener.handlers))
1393+
13901394
def test_build_opener(self):
13911395
class MyHTTPHandler(urllib.request.HTTPHandler): pass
13921396
class FooHandler(urllib.request.BaseHandler):
@@ -1439,10 +1443,22 @@ def test_issue16464(self):
14391443
self.assertEqual(b"1234567890", request.data)
14401444
self.assertEqual("10", request.get_header("Content-length"))
14411445

1442-
1443-
def opener_has_handler(self, opener, handler_class):
1444-
self.assertTrue(any(h.__class__ == handler_class
1445-
for h in opener.handlers))
1446+
def test_HTTPError_interface(self):
1447+
"""
1448+
Issue 13211 reveals that HTTPError didn't implement the URLError
1449+
interface even though HTTPError is a subclass of URLError.
1450+
1451+
>>> msg = 'something bad happened'
1452+
>>> url = code = fp = None
1453+
>>> hdrs = 'Content-Length: 42'
1454+
>>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp)
1455+
>>> assert hasattr(err, 'reason')
1456+
>>> err.reason
1457+
'something bad happened'
1458+
>>> assert hasattr(err, 'headers')
1459+
>>> err.headers
1460+
'Content-Length: 42'
1461+
"""
14461462

14471463
class RequestTests(unittest.TestCase):
14481464

@@ -1514,23 +1530,6 @@ def test_url_fragment(self):
15141530
req = Request(url)
15151531
self.assertEqual(req.get_full_url(), url)
15161532

1517-
def test_HTTPError_interface():
1518-
"""
1519-
Issue 13211 reveals that HTTPError didn't implement the URLError
1520-
interface even though HTTPError is a subclass of URLError.
1521-
1522-
>>> msg = 'something bad happened'
1523-
>>> url = code = fp = None
1524-
>>> hdrs = 'Content-Length: 42'
1525-
>>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp)
1526-
>>> assert hasattr(err, 'reason')
1527-
>>> err.reason
1528-
'something bad happened'
1529-
>>> assert hasattr(err, 'headers')
1530-
>>> err.headers
1531-
'Content-Length: 42'
1532-
"""
1533-
15341533
def test_main(verbose=None):
15351534
from test import test_urllib2
15361535
support.run_doctest(test_urllib2, verbose)

0 commit comments

Comments
 (0)