Skip to content

Commit c3a274b

Browse files
authored
[3.11] gh-108303: Move all pydoc related files to test_pydoc (GH-114506) (#115501)
(cherry picked from commit ccc76c3)
1 parent 9bb3f56 commit c3a274b

File tree

7 files changed

+32
-25
lines changed

7 files changed

+32
-25
lines changed

Lib/pydoc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def getdocloc(self, object, basedir=sysconfig.get_path('stdlib')):
524524
'_thread', 'zipimport') or
525525
(file.startswith(basedir) and
526526
not file.startswith(os.path.join(basedir, 'site-packages')))) and
527-
object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
527+
object.__name__ not in ('xml.etree', 'test.test_pydoc.pydoc_mod')):
528528
if docloc.startswith(("http://", "https://")):
529529
docloc = "{}/{}.html".format(docloc.rstrip("/"), object.__name__.lower())
530530
else:

Lib/test/libregrtest/findtests.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"test_future_stmt",
2424
"test_gdb",
2525
"test_inspect",
26+
"test_pydoc",
2627
"test_multiprocessing_fork",
2728
"test_multiprocessing_forkserver",
2829
"test_multiprocessing_spawn",

Lib/test/test_pydoc/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import os
2+
from test import support
3+
4+
5+
def load_tests(*args):
6+
return support.load_package_tests(os.path.dirname(__file__), *args)
File renamed without changes.
File renamed without changes.

Lib/test/test_pydoc.py renamed to Lib/test/test_pydoc/test_pydoc.py

+23-24
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
captured_stderr, is_emscripten, is_wasi,
3333
requires_docstrings, MISSING_C_DOCSTRINGS)
3434
from test.support.os_helper import (TESTFN, rmtree, unlink)
35-
from test import pydoc_mod
36-
from test import pydocfodder
35+
from test.test_pydoc import pydoc_mod
36+
from test.test_pydoc import pydocfodder
3737

3838

3939
class nonascii:
@@ -50,7 +50,7 @@ class nonascii:
5050

5151
expected_text_pattern = """
5252
NAME
53-
test.pydoc_mod - This is a test module for test_pydoc
53+
test.test_pydoc.pydoc_mod - This is a test module for test_pydoc
5454
%s
5555
CLASSES
5656
builtins.object
@@ -123,7 +123,7 @@ class C(builtins.object)
123123
124124
DATA
125125
__xyz__ = 'X, Y and Z'
126-
c_alias = test.pydoc_mod.C[int]
126+
c_alias = test.test_pydoc.pydoc_mod.C[int]
127127
list_alias1 = typing.List[int]
128128
list_alias2 = list[int]
129129
type_union1 = typing.Union[int, str]
@@ -146,7 +146,7 @@ class C(builtins.object)
146146
for s in expected_data_docstrings)
147147

148148
html2text_of_expected = """
149-
test.pydoc_mod (version 1.2.3.4)
149+
test.test_pydoc.pydoc_mod (version 1.2.3.4)
150150
This is a test module for test_pydoc
151151
152152
Modules
@@ -211,7 +211,7 @@ class C(builtins.object)
211211
212212
Data
213213
__xyz__ = 'X, Y and Z'
214-
c_alias = test.pydoc_mod.C[int]
214+
c_alias = test.test_pydoc.pydoc_mod.C[int]
215215
list_alias1 = typing.List[int]
216216
list_alias2 = list[int]
217217
type_union1 = typing.Union[int, str]
@@ -340,7 +340,7 @@ def get_pydoc_link(module):
340340
"Returns a documentation web link of a module"
341341
abspath = os.path.abspath
342342
dirname = os.path.dirname
343-
basedir = dirname(dirname(abspath(__file__)))
343+
basedir = dirname(dirname(dirname(abspath(__file__))))
344344
doc = pydoc.TextDoc()
345345
loc = doc.getdocloc(module, basedir=basedir)
346346
return loc
@@ -487,7 +487,7 @@ def test_not_here(self):
487487

488488
@requires_docstrings
489489
def test_not_ascii(self):
490-
result = run_pydoc('test.test_pydoc.nonascii', PYTHONIOENCODING='ascii')
490+
result = run_pydoc('test.test_pydoc.test_pydoc.nonascii', PYTHONIOENCODING='ascii')
491491
encoded = nonascii.__doc__.encode('ascii', 'backslashreplace')
492492
self.assertIn(encoded, result)
493493

