]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #17041: Fix testing when Python is configured with the
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 27 Jan 2013 17:47:45 +0000 (19:47 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 27 Jan 2013 17:47:45 +0000 (19:47 +0200)
--without-doc-strings.

Lib/ctypes/test/test_win32.py
Lib/distutils/tests/test_build_ext.py
Lib/test/support.py
Lib/test/test_bytes.py
Lib/test/test_functools.py
Lib/test/test_pydoc.py
Misc/NEWS

index 2534a748cd95562a8fc56635173d25fa73d77110..7e6fe3fba03f61b8a71fd92d89bbcad83b5b5d3a 100644 (file)
@@ -3,6 +3,7 @@
 from ctypes import *
 from ctypes.test import is_resource_enabled
 import unittest, sys
+from test import support
 
 import _ctypes_test
 
@@ -60,7 +61,9 @@ if sys.platform == "win32":
 
         def test_COMError(self):
             from _ctypes import COMError
-            self.assertEqual(COMError.__doc__, "Raised when a COM method call failed.")
+            if support.HAVE_DOCSTRINGS:
+                self.assertEqual(COMError.__doc__,
+                                 "Raised when a COM method call failed.")
 
             ex = COMError(-1, "text", ("details",))
             self.assertEqual(ex.hresult, -1)
index 090eacfb2c3e022d1b3acd0cd0254a58c18da426..065a6a21c992be7259c94101815881ff33e8efcd 100644 (file)
@@ -73,8 +73,9 @@ class BuildExtTestCase(TempdirManager,
         self.assertEqual(xx.foo(2, 5), 7)
         self.assertEqual(xx.foo(13,15), 28)
         self.assertEqual(xx.new().demo(), None)
-        doc = 'This is a template module just for instruction.'
-        self.assertEqual(xx.__doc__, doc)
+        if support.HAVE_DOCSTRINGS:
+            doc = 'This is a template module just for instruction.'
+            self.assertEqual(xx.__doc__, doc)
         self.assertTrue(isinstance(xx.Null(), xx.Null))
         self.assertTrue(isinstance(xx.Str(), xx.Str))
 
index 2130fd639c9f49add256e7f3e722b1e6d70b53d9..66ddf4b0fde498682b1b04ee0d2ef9778d1b8722 100644 (file)
@@ -1477,6 +1477,16 @@ def run_unittest(*classes):
     _filter_suite(suite, case_pred)
     _run_suite(suite)
 
+#=======================================================================
+# Check for the presence of docstrings.
+
+HAVE_DOCSTRINGS = (check_impl_detail(cpython=False) or
+                   sys.platform == 'win32' or
+                   sysconfig.get_config_var('WITH_DOC_STRINGS'))
+
+requires_docstrings = unittest.skipUnless(HAVE_DOCSTRINGS,
+                                          "test requires docstrings")
+
 
 #=======================================================================
 # doctest driver.
index 89e22740fc62ecd58254831fba77ccf158e1ad4a..ba40915f3e3c966966cdf6f54f1c55270ae3745d 100644 (file)
@@ -986,6 +986,7 @@ class AssortedBytesTest(unittest.TestCase):
         self.assertEqual(bytes(b"abc") < b"ab", False)
         self.assertEqual(bytes(b"abc") <= b"ab", False)
 
+    @test.support.requires_docstrings
     def test_doc(self):
         self.assertIsNotNone(bytearray.__doc__)
         self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
index 270cab00756f32f6922d84ad8cbe3a6bf95e5620..10868f3d1543b68d0c2509c2b6528e885bd946c1 100644 (file)
@@ -287,6 +287,7 @@ class TestUpdateWrapper(unittest.TestCase):
         with self.assertRaises(AttributeError):
             functools.update_wrapper(wrapper, f, assign, update)
 
+    @support.requires_docstrings
     @unittest.skipIf(sys.flags.optimize >= 2,
                      "Docstrings are omitted with -O2 and above")
     def test_builtin_update(self):
index c5a8e983568b3b13af1ec4376e3548f8f3cba555..c7318ff613e81f8b3d5aa0eb3153d0ab7e86509a 100644 (file)
@@ -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 = """
 <table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="heading">
 <tr bgcolor="#7799ee">
@@ -134,10 +141,10 @@ expected_html_pattern = """
 <hr>
 Data descriptors defined here:<br>
 <dl><dt><strong>__dict__</strong></dt>
-<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+<dd><tt>%s</tt></dd>
 </dl>
 <dl><dt><strong>__weakref__</strong></dt>
-<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+<dd><tt>%s</tt></dd>
 </dl>
 </td></tr></table> <p>
 <table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
@@ -148,10 +155,10 @@ Data descriptors defined here:<br>
 <tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
 <td width="100%%">Data descriptors defined here:<br>
 <dl><dt><strong>__dict__</strong></dt>
-<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+<dd><tt>%s</tt></dd>
 </dl>
 <dl><dt><strong>__weakref__</strong></dt>
-<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+<dd><tt>%s</tt></dd>
 </dl>
 <hr>
 Data and other attributes defined here:<br>
@@ -193,6 +200,8 @@ war</tt></dd></dl>
 <td width="100%%">Nobody</td></tr></table>
 """.strip() # ' <- emacs turd
 
+expected_html_data_docstrings = tuple(s.replace(' ', '&nbsp;')
+                                      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)
index 3543feb2e569d4c06f32b1be01925a6e9db3da7b..daca4d37e5df0ba4b9e41df0bf637a958537d5bb 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -811,6 +811,9 @@ Extension Modules
 Tests
 -----
 
+- Issue #17041: Fix testing when Python is configured with the
+  --without-doc-strings.
+
 - Issue #15539: Added regression tests for Tools/scripts/pindent.py.
 
 - Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize