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

Method run

Lib/doctest.py:1509–1585  ·  view source on GitHub ↗

Run the examples in `test`, and display the results using the writer function `out`. The examples are run in the namespace `test.globs`. If `clear_globs` is true (the default), then this namespace will be cleared after the test runs, to help with garbage

(self, test, compileflags=None, out=None, clear_globs=True)

Source from the content-addressed store, hash-verified

1507 return self.save_linecache_getlines(filename, module_globals)
1508
1509 def run(self, test, compileflags=None, out=None, clear_globs=True):
1510 """
1511 Run the examples in `test`, and display the results using the
1512 writer function `out`.
1513
1514 The examples are run in the namespace `test.globs`. If
1515 `clear_globs` is true (the default), then this namespace will
1516 be cleared after the test runs, to help with garbage
1517 collection. If you would like to examine the namespace after
1518 the test completes, then use `clear_globs=False`.
1519
1520 `compileflags` gives the set of flags that should be used by
1521 the Python compiler when running the examples. If not
1522 specified, then it will default to the set of future-import
1523 flags that apply to `globs`.
1524
1525 The output of each example is checked using
1526 `DocTestRunner.check_output`, and the results are formatted by
1527 the `DocTestRunner.report_*` methods.
1528 """
1529 self.test = test
1530
1531 if compileflags is None:
1532 compileflags = _extract_future_flags(test.globs)
1533
1534 save_stdout = sys.stdout
1535 if out is None:
1536 encoding = save_stdout.encoding
1537 if encoding is None or encoding.lower() == 'utf-8':
1538 out = save_stdout.write
1539 else:
1540 # Use backslashreplace error handling on write
1541 def out(s):
1542 s = str(s.encode(encoding, 'backslashreplace'), encoding)
1543 save_stdout.write(s)
1544 sys.stdout = self._fakeout
1545
1546 # Patch pdb.set_trace to restore sys.stdout during interactive
1547 # debugging (so it's not still redirected to self._fakeout).
1548 # Note that the interactive output will go to *our*
1549 # save_stdout, even if that's not the real sys.stdout; this
1550 # allows us to write test cases for the set_trace behavior.
1551 save_trace = sys.gettrace()
1552 save_set_trace = pdb.set_trace
1553 self.debugger = _OutputRedirectingPdb(save_stdout)
1554 self.debugger.reset()
1555 pdb.set_trace = self.debugger.set_trace
1556
1557 # Patch linecache.getlines, so we can see the example's source
1558 # when we're inside the debugger.
1559 self.save_linecache_getlines = linecache.getlines
1560 linecache.getlines = self.__patched_linecache_getlines
1561
1562 # Make sure sys.displayhook just prints the value to stdout
1563 save_displayhook = sys.displayhook
1564 sys.displayhook = sys.__displayhook__
1565 saved_can_colorize = _colorize.can_colorize
1566 _colorize.can_colorize = lambda *args, **kwargs: False

Callers 4

testmodFunction · 0.95
testfileFunction · 0.95
run_docstring_examplesFunction · 0.95
runTestMethod · 0.95

Calls 8

__runMethod · 0.95
_extract_future_flagsFunction · 0.85
lowerMethod · 0.45
resetMethod · 0.45
popMethod · 0.45
itemsMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected