MCPcopy Index your code
hub / github.com/RustPython/RustPython / DocTestCase

Class DocTestCase

Lib/doctest.py:2280–2442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2278
2279
2280class DocTestCase(unittest.TestCase):
2281
2282 def __init__(self, test, optionflags=0, setUp=None, tearDown=None,
2283 checker=None):
2284
2285 unittest.TestCase.__init__(self)
2286 self._dt_optionflags = optionflags
2287 self._dt_checker = checker
2288 self._dt_test = test
2289 self._dt_setUp = setUp
2290 self._dt_tearDown = tearDown
2291
2292 def setUp(self):
2293 test = self._dt_test
2294 self._dt_globs = test.globs.copy()
2295
2296 if self._dt_setUp is not None:
2297 self._dt_setUp(test)
2298
2299 def tearDown(self):
2300 test = self._dt_test
2301
2302 if self._dt_tearDown is not None:
2303 self._dt_tearDown(test)
2304
2305 # restore the original globs
2306 test.globs.clear()
2307 test.globs.update(self._dt_globs)
2308
2309 def runTest(self):
2310 test = self._dt_test
2311 old = sys.stdout
2312 new = StringIO()
2313 optionflags = self._dt_optionflags
2314
2315 if not (optionflags & REPORTING_FLAGS):
2316 # The option flags don't include any reporting flags,
2317 # so add the default reporting flags
2318 optionflags |= _unittest_reportflags
2319
2320 runner = DocTestRunner(optionflags=optionflags,
2321 checker=self._dt_checker, verbose=False)
2322
2323 try:
2324 runner.DIVIDER = "-"*70
2325 results = runner.run(test, out=new.write, clear_globs=False)
2326 if results.skipped == results.attempted:
2327 raise unittest.SkipTest("all examples were skipped")
2328 finally:
2329 sys.stdout = old
2330
2331 if results.failed:
2332 raise self.failureException(self.format_failure(new.getvalue().rstrip('\n')))
2333
2334 def format_failure(self, err):
2335 test = self._dt_test
2336 if test.lineno is None:
2337 lineno = 'unknown line number'

Callers 1

DocTestSuiteFunction · 0.85

Calls

no outgoing calls

Tested by 1

DocTestSuiteFunction · 0.68