Skip to content
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

gh-108303: Move all pydoc related files to test_pydoc #114506

Merged
merged 3 commits into from
Feb 13, 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 Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def getdocloc(self, object, basedir=sysconfig.get_path('stdlib')):
'_thread', 'zipimport') or
(file.startswith(basedir) and
not file.startswith(os.path.join(basedir, 'site-packages')))) and
object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
object.__name__ not in ('xml.etree', 'test.test_pydoc.pydoc_mod')):
if docloc.startswith(("http://", "https://")):
docloc = "{}/{}.html".format(docloc.rstrip("/"), object.__name__.lower())
else:
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 @@ -23,6 +23,7 @@
"test_future_stmt",
"test_gdb",
"test_inspect",
"test_pydoc",
"test_multiprocessing_fork",
"test_multiprocessing_forkserver",
"test_multiprocessing_spawn",
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_pydoc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
from test import support


def load_tests(*args):
return support.load_package_tests(os.path.dirname(__file__), *args)
File renamed without changes.
File renamed without changes.
51 changes: 25 additions & 26 deletions Lib/test/test_pydoc.py → Lib/test/test_pydoc/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
captured_stderr, is_emscripten, is_wasi,
requires_docstrings, MISSING_C_DOCSTRINGS)
from test.support.os_helper import (TESTFN, rmtree, unlink)
from test import pydoc_mod
from test import pydocfodder
from test.test_pydoc import pydoc_mod
from test.test_pydoc import pydocfodder


class nonascii:
Expand All @@ -52,7 +52,7 @@ class nonascii:

expected_text_pattern = """
NAME
test.pydoc_mod - This is a test module for test_pydoc
test.test_pydoc.pydoc_mod - This is a test module for test_pydoc
%s
CLASSES
builtins.object
Expand Down Expand Up @@ -125,7 +125,7 @@ class C(builtins.object)

DATA
__xyz__ = 'X, Y and Z'
c_alias = test.pydoc_mod.C[int]
c_alias = test.test_pydoc.pydoc_mod.C[int]
list_alias1 = typing.List[int]
list_alias2 = list[int]
type_union1 = typing.Union[int, str]
Expand All @@ -148,7 +148,7 @@ class C(builtins.object)
for s in expected_data_docstrings)

html2text_of_expected = """
test.pydoc_mod (version 1.2.3.4)
test.test_pydoc.pydoc_mod (version 1.2.3.4)
This is a test module for test_pydoc

Modules
Expand Down Expand Up @@ -213,7 +213,7 @@ class C(builtins.object)

Data
__xyz__ = 'X, Y and Z'
c_alias = test.pydoc_mod.C[int]
c_alias = test.test_pydoc.pydoc_mod.C[int]
list_alias1 = typing.List[int]
list_alias2 = list[int]
type_union1 = typing.Union[int, str]
Expand Down Expand Up @@ -342,7 +342,7 @@ def get_pydoc_link(module):
"Returns a documentation web link of a module"
abspath = os.path.abspath
dirname = os.path.dirname
basedir = dirname(dirname(abspath(__file__)))
basedir = dirname(dirname(dirname(abspath(__file__))))
doc = pydoc.TextDoc()
loc = doc.getdocloc(module, basedir=basedir)
return loc
Expand Down Expand Up @@ -489,7 +489,7 @@ def test_not_here(self):

@requires_docstrings
def test_not_ascii(self):
result = run_pydoc('test.test_pydoc.nonascii', PYTHONIOENCODING='ascii')
result = run_pydoc('test.test_pydoc.test_pydoc.nonascii', PYTHONIOENCODING='ascii')
encoded = nonascii.__doc__.encode('ascii', 'backslashreplace')
self.assertIn(encoded, result)

Expand Down Expand Up @@ -669,9 +669,9 @@ def test_help_output_redirect(self):
buf = StringIO()
helper = pydoc.Helper(output=buf)
unused, doc_loc = get_pydoc_text(pydoc_mod)
module = "test.pydoc_mod"
module = "test.test_pydoc.pydoc_mod"
help_header = """
Help on module test.pydoc_mod in test:
Help on module test.test_pydoc.pydoc_mod in test.test_pydoc:

""".lstrip()
help_header = textwrap.dedent(help_header)
Expand Down Expand Up @@ -1142,7 +1142,6 @@ class TestDescriptions(unittest.TestCase):

def test_module(self):
# Check that pydocfodder module can be described
from test import pydocfodder
doc = pydoc.render_doc(pydocfodder)
self.assertIn("pydocfodder", doc)

