Create MockHandlers and add them to an OpenerDirector. meth_spec: list of lists of tuples and strings defining methods to define on handlers. eg: [["http_error", "ftp_open"], ["http_open"]] defines methods .http_error() and .ftp_open() on one handler, and .http_open() on anot
(opener, meth_spec)
| 445 | |
| 446 | |
| 447 | def add_ordered_mock_handlers(opener, meth_spec): |
| 448 | """Create MockHandlers and add them to an OpenerDirector. |
| 449 | |
| 450 | meth_spec: list of lists of tuples and strings defining methods to define |
| 451 | on handlers. eg: |
| 452 | |
| 453 | [["http_error", "ftp_open"], ["http_open"]] |
| 454 | |
| 455 | defines methods .http_error() and .ftp_open() on one handler, and |
| 456 | .http_open() on another. These methods just record their arguments and |
| 457 | return None. Using a tuple instead of a string causes the method to |
| 458 | perform some action (see MockHandler.handle()), eg: |
| 459 | |
| 460 | [["http_error"], [("http_open", "return request")]] |
| 461 | |
| 462 | defines .http_error() on one handler (which simply returns None), and |
| 463 | .http_open() on another handler, which returns a Request object. |
| 464 | |
| 465 | """ |
| 466 | handlers = [] |
| 467 | count = 0 |
| 468 | for meths in meth_spec: |
| 469 | class MockHandlerSubclass(MockHandler): |
| 470 | pass |
| 471 | |
| 472 | h = MockHandlerSubclass(meths) |
| 473 | h.handler_order += count |
| 474 | h.add_parent(opener) |
| 475 | count = count + 1 |
| 476 | handlers.append(h) |
| 477 | opener.add_handler(h) |
| 478 | return handlers |
| 479 | |
| 480 | |
| 481 | def build_test_opener(*handler_instances): |
no test coverage detected
searching dependent graphs…