Run the xdoctest with a docstring.
(self, api_name: str, docstring: str)
| 472 | return bad_results |
| 473 | |
| 474 | def run(self, api_name: str, docstring: str) -> list[TestResult]: |
| 475 | """Run the xdoctest with a docstring.""" |
| 476 | # check bad statements |
| 477 | bad_results = self._check_bad_statements(docstring) |
| 478 | if bad_results: |
| 479 | for bad_statement in bad_results: |
| 480 | logger.warning("%s >>> %s", api_name, bad_statement.msg) |
| 481 | |
| 482 | return [ |
| 483 | TestResult( |
| 484 | name=api_name, |
| 485 | badstatement=True, |
| 486 | ) |
| 487 | ] |
| 488 | |
| 489 | # parse global directive |
| 490 | docstring, directives = self._parse_directive(docstring) |
| 491 | |
| 492 | # extract xdoctest examples |
| 493 | examples_to_test, examples_nocode = self._extract_examples( |
| 494 | api_name, docstring, **directives |
| 495 | ) |
| 496 | |
| 497 | # run xdoctest |
| 498 | try: |
| 499 | result = self._execute_xdoctest( |
| 500 | examples_to_test, examples_nocode, **directives |
| 501 | ) |
| 502 | except queue.Empty: |
| 503 | result = [ |
| 504 | TestResult( |
| 505 | name=api_name, |
| 506 | timeout=True, |
| 507 | time=directives.get('timeout', TEST_TIMEOUT), |
| 508 | ) |
| 509 | ] |
| 510 | |
| 511 | return result |
| 512 | |
| 513 | def _extract_examples(self, api_name, docstring, **directives): |
| 514 | """Extract code block examples from docstring.""" |