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

Method __run

Lib/doctest.py:1344–1483  ·  view source on GitHub ↗

Run the examples in `test`. Write the outcome of each example with one of the `DocTestRunner.report_*` methods, using the writer function `out`. `compileflags` is the set of compiler flags that should be used to execute examples. Return a TestResults insta

(self, test, compileflags, out)

Source from the content-addressed store, hash-verified

1342 #/////////////////////////////////////////////////////////////////
1343
1344 def __run(self, test, compileflags, out):
1345 """
1346 Run the examples in `test`. Write the outcome of each example
1347 with one of the `DocTestRunner.report_*` methods, using the
1348 writer function `out`. `compileflags` is the set of compiler
1349 flags that should be used to execute examples. Return a TestResults
1350 instance. The examples are run in the namespace `test.globs`.
1351 """
1352 # Keep track of the number of failed, attempted, skipped examples.
1353 failures = attempted = skips = 0
1354
1355 # Save the option flags (since option directives can be used
1356 # to modify them).
1357 original_optionflags = self.optionflags
1358
1359 SUCCESS, FAILURE, BOOM = range(3) # `outcome` state
1360
1361 check = self._checker.check_output
1362
1363 # Process each example.
1364 for examplenum, example in enumerate(test.examples):
1365 attempted += 1
1366
1367 # If REPORT_ONLY_FIRST_FAILURE is set, then suppress
1368 # reporting after the first failure.
1369 quiet = (self.optionflags & REPORT_ONLY_FIRST_FAILURE and
1370 failures > 0)
1371
1372 # Merge in the example's options.
1373 self.optionflags = original_optionflags
1374 if example.options:
1375 for (optionflag, val) in example.options.items():
1376 if val:
1377 self.optionflags |= optionflag
1378 else:
1379 self.optionflags &= ~optionflag
1380
1381 # If 'SKIP' is set, then skip this example.
1382 if self.optionflags & SKIP:
1383 skips += 1
1384 continue
1385
1386 # Record that we started this example.
1387 if not quiet:
1388 self.report_start(out, test, example)
1389
1390 # Use a special filename for compile(), so we can retrieve
1391 # the source code during interactive debugging (see
1392 # __patched_linecache_getlines).
1393 filename = '<doctest %s[%d]>' % (test.name, examplenum)
1394
1395 # Run the example in the given context (globs), and record
1396 # any exception that gets raised. (But don't intercept
1397 # keyboard interrupts.)
1398 try:
1399 # Don't blink! This is where the user's code gets run.
1400 exec(compile(example.source, filename, "single",
1401 compileflags, True), test.globs)

Callers 1

runMethod · 0.95

Calls 15

report_startMethod · 0.95
report_successMethod · 0.95
report_failureMethod · 0.95
__record_outcomeMethod · 0.95
enumerateFunction · 0.85
issubclassFunction · 0.85
nextFunction · 0.85
_exception_tracebackFunction · 0.85
_strip_exception_detailsFunction · 0.85
format_exception_onlyMethod · 0.80
compileFunction · 0.70

Tested by

no test coverage detected