From 9d0add0c7e513a92ee4321aa5be70121c4c1e1e7 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 27 Jan 2013 19:47:45 +0200 Subject: Issue #17041: Fix testing when Python is configured with the --without-doc-strings. --- Lib/test/test_pydoc.py | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'Lib/test/test_pydoc.py') diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index c5a8e983568..c7318ff613e 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -30,6 +30,14 @@ except ImportError: if hasattr(pydoc_mod, "__loader__"): del pydoc_mod.__loader__ +if test.support.HAVE_DOCSTRINGS: + expected_data_docstrings = ( + 'dictionary for instance variables (if defined)', + 'list of weak references to the object (if defined)', + ) * 2 +else: + expected_data_docstrings = ('', '', '', '') + expected_text_pattern = """ NAME test.pydoc_mod - This is a test module for test_pydoc @@ -50,20 +58,16 @@ CLASSES | ---------------------------------------------------------------------- | Data descriptors defined here: |\x20\x20 - | __dict__ - | dictionary for instance variables (if defined) + | __dict__%s |\x20\x20 - | __weakref__ - | list of weak references to the object (if defined) + | __weakref__%s \x20\x20\x20\x20 class B(builtins.object) | Data descriptors defined here: |\x20\x20 - | __dict__ - | dictionary for instance variables (if defined) + | __dict__%s |\x20\x20 - | __weakref__ - | list of weak references to the object (if defined) + | __weakref__%s |\x20\x20 | ---------------------------------------------------------------------- | Data and other attributes defined here: @@ -95,6 +99,9 @@ FILE %s """.strip() +expected_text_data_docstrings = tuple('\n | ' + s if s else '' + for s in expected_data_docstrings) + expected_html_pattern = """ @@ -134,10 +141,10 @@ expected_html_pattern = """
Data descriptors defined here:
__dict__
-
dictionary for instance variables (if defined)
+
%s
__weakref__
-
list of weak references to the object (if defined)
+
%s

@@ -148,10 +155,10 @@ Data descriptors defined here:
     Data descriptors defined here:
__dict__
-
dictionary for instance variables (if defined)
+
%s
__weakref__
-
list of weak references to the object (if defined)
+
%s

Data and other attributes defined here:
@@ -193,6 +200,8 @@ war
Nobody
""".strip() # ' <- emacs turd +expected_html_data_docstrings = tuple(s.replace(' ', ' ') + for s in expected_data_docstrings) # output pattern for missing module missing_pattern = "no Python documentation found for '%s'" @@ -262,7 +271,9 @@ class PydocDocTest(unittest.TestCase): mod_url = nturl2path.pathname2url(mod_file) else: mod_url = mod_file - expected_html = expected_html_pattern % (mod_url, mod_file, doc_loc) + expected_html = expected_html_pattern % ( + (mod_url, mod_file, doc_loc) + + expected_html_data_docstrings) if result != expected_html: print_diffs(expected_html, result) self.fail("outputs are not equal, see diff above") @@ -271,8 +282,10 @@ class PydocDocTest(unittest.TestCase): "Docstrings are omitted with -O2 and above") def test_text_doc(self): result, doc_loc = get_pydoc_text(pydoc_mod) - expected_text = expected_text_pattern % \ - (doc_loc, inspect.getabsfile(pydoc_mod)) + expected_text = expected_text_pattern % ( + (doc_loc,) + + expected_text_data_docstrings + + (inspect.getabsfile(pydoc_mod),)) if result != expected_text: print_diffs(expected_text, result) self.fail("outputs are not equal, see diff above") @@ -346,8 +359,10 @@ class PydocDocTest(unittest.TestCase): captured_output('stderr') as err: helper.help(module) result = buf.getvalue().strip() - expected_text = expected_help_pattern % \ - (doc_loc, inspect.getabsfile(pydoc_mod)) + expected_text = expected_help_pattern % ( + (doc_loc,) + + expected_text_data_docstrings + + (inspect.getabsfile(pydoc_mod),)) self.assertEqual('', output.getvalue()) self.assertEqual('', err.getvalue()) self.assertEqual(expected_text, result) -- cgit v1.2.3