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

Method test_handled

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

Source from the content-addressed store, hash-verified

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
620 o = OpenerDirector()
621 meth_spec = [
622 ["http_open", "ftp_open", "http_error_302"],
623 ["ftp_open"],
624 [("http_open", "return self")],
625 [("http_open", "return self")],
626 ]
627 handlers = add_ordered_mock_handlers(o, meth_spec)
628
629 req = Request("http://example.com/")
630 r = o.open(req)
631 # Second .http_open() gets called, third doesn't, since second returned
632 # non-None. Handlers without .http_open() never get any methods called
633 # on them.
634 # In fact, second mock handler defining .http_open() returns self
635 # (instead of response), which becomes the OpenerDirector's return
636 # value.
637 self.assertEqual(r, handlers[2])
638 calls = [(handlers[0], "http_open"), (handlers[2], "http_open")]
639 for expected, got in zip(calls, o.calls):
640 handler, name, args, kwds = got
641 self.assertEqual((handler, name), expected)
642 self.assertEqual(args, (req,))
643
644 def test_handler_order(self):
645 o = OpenerDirector()

Callers

nothing calls this directly

Calls 5

openMethod · 0.95
OpenerDirectorClass · 0.90
RequestClass · 0.90
assertEqualMethod · 0.45

Tested by

no test coverage detected