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

Skip to content

Commit fe2b4dd

Browse files
[3.11] gh-81682: Fix test failures when CPython is built without docstrings (GH-113410) (GH-113430)
(cherry picked from commit 4e5b27e)
1 parent 80b2bad commit fe2b4dd

File tree

11 files changed

+39
-16
lines changed

11 files changed

+39
-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
@@ -590,6 +590,8 @@ def __del__(self):
590590
del L
591591
self.assertEqual(PyList.num, 0)
592592

593+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
594+
"Signature information for builtins requires docstrings")
593595
def test_heap_ctype_doc_and_text_signature(self):
594596
self.assertEqual(_testcapi.HeapDocCType.__doc__, "somedoc")
595597
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
@@ -946,11 +946,12 @@ async def b():
946946

947947
def test_corotype_1(self):
948948
ct = types.CoroutineType
949-
self.assertIn('into coroutine', ct.send.__doc__)
950-
self.assertIn('inside coroutine', ct.close.__doc__)
951-
self.assertIn('in coroutine', ct.throw.__doc__)
952-
self.assertIn('of the coroutine', ct.__dict__['__name__'].__doc__)
953-
self.assertIn('of the coroutine', ct.__dict__['__qualname__'].__doc__)
949+
if not support.MISSING_C_DOCSTRINGS:
950+
self.assertIn('into coroutine', ct.send.__doc__)
951+
self.assertIn('inside coroutine', ct.close.__doc__)
952+
self.assertIn('in coroutine', ct.throw.__doc__)
953+
self.assertIn('of the coroutine', ct.__dict__['__name__'].__doc__)
954+
self.assertIn('of the coroutine', ct.__dict__['__qualname__'].__doc__)
954955
self.assertEqual(ct.__name__, 'coroutine')
955956

956957
async def f(): pass

Lib/test/test_curses.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import unittest
88

99
from test.support import (requires, verbose, SaveSignals, cpython_only,
10-
check_disallow_instantiation)
10+
check_disallow_instantiation, MISSING_C_DOCSTRINGS)
1111
from test.support.import_helper import import_module
1212

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

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

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

@@ -285,7 +286,8 @@ def test_nonascii(self):
285286
with self.subTest(name):
286287
module = self.load_module_by_name(name)
287288
self.assertEqual(module.__name__, name)
288-
self.assertEqual(module.__doc__, "Module named in %s" % lang)
289+
if not MISSING_C_DOCSTRINGS:
290+
self.assertEqual(module.__doc__, "Module named in %s" % lang)
289291

290292

291293
(Frozen_MultiPhaseExtensionModuleTests,

Lib/test/test_inspect/test_inspect.py

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

3510+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
3511+
"Signature information for builtins requires docstrings")
35103512
def test_signature_from_callable_class(self):
35113513
# A regression test for a class inheriting its signature from `object`.
35123514
class MySignature(inspect.Signature): pass
@@ -3597,7 +3599,8 @@ def test_signature_eval_str(self):
35973599
par('c', PORK, annotation="'MyClass'"),
35983600
)))
35993601

3600-
self.assertEqual(signature_func(isa.UnannotatedClass), sig())
3602+
if not MISSING_C_DOCSTRINGS:
3603+
self.assertEqual(signature_func(isa.UnannotatedClass), sig())
36013604
self.assertEqual(signature_func(isa.unannotated_function),
36023605
sig(
36033606
parameters=(

Lib/test/test_module/__init__.py

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

3434
def test_uninitialized_missing_getattr(self):
3535
# 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: 1 addition & 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

0 commit comments

Comments
 (0)
0