(self)
| 599 | self.assertRaises(URLError, o.open, scheme+"://example.com/") |
| 600 | |
| 601 | def test_handled(self): |
| 602 | # handler returning non-None means no more handlers will be called |
| 603 | o = OpenerDirector() |
| 604 | meth_spec = [ |
| 605 | ["http_open", "ftp_open", "http_error_302"], |
| 606 | ["ftp_open"], |
| 607 | [("http_open", "return self")], |
| 608 | [("http_open", "return self")], |
| 609 | ] |
| 610 | handlers = add_ordered_mock_handlers(o, meth_spec) |
| 611 | |
| 612 | req = Request("http://example.com/") |
| 613 | r = o.open(req) |
| 614 | # Second .http_open() gets called, third doesn't, since second returned |
| 615 | # non-None. Handlers without .http_open() never get any methods called |
| 616 | # on them. |
| 617 | # In fact, second mock handler defining .http_open() returns self |
| 618 | # (instead of response), which becomes the OpenerDirector's return |
| 619 | # value. |
| 620 | self.assertEqual(r, handlers[2]) |
| 621 | calls = [(handlers[0], "http_open"), (handlers[2], "http_open")] |
| 622 | for expected, got in zip(calls, o.calls): |
| 623 | handler, name, args, kwds = got |
| 624 | self.assertEqual((handler, name), expected) |
| 625 | self.assertEqual(args, (req,)) |
| 626 | |
| 627 | def test_handler_order(self): |
| 628 | o = OpenerDirector() |
nothing calls this directly
no test coverage detected