Skip to content

Commit ccc76c3

Browse files
authored
gh-108303: Move all pydoc related test files to new test.test_pydoc package (#114506)
1 parent ca3604a commit ccc76c3

File tree

7 files changed

+34
-27
lines changed

7 files changed

+34
-27
lines changed

Lib/pydoc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def getdocloc(self, object, basedir=sysconfig.get_path('stdlib')):
552552
'_thread', 'zipimport') or
553553
(file.startswith(basedir) and
554554
not file.startswith(os.path.join(basedir, 'site-packages')))) and
555-
object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
555+
object.__name__ not in ('xml.etree', 'test.test_pydoc.pydoc_mod')):
556556
if docloc.startswith(("http://", "https://")):
557557
docloc = "{}/{}.html".format(docloc.rstrip("/"), object.__name__.lower())
558558
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

+25-26
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
captured_stderr, is_emscripten, is_wasi,
3535
requires_docstrings, MISSING_C_DOCSTRINGS)
3636
from test.support.os_helper import (TESTFN, rmtree, unlink)
37-
from test import pydoc_mod
38-
from test import pydocfodder
37+
from test.test_pydoc import pydoc_mod
38+
from test.test_pydoc import pydocfodder
3939

4040

4141
class nonascii:
@@ -52,7 +52,7 @@ class nonascii:
5252

5353
expected_text_pattern = """
5454
NAME
55-
test.pydoc_mod - This is a test module for test_pydoc
55+
test.test_pydoc.pydoc_mod - This is a test module for test_pydoc
5656
%s
5757
CLASSES
5858
builtins.object
@@ -125,7 +125,7 @@ class C(builtins.object)
125125
126126
DATA
127127
__xyz__ = 'X, Y and Z'
128-
c_alias = test.pydoc_mod.C[int]
128+
c_alias = test.test_pydoc.pydoc_mod.C[int]
129129
list_alias1 = typing.List[int]
130130
list_alias2 = list[int]
131131
type_union1 = typing.Union[int, str]
@@ -148,7 +148,7 @@ class C(builtins.object)
148148
for s in expected_data_docstrings)
149149

150150
html2text_of_expected = """
151-
test.pydoc_mod (version 1.2.3.4)
151+
test.test_pydoc.pydoc_mod (version 1.2.3.4)
152152
This is a test module for test_pydoc
153153
154154
Modules
@@ -213,7 +213,7 @@ class C(builtins.object)
213213
214214
Data
215215
__xyz__ = 'X, Y and Z'
216-
c_alias = test.pydoc_mod.C[int]
216+
c_alias = test.test_pydoc.pydoc_mod.C[int]
217217
list_alias1 = typing.List[int]
218218
list_alias2 = list[int]
219219
type_union1 = typing.Union[int, str]
@@ -342,7 +342,7 @@ def get_pydoc_link(module):
342342
"Returns a documentation web link of a module"
343343
abspath = os.path.abspath
344344
dirname = os.path.dirname
345-
basedir = dirname(dirname(abspath(__file__)))
345+
basedir = dirname(dirname(dirname(abspath(__file__))))
346346
doc = pydoc.TextDoc()
347347
loc = doc.getdocloc(module, basedir=basedir)
348348
return loc
@@ -489,7 +489,7 @@ def test_not_here(self):
489489

490490
@requires_docstrings
491491
def test_not_ascii(self):
492-
result = run_pydoc('test.test_pydoc.nonascii', PYTHONIOENCODING='ascii')
492+
result = run_pydoc('test.test_pydoc.test_pydoc.nonascii', PYTHONIOENCODING='ascii')
493493
encoded = nonascii.__doc__.encode('ascii', 'backslashreplace')
494494
self.assertIn(encoded, result)
495495

@@ -669,9 +669,9 @@ def test_help_output_redirect(self):
669669
buf = StringIO()
670670
helper = pydoc.Helper(output=buf)
671671
unused, doc_loc = get_pydoc_text(pydoc_mod)
672-
module = "test.pydoc_mod"
672+
module = "test.test_pydoc.pydoc_mod"
673673
help_header = """
674-
Help on module test.pydoc_mod in test:
674+
Help on module test.test_pydoc.pydoc_mod in test.test_pydoc:
675675
676676
""".lstrip()
677677
help_header = textwrap.dedent(help_header)
@@ -1142,7 +1142,6 @@ class TestDescriptions(unittest.TestCase):
11421142

