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

Skip to content

Commit f011881

Browse files
Issue #17041: Fix testing when Python is configured with the
--without-doc-strings.
2 parents ef0a44c + 26f1166 commit f011881

6 files changed

Lines changed: 53 additions & 28 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,6 @@ def _is_ipv6_enabled():
597597

598598
requires_lzma = unittest.skipUnless(lzma, 'requires lzma')
599599

600-
requires_docstrings = unittest.skipUnless(
601-
sysconfig.get_config_var('WITH_DOC_STRINGS'),
602-
"test requires docstrings")
603-
604600
is_jython = sys.platform.startswith('java')
605601

606602
# Filename used for testing
@@ -1599,6 +1595,16 @@ def case_pred(test):
15991595
_filter_suite(suite, case_pred)
16001596
_run_suite(suite)
16011597

1598+
#=======================================================================
1599+
# Check for the presence of docstrings.
1600+
1601+
HAVE_DOCSTRINGS = (check_impl_detail(cpython=False) or
1602+
sys.platform == 'win32' or
1603+
sysconfig.get_config_var('WITH_DOC_STRINGS'))
1604+
1605+
requires_docstrings = unittest.skipUnless(HAVE_DOCSTRINGS,
1606+
"test requires docstrings")
1607+
16021608

16031609
#=======================================================================
16041610
# doctest driver.

Lib/test/test_functools.py

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

315+
@support.requires_docstrings
315316
@unittest.skipIf(sys.flags.optimize >= 2,
316317
"Docstrings are omitted with -O2 and above")
317318
def test_builtin_update(self):

Lib/test/test_pydoc.py

Lines changed: 32 additions & 21 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'"
@@ -256,7 +265,6 @@ class PydocDocTest(unittest.TestCase):
256265
"Docstrings are omitted with -O2 and above")
257266
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
258267
'trace function introduces __locals__ unexpectedly')
259-
@test.support.requires_docstrings
260268
def test_html_doc(self):
261269
result, doc_loc = get_pydoc_html(pydoc_mod)
262270
mod_file = inspect.getabsfile(pydoc_mod)
@@ -265,7 +273,9 @@ def test_html_doc(self):
265273
mod_url = nturl2path.pathname2url(mod_file)
266274
else:
267275
mod_url = mod_file
268-
expected_html = expected_html_pattern % (mod_url, mod_file, doc_loc)
276+
expected_html = expected_html_pattern % (
277+
(mod_url, mod_file, doc_loc) +
278+
expected_html_data_docstrings)
269279
if result != expected_html:
270280
print_diffs(expected_html, result)
271281
self.fail("outputs are not equal, see diff above")
@@ -274,11 +284,12 @@ def test_html_doc(self):
274284
"Docstrings are omitted with -O2 and above")
275285
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
276286
'trace function introduces __locals__ unexpectedly')
277-
@test.support.requires_docstrings
278287
def test_text_doc(self):
279288
result, doc_loc = get_pydoc_text(pydoc_mod)
280-
expected_text = expected_text_pattern % \
281-
(doc_loc, inspect.getabsfile(pydoc_mod))
289+
expected_text = expected_text_pattern % (
290+
(doc_loc,) +
291+
expected_text_data_docstrings +
292+
(inspect.getabsfile(pydoc_mod),))
282293
if result != expected_text:
283294
print_diffs(expected_text, result)
284295
self.fail("outputs are not equal, see diff above")
@@ -329,7 +340,6 @@ def test_stripid(self):
329340
'Docstrings are omitted with -O2 and above')
330341
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
331342
'trace function introduces __locals__ unexpectedly')
332-
@test.support.requires_docstrings
333343
def test_help_output_redirect(self):
334344
# issue 940286, if output is set in Helper, then all output from
335345
# Helper.help should be redirected
@@ -355,8 +365,10 @@ def test_help_output_redirect(self):
355365
captured_output('stderr') as err:
356366
helper.help(module)
357367
result = buf.getvalue().strip()
358-
expected_text = expected_help_pattern % \
359-
(doc_loc, inspect.getabsfile(pydoc_mod))
368+
expected_text = expected_help_pattern % (
369+
(doc_loc,) +
370+
expected_text_data_docstrings +
371+
(inspect.getabsfile(pydoc_mod),))
360372
self.assertEqual('', output.getvalue())
361373
self.assertEqual('', err.getvalue())
362374
self.assertEqual(expected_text, result)
@@ -499,7 +511,6 @@ def test_content_type_err(self):
499511
self.assertRaises(TypeError, f, 'A', '')
500512
self.assertRaises(TypeError, f, 'B', 'foobar')
501513

502-
@test.support.requires_docstrings
503514
def test_url_requests(self):
504515
# Test for the correct title in the html pages returned.
505516
# This tests the different parts of the URL handler without

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,9 @@ Extension Modules
700700
Tests
701701
-----
702702

703+
- Issue #17041: Fix testing when Python is configured with the
704+
--without-doc-strings.
705+
703706
- Issue #16923: Fix ResourceWarnings in test_ssl.
704707

705708
- Issue #15539: Added regression tests for Tools/scripts/pindent.py.

0 commit comments

Comments
 (0)