MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_processors

Method test_processors

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

Source from the content-addressed store, hash-verified

679 self.assertEqual(args, got[2])
680
681 def test_processors(self):
682 # *_request / *_response methods get called appropriately
683 o = OpenerDirector()
684 meth_spec = [
685 [("http_request", "return request"),
686 ("http_response", "return response")],
687 [("http_request", "return request"),
688 ("http_response", "return response")],
689 ]
690 handlers = add_ordered_mock_handlers(o, meth_spec)
691
692 req = Request("http://example.com/")
693 o.open(req)
694 # processor methods are called on *all* handlers that define them,
695 # not just the first handler that handles the request
696 calls = [
697 (handlers[0], "http_request"), (handlers[1], "http_request"),
698 (handlers[0], "http_response"), (handlers[1], "http_response")]
699
700 for i, (handler, name, args, kwds) in enumerate(o.calls):
701 if i < 2:
702 # *_request
703 self.assertEqual((handler, name), calls[i])
704 self.assertEqual(len(args), 1)
705 self.assertIsInstance(args[0], Request)
706 else:
707 # *_response
708 self.assertEqual((handler, name), calls[i])
709 self.assertEqual(len(args), 2)
710 self.assertIsInstance(args[0], Request)
711 # response from opener.open is None, because there's no
712 # handler that defines http_open to handle it
713 if args[1] is not None:
714 self.assertIsInstance(args[1], MockResponse)
715
716
717class HandlerTests(unittest.TestCase):

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected