MCPcopy Create free account
hub / github.com/python/cpython / test_badly_named_methods

Method test_badly_named_methods

Lib/test/test_urllib2.py:597–616  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

595 self.assertEqual(len(o.handle_error), 0)
596
597 def test_badly_named_methods(self):
598 # test work-around for three methods that accidentally follow the
599 # naming conventions for handler methods
600 # (*_open() / *_request() / *_response())
601
602 # These used to call the accidentally-named methods, causing a
603 # TypeError in real code; here, returning self from these mock
604 # methods would either cause no exception, or AttributeError.
605
606 from urllib.error import URLError
607
608 o = OpenerDirector()
609 meth_spec = [
610 [("do_open", "return self"), ("proxy_open", "return self")],
611 [("redirect_request", "return self")],
612 ]
613 add_ordered_mock_handlers(o, meth_spec)
614 o.add_handler(urllib.request.UnknownHandler())
615 for scheme in "do", "proxy", "redirect":
616 self.assertRaises(URLError, o.open, scheme+"://example.com/")
617
618 def test_handled(self):
619 # handler returning non-None means no more handlers will be called

Callers

nothing calls this directly

Calls 4

add_handlerMethod · 0.95
OpenerDirectorClass · 0.90
assertRaisesMethod · 0.45

Tested by

no test coverage detected