mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
[3.12] gh-81682: Fix test failures when CPython is built without docstrings (GH-113410) (GH-113429)
(cherry picked from commit 4e5b27e6a3
)
This commit is contained in:
parent
fee2bc15f9
commit
fc4d2c3dc6
12 changed files with 43 additions and 16 deletions
|
@ -7,6 +7,7 @@ import textwrap
|
||||||
import types
|
import types
|
||||||
import re
|
import re
|
||||||
from idlelib.idle_test.mock_tk import Text
|
from idlelib.idle_test.mock_tk import Text
|
||||||
|
from test.support import MISSING_C_DOCSTRINGS
|
||||||
|
|
||||||
|
|
||||||
# Test Class TC is used in multiple get_argspec test methods
|
# Test Class TC is used in multiple get_argspec test methods
|
||||||
|
@ -50,6 +51,8 @@ class Get_argspecTest(unittest.TestCase):
|
||||||
# but a red buildbot is better than a user crash (as has happened).
|
# but a red buildbot is better than a user crash (as has happened).
|
||||||
# For a simple mismatch, change the expected output to the actual.
|
# For a simple mismatch, change the expected output to the actual.
|
||||||
|
|
||||||
|
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
||||||
|
"Signature information for builtins requires docstrings")
|
||||||
def test_builtins(self):
|
def test_builtins(self):
|
||||||
|
|
||||||
def tiptest(obj, out):
|
def tiptest(obj, out):
|
||||||
|
@ -143,6 +146,8 @@ you\'ll probably have to override _wrap_chunks().''')
|
||||||
f.__doc__ = 'a'*300
|
f.__doc__ = 'a'*300
|
||||||
self.assertEqual(get_spec(f), f"()\n{'a'*(calltip._MAX_COLS-3) + '...'}")
|
self.assertEqual(get_spec(f), f"()\n{'a'*(calltip._MAX_COLS-3) + '...'}")
|
||||||
|
|
||||||
|
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
||||||
|
"Signature information for builtins requires docstrings")
|
||||||
def test_multiline_docstring(self):
|
def test_multiline_docstring(self):
|
||||||
# Test fewer lines than max.
|
# Test fewer lines than max.
|
||||||
self.assertEqual(get_spec(range),
|
self.assertEqual(get_spec(range),
|
||||||
|
@ -157,6 +162,7 @@ bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
|
||||||
bytes(int) -> bytes object of size given by the parameter initialized with null bytes
|
bytes(int) -> bytes object of size given by the parameter initialized with null bytes
|
||||||
bytes() -> empty bytes object''')
|
bytes() -> empty bytes object''')
|
||||||
|
|
||||||
|
def test_multiline_docstring_2(self):
|
||||||
# Test more than max lines
|
# Test more than max lines
|
||||||
def f(): pass
|
def f(): pass
|
||||||
f.__doc__ = 'a\n' * 15
|
f.__doc__ = 'a\n' * 15
|
||||||
|
|
|
@ -462,6 +462,8 @@ class CAPITest(unittest.TestCase):
|
||||||
del L
|
del L
|
||||||
self.assertEqual(PyList.num, 0)
|
self.assertEqual(PyList.num, 0)
|
||||||
|
|
||||||
|
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
||||||
|
"Signature information for builtins requires docstrings")
|
||||||
def test_heap_ctype_doc_and_text_signature(self):
|
def test_heap_ctype_doc_and_text_signature(self):
|
||||||
self.assertEqual(_testcapi.HeapDocCType.__doc__, "somedoc")
|
self.assertEqual(_testcapi.HeapDocCType.__doc__, "somedoc")
|
||||||
self.assertEqual(_testcapi.HeapDocCType.__text_signature__, "(arg1, arg2)")
|
self.assertEqual(_testcapi.HeapDocCType.__text_signature__, "(arg1, arg2)")
|
||||||
|
|
|
@ -953,6 +953,7 @@ class CoroutineTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_corotype_1(self):
|
def test_corotype_1(self):
|
||||||
ct = types.CoroutineType
|
ct = types.CoroutineType
|
||||||
|
if not support.MISSING_C_DOCSTRINGS:
|
||||||
self.assertIn('into coroutine', ct.send.__doc__)
|
self.assertIn('into coroutine', ct.send.__doc__)
|
||||||
self.assertIn('inside coroutine', ct.close.__doc__)
|
self.assertIn('inside coroutine', ct.close.__doc__)
|
||||||
self.assertIn('in coroutine', ct.throw.__doc__)
|
self.assertIn('in coroutine', ct.throw.__doc__)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import unittest
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from test.support import (requires, verbose, SaveSignals, cpython_only,
|
from test.support import (requires, verbose, SaveSignals, cpython_only,
|
||||||
check_disallow_instantiation)
|
check_disallow_instantiation, MISSING_C_DOCSTRINGS)
|
||||||
from test.support.import_helper import import_module
|
from test.support.import_helper import import_module
|
||||||
|
|
||||||
# Optionally test curses module. This currently requires that the
|
# Optionally test curses module. This currently requires that the
|
||||||
|
@ -1142,6 +1142,8 @@ class TestCurses(unittest.TestCase):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
del stdscr.encoding
|
del stdscr.encoding
|
||||||
|
|
||||||
|
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
||||||
|
"Signature information for builtins requires docstrings")
|
||||||
def test_issue21088(self):
|
def test_issue21088(self):
|
||||||
stdscr = self.stdscr
|
stdscr = self.stdscr
|
||||||
#
|
#
|
||||||
|
|
|
@ -939,6 +939,8 @@ class TestCmpToKey:
|
||||||
self.assertRaises(TypeError, hash, k)
|
self.assertRaises(TypeError, hash, k)
|
||||||
self.assertNotIsInstance(k, collections.abc.Hashable)
|
self.assertNotIsInstance(k, collections.abc.Hashable)
|
||||||
|
|
||||||
|
@unittest.skipIf(support.MISSING_C_DOCSTRINGS,
|
||||||
|
"Signature information for builtins requires docstrings")
|
||||||
def test_cmp_to_signature(self):
|
def test_cmp_to_signature(self):
|
||||||
self.assertEqual(str(Signature.from_callable(self.cmp_to_key)),
|
self.assertEqual(str(Signature.from_callable(self.cmp_to_key)),
|
||||||
'(mycmp)')
|
'(mycmp)')
|
||||||
|
|
|
@ -10,6 +10,7 @@ import unittest
|
||||||
import warnings
|
import warnings
|
||||||
import importlib.util
|
import importlib.util
|
||||||
import importlib
|
import importlib
|
||||||
|
from test.support import MISSING_C_DOCSTRINGS
|
||||||
from test.support.script_helper import assert_python_failure
|
from test.support.script_helper import assert_python_failure
|
||||||
|
|
||||||
|
|
||||||
|
@ -375,6 +376,7 @@ class MultiPhaseExtensionModuleTests(abc.LoaderTests):
|
||||||
with self.subTest(name):
|
with self.subTest(name):
|
||||||
module = self.load_module_by_name(name)
|
module = self.load_module_by_name(name)
|
||||||
self.assertEqual(module.__name__, name)
|
self.assertEqual(module.__name__, name)
|
||||||
|
if not MISSING_C_DOCSTRINGS:
|
||||||
self.assertEqual(module.__doc__, "Module named in %s" % lang)
|
self.assertEqual(module.__doc__, "Module named in %s" % lang)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3722,6 +3722,8 @@ class TestSignatureObject(unittest.TestCase):
|
||||||
foo_sig = MySignature.from_callable(foo)
|
foo_sig = MySignature.from_callable(foo)
|
||||||
self.assertIsInstance(foo_sig, MySignature)
|
self.assertIsInstance(foo_sig, MySignature)
|
||||||
|
|
||||||
|
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
||||||
|
"Signature information for builtins requires docstrings")
|
||||||
def test_signature_from_callable_class(self):
|
def test_signature_from_callable_class(self):
|
||||||
# A regression test for a class inheriting its signature from `object`.
|
# A regression test for a class inheriting its signature from `object`.
|
||||||
class MySignature(inspect.Signature): pass
|
class MySignature(inspect.Signature): pass
|
||||||
|
@ -3812,6 +3814,7 @@ class TestSignatureObject(unittest.TestCase):
|
||||||
par('c', PORK, annotation="'MyClass'"),
|
par('c', PORK, annotation="'MyClass'"),
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
if not MISSING_C_DOCSTRINGS:
|
||||||
self.assertEqual(signature_func(isa.UnannotatedClass), sig())
|
self.assertEqual(signature_func(isa.UnannotatedClass), sig())
|
||||||
self.assertEqual(signature_func(isa.unannotated_function),
|
self.assertEqual(signature_func(isa.unannotated_function),
|
||||||
sig(
|
sig(
|
||||||
|
|
|
@ -30,7 +30,7 @@ class ModuleTests(unittest.TestCase):
|
||||||
self.fail("__name__ = %s" % repr(s))
|
self.fail("__name__ = %s" % repr(s))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
self.assertEqual(foo.__doc__, ModuleType.__doc__)
|
self.assertEqual(foo.__doc__, ModuleType.__doc__ or '')
|
||||||
|
|
||||||
def test_uninitialized_missing_getattr(self):
|
def test_uninitialized_missing_getattr(self):
|
||||||
# Issue 8297
|
# Issue 8297
|
||||||
|
|
|
@ -29,7 +29,7 @@ from test.support.script_helper import (assert_python_ok,
|
||||||
from test.support import threading_helper
|
from test.support import threading_helper
|
||||||
from test.support import (reap_children, captured_output, captured_stdout,
|
from test.support import (reap_children, captured_output, captured_stdout,
|
||||||
captured_stderr, is_emscripten, is_wasi,
|
captured_stderr, is_emscripten, is_wasi,
|
||||||
requires_docstrings)
|
requires_docstrings, MISSING_C_DOCSTRINGS)
|
||||||
from test.support.os_helper import (TESTFN, rmtree, unlink)
|
from test.support.os_helper import (TESTFN, rmtree, unlink)
|
||||||
from test import pydoc_mod
|
from test import pydoc_mod
|
||||||
|
|
||||||
|
@ -1062,12 +1062,14 @@ class TestDescriptions(unittest.TestCase):
|
||||||
doc = pydoc.render_doc(typing.List[int], renderer=pydoc.plaintext)
|
doc = pydoc.render_doc(typing.List[int], renderer=pydoc.plaintext)
|
||||||
self.assertIn('_GenericAlias in module typing', doc)
|
self.assertIn('_GenericAlias in module typing', doc)
|
||||||
self.assertIn('List = class list(object)', doc)
|
self.assertIn('List = class list(object)', doc)
|
||||||
|
if not MISSING_C_DOCSTRINGS:
|
||||||
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
|
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
|
||||||
|
|
||||||
self.assertEqual(pydoc.describe(list[int]), 'GenericAlias')
|
self.assertEqual(pydoc.describe(list[int]), 'GenericAlias')
|
||||||
doc = pydoc.render_doc(list[int], renderer=pydoc.plaintext)
|
doc = pydoc.render_doc(list[int], renderer=pydoc.plaintext)
|
||||||
self.assertIn('GenericAlias in module builtins', doc)
|
self.assertIn('GenericAlias in module builtins', doc)
|
||||||
self.assertIn('\nclass list(object)', doc)
|
self.assertIn('\nclass list(object)', doc)
|
||||||
|
if not MISSING_C_DOCSTRINGS:
|
||||||
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
|
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
|
||||||
|
|
||||||
def test_union_type(self):
|
def test_union_type(self):
|
||||||
|
@ -1082,6 +1084,7 @@ class TestDescriptions(unittest.TestCase):
|
||||||
doc = pydoc.render_doc(int | str, renderer=pydoc.plaintext)
|
doc = pydoc.render_doc(int | str, renderer=pydoc.plaintext)
|
||||||
self.assertIn('UnionType in module types object', doc)
|
self.assertIn('UnionType in module types object', doc)
|
||||||
self.assertIn('\nclass UnionType(builtins.object)', doc)
|
self.assertIn('\nclass UnionType(builtins.object)', doc)
|
||||||
|
if not MISSING_C_DOCSTRINGS:
|
||||||
self.assertIn(types.UnionType.__doc__.strip().splitlines()[0], doc)
|
self.assertIn(types.UnionType.__doc__.strip().splitlines()[0], doc)
|
||||||
|
|
||||||
def test_special_form(self):
|
def test_special_form(self):
|
||||||
|
|
|
@ -2,6 +2,7 @@ import unittest
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
import builtins
|
import builtins
|
||||||
import rlcompleter
|
import rlcompleter
|
||||||
|
from test.support import MISSING_C_DOCSTRINGS
|
||||||
|
|
||||||
class CompleteMe:
|
class CompleteMe:
|
||||||
""" Trivial class used in testing rlcompleter.Completer. """
|
""" Trivial class used in testing rlcompleter.Completer. """
|
||||||
|
@ -40,12 +41,12 @@ class TestRlcompleter(unittest.TestCase):
|
||||||
|
|
||||||
# test with a customized namespace
|
# test with a customized namespace
|
||||||
self.assertEqual(self.completer.global_matches('CompleteM'),
|
self.assertEqual(self.completer.global_matches('CompleteM'),
|
||||||
['CompleteMe()'])
|
['CompleteMe(' if MISSING_C_DOCSTRINGS else 'CompleteMe()'])
|
||||||
self.assertEqual(self.completer.global_matches('eg'),
|
self.assertEqual(self.completer.global_matches('eg'),
|
||||||
['egg('])
|
['egg('])
|
||||||
# XXX: see issue5256
|
# XXX: see issue5256
|
||||||
self.assertEqual(self.completer.global_matches('CompleteM'),
|
self.assertEqual(self.completer.global_matches('CompleteM'),
|
||||||
['CompleteMe()'])
|
['CompleteMe(' if MISSING_C_DOCSTRINGS else 'CompleteMe()'])
|
||||||
|
|
||||||
def test_attr_matches(self):
|
def test_attr_matches(self):
|
||||||
# test with builtins namespace
|
# test with builtins namespace
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Python test set -- part 6, built-in types
|
# Python test set -- part 6, built-in types
|
||||||
|
|
||||||
from test.support import run_with_locale, cpython_only
|
from test.support import run_with_locale, cpython_only, MISSING_C_DOCSTRINGS
|
||||||
import collections.abc
|
import collections.abc
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import copy
|
import copy
|
||||||
|
@ -597,6 +597,8 @@ class TypesTests(unittest.TestCase):
|
||||||
self.assertIsInstance(object.__lt__, types.WrapperDescriptorType)
|
self.assertIsInstance(object.__lt__, types.WrapperDescriptorType)
|
||||||
self.assertIsInstance(int.__lt__, types.WrapperDescriptorType)
|
self.assertIsInstance(int.__lt__, types.WrapperDescriptorType)
|
||||||
|
|
||||||
|
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
||||||
|
"Signature information for builtins requires docstrings")
|
||||||
def test_dunder_get_signature(self):
|
def test_dunder_get_signature(self):
|
||||||
sig = inspect.signature(object.__init__.__get__)
|
sig = inspect.signature(object.__init__.__get__)
|
||||||
self.assertEqual(list(sig.parameters), ["instance", "owner"])
|
self.assertEqual(list(sig.parameters), ["instance", "owner"])
|
||||||
|
|
|
@ -17,6 +17,7 @@ import unittest
|
||||||
from datetime import date, datetime, time, timedelta, timezone
|
from datetime import date, datetime, time, timedelta, timezone
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
|
|
||||||
|
from test.support import MISSING_C_DOCSTRINGS
|
||||||
from test.test_zoneinfo import _support as test_support
|
from test.test_zoneinfo import _support as test_support
|
||||||
from test.test_zoneinfo._support import OS_ENV_LOCK, TZPATH_TEST_LOCK, ZoneInfoTestBase
|
from test.test_zoneinfo._support import OS_ENV_LOCK, TZPATH_TEST_LOCK, ZoneInfoTestBase
|
||||||
from test.support.import_helper import import_module
|
from test.support.import_helper import import_module
|
||||||
|
@ -404,6 +405,8 @@ class ZoneInfoTest(TzPathUserMixin, ZoneInfoTestBase):
|
||||||
class CZoneInfoTest(ZoneInfoTest):
|
class CZoneInfoTest(ZoneInfoTest):
|
||||||
module = c_zoneinfo
|
module = c_zoneinfo
|
||||||
|
|
||||||
|
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
||||||
|
"Signature information for builtins requires docstrings")
|
||||||
def test_signatures(self):
|
def test_signatures(self):
|
||||||
"""Ensure that C module has valid method signatures."""
|
"""Ensure that C module has valid method signatures."""
|
||||||
import inspect
|
import inspect
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue