3030if 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+
3341expected_text_pattern = """
3442NAME
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+
98105expected_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>
135142Data descriptors defined here:<br>
136143<dl><dt><strong>__dict__</strong></dt>
137- <dd><tt>dictionary for instance variables (if defined) </tt></dd>
144+ <dd><tt>%s </tt></dd>
138145</dl>
139146<dl><dt><strong>__weakref__</strong></dt>
140- <dd><tt>list of weak references to the object (if 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> </tt></td><td> </td>
149156<td width="100%%">Data descriptors defined here:<br>
150157<dl><dt><strong>__dict__</strong></dt>
151- <dd><tt>dictionary for instance variables (if defined) </tt></dd>
158+ <dd><tt>%s </tt></dd>
152159</dl>
153160<dl><dt><strong>__weakref__</strong></dt>
154- <dd><tt>list of weak references to the object (if defined) </tt></dd>
161+ <dd><tt>%s </tt></dd>
155162</dl>
156163<hr>
157164Data 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 (' ' , ' ' )
204+ for s in expected_data_docstrings )
196205
197206# output pattern for missing module
198207missing_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
0 commit comments