8000 [3.12] gh-81682: Fix test failures when CPython is built without docs… · python/cpython@fc4d2c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc4d2c3

Browse files
[3.12] gh-81682: Fix test failures when CPython is built without docstrings (GH-113410) (GH-113429)
(cherry picked from commit 4e5b27e)
1 parent fee2bc1 commit fc4d2c3

File tree

12 files changed

+43
-16
lines changed

12 files changed

+43
-16
lines changed

Lib/idlelib/idle_test/test_calltip.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import types
88
import re
99
from idlelib.idle_test.mock_tk import Text
10+
from test.support import MISSING_C_DOCSTRINGS
1011

1112

1213
# Test Class TC is used in multiple get_argspec test methods
@@ -50,6 +51,8 @@ class Get_argspecTest(unittest.TestCase):
5051
# but a red buildbot is better than a user crash (as has happened).
5152
# For a simple mismatch, change the expected output to the actual.
5253

54+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
55+
"Signature information for builtins requires docstrings")
5356
def test_builtins(self):
5457

5558
def tiptest(obj, out):
@@ -143,6 +146,8 @@ def f(): pass
143146
f.__doc__ = 'a'*300
144147
self.assertEqual(get_spec(f), f"()\n{'a'*(calltip._MAX_COLS-3) + '...'}")
145148