@@ -667,9 +667,9 @@ def test_help_output_redirect(self):
667667
buf = StringIO()
668668
helper = pydoc.Helper(output=buf)
669669
unused, doc_loc = get_pydoc_text(pydoc_mod)
670-
module = "test.pydoc_mod"
670+
module = "test.test_pydoc.pydoc_mod"
671671
help_header = """
672-
Help on module test.pydoc_mod in test:
672+
Help on module test.test_pydoc.pydoc_mod in test.test_pydoc:
673673
674674
""".lstrip()
675675
help_header = textwrap.dedent(help_header)
@@ -1050,7 +1050,6 @@ class TestDescriptions(unittest.TestCase):
10501050

10511051
def test_module(self):
10521052
# Check that pydocfodder module can be described
1053-
from test import pydocfodder
10541053
doc = pydoc.render_doc(pydocfodder)
10551054
self.assertIn("pydocfodder", doc)
10561055

@@ -1229,7 +1228,7 @@ def cm(cls, x):
12291228
'cm(...)\n'
12301229
' A class method\n')
12311230
self.assertEqual(self._get_summary_lines(X.cm), """\
1232-
cm(x) class method of test.test_pydoc.X
1231+
cm(x) class method of test.test_pydoc.test_pydoc.X
12331232
A class method
12341233
""")
12351234
self.assertIn("""
@@ -1411,19 +1410,19 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
14111410
lines = self.getsection(result, f' | Methods {where}:', ' | ' + '-'*70)
14121411
self.assertIn(' | A_method_alias = A_method(self)', lines)
14131412
self.assertIn(' | B_method_alias = B_method(self)', lines)
1414-
self.assertIn(' | A_staticmethod(x, y) from test.pydocfodder.A', lines)
1413+
self.assertIn(' | A_staticmethod(x, y) from test.test_pydoc.pydocfodder.A', lines)
14151414
self.assertIn(' | A_staticmethod_alias = A_staticmethod(x, y)', lines)
1416-
self.assertIn(' | global_func(x, y) from test.pydocfodder', lines)
1415+
self.assertIn(' | global_func(x, y) from test.test_pydoc.pydocfodder', lines)
14171416
self.assertIn(' | global_func_alias = global_func(x, y)', lines)
1418-
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.pydocfodder', lines)
1417+
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
14191418
self.assertIn(' | __repr__(self, /) from builtins.object', lines)
14201419
self.assertIn(' | object_repr = __repr__(self, /)', lines)
14211420

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

@@ -1439,19 +1438,19 @@ def test_html_doc_routines_in_class(self, cls=pydocfodder.B):
14391438
lines = self.getsection(result, f'Methods {where}:', '-'*70)
14401439
self.assertIn('A_method_alias = A_method(self)', lines)
14411440
self.assertIn('B_method_alias = B_method(self)', lines)
1442-
self.assertIn('A_staticmethod(x, y) from test.pydocfodder.A', lines)
1441+
self.assertIn('A_staticmethod(x, y) from test.test_pydoc.pydocfodder.A', lines)
14431442
self.assertIn('A_staticmethod_alias = A_staticmethod(x, y)', lines)
1444-
self.assertIn('global_func(x, y) from test.pydocfodder', lines)
1443+
self.assertIn('global_func(x, y) from test.test_pydoc.pydocfodder', lines)
14451444
self.assertIn('global_func_alias = global_func(x, y)', lines)
1446-
self.assertIn('global_func2_alias = global_func2(x, y) from test.pydocfodder', lines)
1445+
self.assertIn('global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
14471446
self.assertIn('__repr__(self, /) from builtins.object', lines)
14481447
self.assertIn('object_repr = __repr__(self, /)', lines)
14491448

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

14561455
lines = self.getsection(result, f'Class methods {where}:', '-'*70)
14571456
self.assertIn('B_classmethod(x)', lines)

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,7 @@ TESTSUBDIRS= ctypes/test \
20302030
test/test_json \
20312031
test/test_module \
20322032
test/test_peg_generator \
2033+
test/test_pydoc \
20332034
test/test_sqlite3 \
20342035
test/test_tomllib \
20352036
test/test_tomllib/data \

0 commit comments

Comments
 (0)