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'"
@@ -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 )
0 commit comments