149+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
150+
"Signature information for builtins requires docstrings")
146151
def test_multiline_docstring(self):
147152
# Test fewer lines than max.
148153
self.assertEqual(get_spec(range),
@@ -157,6 +162,7 @@ def test_multiline_docstring(self):
157162
bytes(int) -> bytes object of size given by the parameter initialized with null bytes
158163
bytes() -> empty bytes object''')
159164

165+
def test_multiline_docstring_2(self):
160166
# Test more than max lines
161167
def f(): pass
162168
f.__doc__ = 'a\n' * 15

Lib/test/test_capi/test_misc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ def __del__(self):
462462
del L
463463
self.assertEqual(PyList.num, 0)
464464

465+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
466+
"Signature information for builtins requires docstrings")
465467
def test_heap_ctype_doc_and_text_signature(self):
466468
self.assertEqual(_testcapi.HeapDocCType.__doc__, "somedoc")
467469
self.assertEqual(_testcapi.HeapDocCType.__text_signature__, "(arg1, arg2)")

Lib/test/test_coroutines.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,11 +953,12 @@ async def b():
953953

954954
def test_corotype_1(self):
955955
ct = types.CoroutineType
956-
self.assertIn('into coroutine', ct.send.__doc__)
957-
self.assertIn('inside coroutine', ct.close.__doc__)
958-
self.assertIn('in coroutine', ct.throw.__doc__)
959-
self.assertIn('of the coroutine', ct.__dict__['__name__'].__doc__)
960-
self.assertIn('of the coroutine', ct.__dict__['__qualname__'].__doc__)
956+
if not support.MISSING_C_DOCSTRINGS:
957+
self.assertIn('into coroutine', ct.send.__doc__)
958+
self.assertIn('inside coroutine', ct.close.__doc__)
959+
self.assertIn('in coroutine', ct.throw.__doc__)
960+
self.assertIn('of the coroutine', ct.__dict__['__name__'].__doc__)
961+
self.assertIn('of the coroutine', ct.__dict__['__qualname__'].__doc__)
961962
self.assertEqual(ct.__name__, 'coroutine')
962963

963964
async def f(): pass

Lib/test/test_curses.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from unittest.mock import MagicMock
99

1010
from test.support import (requires, verbose, SaveSignals, cpython_only,
11-
check_disallow_instantiation)
11+
check_disallow_instantiation, MISSING_C_DOCSTRINGS)
1212
from test.support.import_helper import import_module
1313

1414
# Optionally test curses module. This currently requires that the
@@ -1142,6 +1142,8 @@ def test_encoding(self):
11421142
with self.assertRaises(TypeError):
11431143
del stdscr.encoding
11441144

1145+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
1146+
"Signature information for builtins requires docstrings")
11451147
def test_issue21088(self):
11461148
stdscr = self.stdscr
11471149
#

Lib/test/test_functools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,8 @@ def mycmp(x, y):
939939
self.assertRaises(TypeError, hash, k)
940940
self.assertNotIsInstance(k, collections.abc.Hashable)
941941

942+
@unittest.skipIf(support.MISSING_C_DOCSTRINGS,
943+
"Signature information for builtins requires docstrings")
942944
def test_cmp_to_signature(self):
943945
self.assertEqual(str(Signature.from_callable(self.cmp_to_key)),
944946
'(mycmp)')

Lib/test/test_importlib/extension/test_loader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import warnings
1111
import importlib.util
1212
import importlib
13+
from test.support import MISSING_C_DOCSTRINGS
1314
from test.support.script_helper import assert_python_failure
1415

1516

@@ -375,7 +376,8 @@ def test_nonascii(self):
375376
with self.subTest(name):
376377
module = self.load_module_by_name(name)
377378
self.assertEqual(module.__name__, name)
378-
self.assertEqual(module.__doc__, "Module named in %s" % lang)
379+
if not MISSING_C_DOCSTRINGS:
380+
self.assertEqual(module.__doc__, "Module named in %s" % lang)
379381

380382

381383
(Frozen_MultiPhaseExtensionModuleTests,

Lib/test/test_inspect/test_inspect.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3722,6 +3722,8 @@ def foo(a, *, b:1): pass
37223722
foo_sig = MySignature.from_callable(foo)
37233723
self.assertIsInstance(foo_sig, MySignature)
37243724

3725+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
3726+
"Signature information for builtins requires docstrings")
37253727
def test_signature_from_callable_class(self):
37263728
# A regression test for a class inheriting its signature from `object`.
37273729
class MySignature(inspect.Signature): pass
@@ -3812,7 +3814,8 @@ def test_signature_eval_str(self):
38123814
par('c', PORK, annotation="'MyClass'"),
38133815
)))
38143816

3815-
self.assertEqual(signature_func(isa.UnannotatedClass), sig())
3817+
if not MISSING_C_DOCSTRINGS:
3818+
self.assertEqual(signature_func(isa.UnannotatedClass), sig())
38163819
self.assertEqual(signature_func(isa.unannotated_function),
38173820
sig(
38183821
parameters=(

Lib/test/test_module/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_uninitialized(self):
3030
self.fail("__name__ = %s" % repr(s))
3131
except AttributeError:
3232
pass
33-
self.assertEqual(foo.__doc__, ModuleType.__doc__)
33+
self.assertEqual(foo.__doc__, ModuleType.__doc__ or '')
3434

3535
def test_uninitialized_missing_getattr(self):
3636
# Issue 8297

Lib/test/test_pydoc.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from test.support import threading_helper
3030
from test.support import (reap_children, captured_output, captured_stdout,
3131
captured_stderr, is_emscripten, is_wasi,
32-
requires_docstrings)
32+
requires_docstrings, MISSING_C_DOCSTRINGS)
3333
from test.support.os_helper import (TESTFN, rmtree, unlink)
3434
from test import pydoc_mod
3535

@@ -1062,13 +1062,15 @@ def test_generic_alias(self):
10621062
doc = pydoc.render_doc(typing.List[int], renderer=pydoc.plaintext)
10631063
self.assertIn('_GenericAlias in module typing', doc)
10641064
self.assertIn('List = class list(object)', doc)
1065-
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
1065+
if not MISSING_C_DOCSTRINGS:
1066+
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
10661067

10671068
self.assertEqual(pydoc.describe(list[int]), 'GenericAlias')
10681069
doc = pydoc.render_doc(list[int], renderer=pydoc.plaintext)
10691070
self.assertIn('GenericAlias in module builtins', doc)
10701071
self.assertIn('\nclass list(object)', doc)
1071-
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
1072+
if not MISSING_C_DOCSTRINGS:
1073+
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
10721074

10731075
def test_union_type(self):
10741076
self.assertEqual(pydoc.describe(typing.Union[int, str]), '_UnionGenericAlias')
@@ -1082,7 +1084,8 @@ def test_union_type(self):
10821084
doc = pydoc.render_doc(int | str, renderer=pydoc.plaintext)
10831085
self.assertIn('UnionType in module types object', doc)
10841086
self.assertIn('\nclass UnionType(builtins.object)', doc)
1085-
self.assertIn(types.UnionType.__doc__.strip().splitlines()[0], doc)
1087+
if not MISSING_C_DOCSTRINGS:
1088+
self.assertIn(types.UnionType.__doc__.strip().splitlines()[0], doc)
10861089

10871090
def test_special_form(self):
10881091
self.assertEqual(pydoc.describe(typing.NoReturn), '_SpecialForm')

Lib/test/test_rlcompleter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import patch
33
import builtins
44
import rlcompleter
5+
from test.support import MISSING_C_DOCSTRINGS
56

67
class CompleteMe:
78
""" Trivial class used in testing rlcompleter.Completer. """
@@ -40,12 +41,12 @@ def test_global_matches(self):
4041

4142
# test with a customized namespace
4243
self.assertEqual(self.completer.global_matches('CompleteM'),
43-
['CompleteMe()'])
44+
['CompleteMe(' if MISSING_C_DOCSTRINGS else 'CompleteMe()'])
4445
self.assertEqual(self.completer.global_matches('eg'),
4546
['egg('])
4647
# XXX: see issue5256
4748
self.assertEqual(self.completer.global_matches('CompleteM'),
48-
['CompleteMe()'])
49+
['CompleteMe(' if MISSING_C_DOCSTRINGS else 'CompleteMe()'])
4950

5051
def test_attr_matches(self):
5152
# test with builtins namespace

Lib/test/test_types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python test set -- part 6, built-in types
22

3-
from test.support import run_with_locale, cpython_only
3+
from test.support import run_with_locale, cpython_only, MISSING_C_DOCSTRINGS
44
import collections.abc
55
from collections import namedtuple
66
import copy
@@ -597,6 +597,8 @@ def test_slot_wrapper_types(self):
597597
self.assertIsInstance(object.__lt__, types.WrapperDescriptorType)
598598
self.assertIsInstance(int.__lt__, types.WrapperDescriptorType)
599599

600+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
601+
"Signature information for builtins requires docstrings")
600602
def test_dunder_get_signature(self):
601603
sig = inspect.signature(object.__init__.__get__)
602604
self.assertEqual(list(sig.parameters), ["instance", "owner"])

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from datetime import date, datetime, time, timedelta, timezone
1818
from functools import cached_property
1919

20+
from test.support import MISSING_C_DOCSTRINGS
2021
from test.test_zoneinfo import _support as test_support
2122
from test.test_zoneinfo._support import OS_ENV_LOCK, TZPATH_TEST_LOCK, ZoneInfoTestBase
2223
from test.support.import_helper import import_module
@@ -404,6 +405,8 @@ def test_time_fixed_offset(self):
404405
class CZoneInfoTest(ZoneInfoTest):
405406
module = c_zoneinfo
406407

408+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
409+
"Signature information for builtins requires docstrings")
407410
def test_signatures(self):
408411
"""Ensure that C module has valid method signatures."""
409412
import inspect

0 commit comments

Comments
 (0)
0