Expand Down Expand Up @@ -1425,10 +1424,10 @@ def smeth(*args, **kwargs):
self.assertEqual(self._get_summary_line(C.meth),
"meth" + unbound)
self.assertEqual(self._get_summary_line(C().meth),
"meth" + bound + " method of test.test_pydoc.C instance")
"meth" + bound + " method of test.test_pydoc.test_pydoc.C instance")
C.cmeth.__func__.__text_signature__ = text_signature
self.assertEqual(self._get_summary_line(C.cmeth),
"cmeth" + bound + " class method of test.test_pydoc.C")
"cmeth" + bound + " class method of test.test_pydoc.test_pydoc.C")
C.smeth.__text_signature__ = text_signature
self.assertEqual(self._get_summary_line(C.smeth),
"smeth" + unbound)
Expand Down Expand Up @@ -1465,7 +1464,7 @@ def cm(cls, x):
'cm(...)\n'
' A class method\n')
self.assertEqual(self._get_summary_lines(X.cm), """\
cm(x) class method of test.test_pydoc.X
cm(x) class method of test.test_pydoc.test_pydoc.X
A class method
""")
self.assertIn("""
Expand Down Expand Up @@ -1647,19 +1646,19 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
lines = self.getsection(result, f' | Methods {where}:', ' | ' + '-'*70)
self.assertIn(' | A_method_alias = A_method(self)', lines)
self.assertIn(' | B_method_alias = B_method(self)', lines)
self.assertIn(' | A_staticmethod(x, y) from test.pydocfodder.A', lines)
self.assertIn(' | A_staticmethod(x, y) from test.test_pydoc.pydocfodder.A', lines)
self.assertIn(' | A_staticmethod_alias = A_staticmethod(x, y)', lines)
self.assertIn(' | global_func(x, y) from test.pydocfodder', lines)
self.assertIn(' | global_func(x, y) from test.test_pydoc.pydocfodder', lines)
self.assertIn(' | global_func_alias = global_func(x, y)', lines)
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.pydocfodder', lines)
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
self.assertIn(' | __repr__(self, /) from builtins.object', lines)
self.assertIn(' | object_repr = __repr__(self, /)', lines)

lines = self.getsection(result, f' | Static methods {where}:', ' | ' + '-'*70)
self.assertIn(' | A_classmethod_ref = A_classmethod(x) class method of test.pydocfodder.A', lines)
note = '' if cls is pydocfodder.B else ' class method of test.pydocfodder.B'
self.assertIn(' | A_classmethod_ref = A_classmethod(x) class method of test.test_pydoc.pydocfodder.A', lines)
note = '' if cls is pydocfodder.B else ' class method of test.test_pydoc.pydocfodder.B'
self.assertIn(' | B_classmethod_ref = B_classmethod(x)' + note, lines)
self.assertIn(' | A_method_ref = A_method() method of test.pydocfodder.A instance', lines)
self.assertIn(' | A_method_ref = A_method() method of test.test_pydoc.pydocfodder.A instance', lines)
self.assertIn(' | get(key, default=None, /) method of builtins.dict instance', lines)
self.assertIn(' | dict_get = get(key, default=None, /) method of builtins.dict instance', lines)

Expand All @@ -1675,19 +1674,19 @@ def test_html_doc_routines_in_class(self, cls=pydocfodder.B):
lines = self.getsection(result, f'Methods {where}:', '-'*70)
self.assertIn('A_method_alias = A_method(self)', lines)
self.assertIn('B_method_alias = B_method(self)', lines)
self.assertIn('A_staticmethod(x, y) from test.pydocfodder.A', lines)
self.assertIn('A_staticmethod(x, y) from test.test_pydoc.pydocfodder.A', lines)
self.assertIn('A_staticmethod_alias = A_staticmethod(x, y)', lines)
self.assertIn('global_func(x, y) from test.pydocfodder', lines)
self.assertIn('global_func(x, y) from test.test_pydoc.pydocfodder', lines)
self.assertIn('global_func_alias = global_func(x, y)', lines)
self.assertIn('global_func2_alias = global_func2(x, y) from test.pydocfodder', lines)
self.assertIn('global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
self.assertIn('__repr__(self, /) from builtins.object', lines)
self.assertIn('object_repr = __repr__(self, /)', lines)

lines = self.getsection(result, f'Static methods {where}:', '-'*70)
self.assertIn('A_classmethod_ref = A_classmethod(x) class method of test.pydocfodder.A', lines)
note = '' if cls is pydocfodder.B else ' class method of test.pydocfodder.B'
self.assertIn('A_classmethod_ref = A_classmethod(x) class method of test.test_pydoc.pydocfodder.A', lines)
note = '' if cls is pydocfodder.B else ' class method of test.test_pydoc.pydocfodder.B'
self.assertIn('B_classmethod_ref = B_classmethod(x)' + note, lines)
self.assertIn('A_method_ref = A_method() method of test.pydocfodder.A instance', lines)
self.assertIn('A_method_ref = A_method() method of test.test_pydoc.pydocfodder.A instance', lines)

lines = self.getsection(result, f'Class methods {where}:', '-'*70)
self.assertIn('B_classmethod(x)', lines)
Expand Down
1 change: 1 addition & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -2307,6 +2307,7 @@ TESTSUBDIRS= idlelib/idle_test \
test/test_module \
test/test_pathlib \
test/test_peg_generator \
test/test_pydoc \
test/test_sqlite3 \
test/test_tkinter \
test/test_tomllib \
Expand Down
Loading