MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / run

Method run

tools/sampcd_processor.py:474–511  ·  view source on GitHub ↗

Run the xdoctest with a docstring.

(self, api_name: str, docstring: str)

Source from the content-addressed store, hash-verified

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."""

Callers 3

run_gitFunction · 0.45
_executeMethod · 0.45
mainFunction · 0.45

Calls 6

_check_bad_statementsMethod · 0.95
_parse_directiveMethod · 0.95
_extract_examplesMethod · 0.95
_execute_xdoctestMethod · 0.95
TestResultClass · 0.90
getMethod · 0.45

Tested by 1

mainFunction · 0.36