MCPcopy Index your code
hub / github.com/python/cpython / test_processors

Method test_processors

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

Source from the content-addressed store, hash-verified

696 self.assertEqual(args, got[2])
697
698 def test_processors(self):
699 # *_request / *_response methods get called appropriately
700 o = OpenerDirector()
701 meth_spec = [
702 [("http_request", "return request"),
703 ("http_response", "return response")],
704 [("http_request", "return request"),
705 ("http_response", "return response")],
706 ]
707 handlers = add_ordered_mock_handlers(o, meth_spec)
708
709 req = Request("http://example.com/")
710 o.open(req)
711 # processor methods are called on *all* handlers that define them,
712 # not just the first handler that handles the request
713 calls = [
714 (handlers[0], "http_request"), (handlers[1], "http_request"),
715 (handlers[0], "http_response"), (handlers[1], "http_response")]
716
717 for i, (handler, name, args, kwds) in enumerate(o.calls):
718 if i < 2:
719 # *_request
720 self.assertEqual((handler, name), calls[i])
721 self.assertEqual(len(args), 1)
722 self.assertIsInstance(args[0], Request)
723 else:
724 # *_response
725 self.assertEqual((handler, name), calls[i])
726 self.assertEqual(len(args), 2)
727 self.assertIsInstance(args[0], Request)
728 # response from opener.open is None, because there's no
729 # handler that defines http_open to handle it
730 if args[1] is not None:
731 self.assertIsInstance(args[1], MockResponse)
732
733
734class HandlerTests(unittest.TestCase):

Callers

nothing calls this directly

Calls 7

openMethod · 0.95
OpenerDirectorClass · 0.90
RequestClass · 0.90
enumerateFunction · 0.85
assertIsInstanceMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected