Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d0add0

Browse files
Issue #17041: Fix testing when Python is configured with the
--without-doc-strings.
1 parent 6f02ea0 commit 9d0add0

7 files changed

Lines changed: 54 additions & 20 deletions

File tree

Lib/ctypes/test/test_win32.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from ctypes import *
44
from ctypes.test import is_resource_enabled
55
import unittest, sys
6+
from test import support
67

78
import _ctypes_test
89

@@ -60,7 +61,9 @@ def test_PARAM(self):
6061

6162
def test_COMError(self):
6263
from _ctypes import COMError
63-
self.assertEqual(COMError.__doc__, "Raised when a COM method call failed.")
64+
if support.HAVE_DOCSTRINGS:
65+
self.assertEqual(COMError.__doc__,
66+
"Raised when a COM method call failed.")
6467

6568
ex = COMError(-1, "text", ("details",))
6669
self.assertEqual(ex.hresult, -1)

Lib/distutils/tests/test_build_ext.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ def test_build_ext(self):
7373
self.assertEqual(xx.foo(2, 5), 7)
7474
self.assertEqual(xx.foo(13,15), 28)
7575
self.assertEqual(xx.new().demo(), None)
76-
doc = 'This is a template module just for instruction.'
77-
self.assertEqual(xx.__doc__, doc)
76+
if support.HAVE_DOCSTRINGS:
77+
doc = 'This is a template module just for instruction.'
78+
self.assertEqual(xx.__doc__, doc)
7879
self.assertTrue(isinstance(xx.Null(), xx.Null))
7980
self.assertTrue(isinstance(xx.Str(), xx.Str))
8081

Lib/test/support.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,16 @@ def case_pred(test):
14771477
_filter_suite(suite, case_pred)
14781478
_run_suite(suite)
14791479

1480+
#=======================================================================
1481+
# Check for the presence of docstrings.
1482+
1483+
HAVE_DOCSTRINGS = (check_impl_detail(cpython=False) or
1484+
sys.platform == 'win32' or
1485+
sysconfig.get_config_var('WITH_DOC_STRINGS'))
1486+
1487+
requires_docstrings = unittest.skipUnless(HAVE_DOCSTRINGS,
1488+
"test requires docstrings")
1489+
14801490

14811491
#=======================================================================
14821492
# doctest driver.

Lib/test/test_bytes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ def test_compare_bytes_to_bytearray(self):
986986
self.assertEqual(bytes(b"abc") < b"ab", False)
987987
self.assertEqual(bytes(b"abc") <= b"ab", False)
988988

989+
@test.support.requires_docstrings
989990
def test_doc(self):
990991
self.assertIsNotNone(bytearray.__doc__)
991992
self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)

Lib/test/test_functools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def wrapper():
287287
with self.assertRaises(AttributeError):
288288
functools.update_wrapper(wrapper, f, assign, update)
289289

290+
@support.requires_docstrings
290291
@unittest.skipIf(sys.flags.optimize >= 2,
291292
"Docstrings are omitted with -O2 and above")
292293
def test_builtin_update(self):

Lib/test/test_pydoc.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
if hasattr(pydoc_mod, "__loader__"):
3131
del pydoc_mod.__loader__
3232

33+
if test.support.HAVE_DOCSTRINGS:
34+
expected_data_docstrings = (
35+
'dictionary for instance variables (if defined)',
36+
'list of weak references to the object (if defined)',
37+
) * 2
38+
else:
39+
expected_data_docstrings = ('', '', '', '')
40+
3341
expected_text_pattern = """
3442
NAME
3543
test.pydoc_mod - This is a test module for test_pydoc
@@ -50,20 +58,16 @@ class A(builtins.object)
5058
| ----------------------------------------------------------------------
5159
| Data descriptors defined here:
5260
|\x20\x20
53-
| __dict__
54-
| dictionary for instance variables (if defined)
61+
| __dict__%s
5562
|\x20\x20
56-
| __weakref__
57-
| list of weak references to the object (if defined)
63+
| __weakref__%s
5864
\x20\x20\x20\x20
5965
class B(builtins.object)
6066
| Data descriptors defined here:
6167
|\x20\x20
62-
| __dict__
63-
| dictionary for instance variables (if defined)
68+
| __dict__%s
6469
|\x20\x20
65-
| __weakref__
66-
| list of weak references to the object (if defined)
70+
| __weakref__%s
6771
|\x20\x20
6872
| ----------------------------------------------------------------------
6973
| Data and other attributes defined here:
@@ -95,6 +99,9 @@ class B(builtins.object)
9599
%s
96100
""".strip()
97101

102+
expected_text_data_docstrings = tuple('\n | ' + s if s else ''
103+
for s in expected_data_docstrings)
104+
98105
expected_html_pattern = """
99106
<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="heading">
100107
<tr bgcolor="#7799ee">
@@ -134,10 +141,10 @@ class B(builtins.object)
134141
<hr>
135142
Data descriptors defined here:<br>
136143
<dl><dt><strong>__dict__</strong></dt>
137-
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
144+
<dd><tt>%s</tt></dd>
138145
</dl>
139146
<dl><dt><strong>__weakref__</strong></dt>
140-
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
147+
<dd><tt>%s</tt></dd>
141148
</dl>
142149
</td></tr></table> <p>
143150
<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
@@ -148,10 +155,10 @@ class B(builtins.object)
148155
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
149156
<td width="100%%">Data descriptors defined here:<br>
150157
<dl><dt><strong>__dict__</strong></dt>
151-
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
158+
<dd><tt>%s</tt></dd>
152159
</dl>
153160
<dl><dt><strong>__weakref__</strong></dt>
154-
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
161+
<dd><tt>%s</tt></dd>
155162
</dl>
156163
<hr>
157164
Data and other attributes defined here:<br>
@@ -193,6 +200,8 @@ class B(builtins.object)
193200
<td width="100%%">Nobody</td></tr></table>
194201
""".strip() # ' <- emacs turd
195202

203+
expected_html_data_docstrings = tuple(s.replace(' ', '&nbsp;')
204+
for s in expected_data_docstrings)
196205

197206
# output pattern for missing module
198207
missing_pattern = "no Python documentation found for '%s'"
@@ -262,7 +271,9 @@ def test_html_doc(self):
262271
mod_url = nturl2path.pathname2url(mod_file)
263272
else:
264273
mod_url = mod_file
265-
expected_html = expected_html_pattern % (mod_url, mod_file, doc_loc)
274+
expected_html = expected_html_pattern % (
275+
(mod_url, mod_file, doc_loc) +
276+
expected_html_data_docstrings)
266277
if result != expected_html:
267278
print_diffs(expected_html, result)
268279
self.fail("outputs are not equal, see diff above")
@@ -271,8 +282,10 @@ def test_html_doc(self):
271282
"Docstrings are omitted with -O2 and above")
272283
def test_text_doc(self):
273284
result, doc_loc = get_pydoc_text(pydoc_mod)
274-
expected_text = expected_text_pattern % \
275-
(doc_loc, inspect.getabsfile(pydoc_mod))
285+
expected_text = expected_text_pattern % (
286+
(doc_loc,) +
287+
expected_text_data_docstrings +
288+
(inspect.getabsfile(pydoc_mod),))
276289
if result != expected_text:
277290
print_diffs(expected_text, result)
278291
self.fail("outputs are not equal, see diff above")
@@ -346,8 +359,10 @@ def test_help_output_redirect(self):
346359
captured_output('stderr') as err:
347360
helper.help(module)
348361
result = buf.getvalue().strip()
349-
expected_text = expected_help_pattern % \
350-
(doc_loc, inspect.getabsfile(pydoc_mod))
362+
expected_text = expected_help_pattern % (
363+
(doc_loc,) +
364+
expected_text_data_docstrings +
365+
(inspect.getabsfile(pydoc_mod),))
351366
self.assertEqual('', output.getvalue())
352367
self.assertEqual('', err.getvalue())
353368
self.assertEqual(expected_text, result)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,9 @@ Extension Modules
811811
Tests
812812
-----
813813

814+
- Issue #17041: Fix testing when Python is configured with the
815+
--without-doc-strings.
816+
814817
- Issue #15539: Added regression tests for Tools/scripts/pindent.py.
815818

816819
- Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize

0 commit comments

Comments
 (0)