MCPcopy Index your code
hub / github.com/python/cpython / run

Method run

Lib/doctest.py:1536–1612  ·  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

1534 return self.save_linecache_getlines(filename, module_globals)
1535
1536 def run(self, test, compileflags=None, out=None, clear_globs=True):
1537 """
1538 Run the examples in `test`, and display the results using the
1539 writer function `out`.
1540
1541 The examples are run in the namespace `test.globs`. If
1542 `clear_globs` is true (the default), then this namespace will
1543 be cleared after the test runs, to help with garbage
1544 collection. If you would like to examine the namespace after
1545 the test completes, then use `clear_globs=False`.
1546
1547 `compileflags` gives the set of flags that should be used by
1548 the Python compiler when running the examples. If not
1549 specified, then it will default to the set of future-import
1550 flags that apply to `globs`.
1551
1552 The output of each example is checked using
1553 `DocTestRunner.check_output`, and the results are formatted by
1554 the `DocTestRunner.report_*` methods.
1555 """
1556 self.test = test
1557
1558 if compileflags is None:
1559 compileflags = _extract_future_flags(test.globs)
1560
1561 save_stdout = sys.stdout
1562 if out is None:
1563 encoding = save_stdout.encoding
1564 if encoding is None or encoding.lower() == 'utf-8':
1565 out = save_stdout.write
1566 else:
1567 # Use backslashreplace error handling on write
1568 def out(s):
1569 s = str(s.encode(encoding, 'backslashreplace'), encoding)
1570 save_stdout.write(s)
1571 sys.stdout = self._fakeout
1572
1573 # Patch pdb.set_trace to restore sys.stdout during interactive
1574 # debugging (so it's not still redirected to self._fakeout).
1575 # Note that the interactive output will go to *our*
1576 # save_stdout, even if that's not the real sys.stdout; this
1577 # allows us to write test cases for the set_trace behavior.
1578 save_trace = sys.gettrace()
1579 save_set_trace = pdb.set_trace
1580 self.debugger = _OutputRedirectingPdb(save_stdout)
1581 self.debugger.reset()
1582 pdb.set_trace = self.debugger.set_trace
1583
1584 # Patch linecache.getlines, so we can see the example's source
1585 # when we're inside the debugger.
1586 self.save_linecache_getlines = linecache.getlines
1587 linecache.getlines = self.__patched_linecache_getlines
1588
1589 # Make sure sys.displayhook just prints the value to stdout
1590 save_displayhook = sys.displayhook
1591 sys.displayhook = sys.__displayhook__
1592 saved_can_colorize = _colorize.can_colorize
1593 _colorize.can_colorize = lambda *args, **kwargs: False

Callers 4

testmodFunction · 0.95
testfileFunction · 0.95
run_docstring_examplesFunction · 0.95
_run_object_doctestFunction · 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