Skip to content

gh-108303: Move all doctest related files and tests to Lib/test/test_doctest/ #112109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/doctest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ That's all you need to know to start making productive use of :mod:`doctest`!
Jump in. The following sections provide full details. Note that there are many
examples of doctests in the standard Python test suite and libraries.
Especially useful examples can be found in the standard test file
:file:`Lib/test/test_doctest.py`.
:file:`Lib/test/test_doctest/test_doctest.py`.


.. _doctest-simple-testmod:
Expand Down
1 change: 1 addition & 0 deletions Lib/test/libregrtest/findtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SPLITTESTDIRS: set[TestName] = {
"test_asyncio",
"test_concurrent_futures",
"test_doctests",
"test_future_stmt",
"test_gdb",
"test_inspect",
Expand Down
20 changes: 20 additions & 0 deletions Lib/test/support/pty_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,23 @@ def terminate(proc):
input = b"" # Stop writing
if not input:
sel.modify(master, selectors.EVENT_READ)


######################################################################
## Fake stdin (for testing interactive debugging)
######################################################################

class FakeInput:
"""
A fake input stream for pdb's interactive debugger. Whenever a
line is read, print it (to simulate the user typing it), and then
return it. The set of lines to return is specified in the
constructor; they should not have trailing newlines.
"""
def __init__(self, lines):
self.lines = lines

def readline(self):
line = self.lines.pop(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling list.pop(0) frequently is inefficient. Maybe the constructor should create a collections.deque() and call self.lines.popleft() instead?

Copy link
Member Author

@sobolevn sobolevn Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is usually used in cases like sys.stdin = FakeInput(['next', 'print(x)', 'continue']), I don't think it matters much. But, I can do this if you want :)

print(line)
return line + '\n'
5 changes: 5 additions & 0 deletions Lib/test/test_doctest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os
from test.support import load_package_tests

def load_tests(*args):
return load_package_tests(os.path.dirname(__file__), *args)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def bar():
def test_silly_setup():
"""

>>> import test.test_doctest
>>> test.test_doctest.sillySetup
>>> import test.test_doctest.test_doctest
>>> test.test_doctest.test_doctest.sillySetup
True
"""

Expand Down
Loading