Skip to content

Commit c6d5613

Browse files
authored
gh-108638: Fix tests when _stat extension is missing (#108689)
Fix test_inspect and test_pydoc when the _stat extension is missing. Skip tests relying on _stat when _stat is missing.
1 parent d48760b commit c6d5613

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

Lib/test/test_inspect.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ def test_getfullargspec_builtin_func_no_signature(self):
11861186

11871187
cls = _testcapi.DocStringNoSignatureTest
11881188
obj = _testcapi.DocStringNoSignatureTest()
1189-
for builtin, template in [
1189+
tests = [
11901190
(_testcapi.docstring_no_signature_noargs, meth_noargs),
11911191
(_testcapi.docstring_no_signature_o, meth_o),
11921192
(cls.meth_noargs, meth_self_noargs),
@@ -1201,7 +1201,6 @@ def test_getfullargspec_builtin_func_no_signature(self):
12011201
(cls.meth_o_coexist, meth_self_o),
12021202

12031203
(time.time, meth_noargs),
1204-
(stat.S_IMODE, meth_o),
12051204
(str.lower, meth_self_noargs),
12061205
(''.lower, meth_self_noargs),
12071206
(set.add, meth_self_o),
@@ -1212,7 +1211,16 @@ def test_getfullargspec_builtin_func_no_signature(self):
12121211
(datetime.datetime.utcnow, meth_type_noargs),
12131212
(dict.__dict__['__class_getitem__'], meth_type_o),
12141213
(dict.__class_getitem__, meth_type_o),
1215-
]:
1214+
]
1215+
try:
1216+
import _stat
1217+
except ImportError:
1218+
# if the _stat extension is not available, stat.S_IMODE() is
1219+
# implemented in Python, not in C
1220+
pass
1221+
else:
1222+
tests.append((stat.S_IMODE, meth_o))
1223+
for builtin, template in tests:
12161224
with self.subTest(builtin):
12171225
self.assertEqual(inspect.getfullargspec(builtin),
12181226
inspect.getfullargspec(template))
@@ -2934,7 +2942,7 @@ def test_signature_on_builtins_no_signature(self):
29342942

29352943
cls = _testcapi.DocStringNoSignatureTest
29362944
obj = _testcapi.DocStringNoSignatureTest()
2937-
for builtin, template in [
2945+
tests = [
29382946
(_testcapi.docstring_no_signature_noargs, meth_noargs),
29392947
(_testcapi.docstring_no_signature_o, meth_o),
29402948
(cls.meth_noargs, meth_self_noargs),
@@ -2949,7 +2957,6 @@ def test_signature_on_builtins_no_signature(self):
29492957
(cls.meth_o_coexist, meth_self_o),
29502958

29512959
(time.time, meth_noargs),
2952-
(stat.S_IMODE, meth_o),
29532960
(str.lower, meth_self_noargs),
29542961
(''.lower, meth_noargs),
29552962
(set.add, meth_self_o),
@@ -2960,7 +2967,16 @@ def test_signature_on_builtins_no_signature(self):
29602967
(datetime.datetime.utcnow, meth_noargs),
29612968
(dict.__dict__['__class_getitem__'], meth_type_o),
29622969
(dict.__class_getitem__, meth_o),
2963-
]:
2970+
]
2971+
try:
2972+
import _stat
2973+
except ImportError:
2974+
# if the _stat extension is not available, stat.S_IMODE() is
2975+
# implemented in Python, not in C
2976+
pass
2977+
else:
2978+
tests.append((stat.S_IMODE, meth_o))
2979+
for builtin, template in tests:
29642980
with self.subTest(builtin):
29652981
self.assertEqual(inspect.signature(builtin),
29662982
inspect.signature(template))

Lib/test/test_pydoc.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,13 @@ def test_module_level_callable_noargs(self):
11871187
"time()")
11881188

11891189
def test_module_level_callable_o(self):
1190-
self.assertEqual(self._get_summary_line(stat.S_IMODE),
1190+
try:
1191+
import _stat
1192+
except ImportError:
1193+
# stat.S_IMODE() and _stat.S_IMODE() have a different signature
1194+
self.skipTest('_stat extension is missing')
1195+
1196+
self.assertEqual(self._get_summary_line(_stat.S_IMODE),
11911197
"S_IMODE(object, /)")
11921198

11931199
def test_unbound_builtin_method_noargs(self):

0 commit comments

Comments
 (0)