11431143
def test_module(self):
11441144
# Check that pydocfodder module can be described
1145-
from test import pydocfodder
11461145
doc = pydoc.render_doc(pydocfodder)
11471146
self.assertIn("pydocfodder", doc)
11481147

@@ -1425,10 +1424,10 @@ def smeth(*args, **kwargs):
14251424
self.assertEqual(self._get_summary_line(C.meth),
14261425
"meth" + unbound)
14271426
self.assertEqual(self._get_summary_line(C().meth),
1428-
"meth" + bound + " method of test.test_pydoc.C instance")
1427+
"meth" + bound + " method of test.test_pydoc.test_pydoc.C instance")
14291428
C.cmeth.__func__.__text_signature__ = text_signature
14301429
self.assertEqual(self._get_summary_line(C.cmeth),
1431-
"cmeth" + bound + " class method of test.test_pydoc.C")
1430+
"cmeth" + bound + " class method of test.test_pydoc.test_pydoc.C")
14321431
C.smeth.__text_signature__ = text_signature
14331432
self.assertEqual(self._get_summary_line(C.smeth),
14341433
"smeth" + unbound)
@@ -1465,7 +1464,7 @@ def cm(cls, x):
14651464
'cm(...)\n'
14661465
' A class method\n')
14671466
self.assertEqual(self._get_summary_lines(X.cm), """\
1468-
cm(x) class method of test.test_pydoc.X
1467+
cm(x) class method of test.test_pydoc.test_pydoc.X
14691468
A class method
14701469
""")
14711470
self.assertIn("""
@@ -1647,19 +1646,19 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
16471646
lines = self.getsection(result, f' | Methods {where}:', ' | ' + '-'*70)
16481647
self.assertIn(' | A_method_alias = A_method(self)', lines)
16491648
self.assertIn(' | B_method_alias = B_method(self)', lines)
1650-
self.assertIn(' | A_staticmethod(x, y) from test.pydocfodder.A', lines)
1649+
self.assertIn(' | A_staticmethod(x, y) from test.test_pydoc.pydocfodder.A', lines)
16511650
self.assertIn(' | A_staticmethod_alias = A_staticmethod(x, y)', lines)
1652-
self.assertIn(' | global_func(x, y) from test.pydocfodder', lines)
1651+
self.assertIn(' | global_func(x, y) from test.test_pydoc.pydocfodder', lines)
16531652
self.assertIn(' | global_func_alias = global_func(x, y)', lines)
1654-
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.pydocfodder', lines)
1653+
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
16551654
self.assertIn(' | __repr__(self, /) from builtins.object', lines)
16561655
self.assertIn(' | object_repr = __repr__(self, /)', lines)
16571656

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

@@ -1675,19 +1674,19 @@ def test_html_doc_routines_in_class(self, cls=pydocfodder.B):
16751674
lines = self.getsection(result, f'Methods {where}:', '-'*70)
16761675
self.assertIn('A_method_alias = A_method(self)', lines)
16771676
self.assertIn('B_method_alias = B_method(self)', lines)
1678-
self.assertIn('A_staticmethod(x, y) from test.pydocfodder.A', lines)
1677+
self.assertIn('A_staticmethod(x, y) from test.test_pydoc.pydocfodder.A', lines)
16791678
self.assertIn('A_staticmethod_alias = A_staticmethod(x, y)', lines)
1680-
self.assertIn('global_func(x, y) from test.pydocfodder', lines)
1679+
self.assertIn('global_func(x, y) from test.test_pydoc.pydocfodder', lines)
16811680
self.assertIn('global_func_alias = global_func(x, y)', lines)
1682-
self.assertIn('global_func2_alias = global_func2(x, y) from test.pydocfodder', lines)
1681+
self.assertIn('global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
16831682
self.assertIn('__repr__(self, /) from builtins.object', lines)
16841683
self.assertIn('object_repr = __repr__(self, /)', lines)
16851684

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

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

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,7 @@ TESTSUBDIRS= idlelib/idle_test \
23072307
test/test_module \
23082308
test/test_pathlib \
23092309
test/test_peg_generator \
2310+
test/test_pydoc \
23102311
test/test_sqlite3 \
23112312
test/test_tkinter \
23122313
test/test_tomllib \

0 commit comments

Comments
 (0)