- Issue #17041: Fix testing when Python is configured with the
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 27 Jan 2013 17:45:49 +0000 (19:45 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 27 Jan 2013 17:45:49 +0000 (19:45 +0200)
  --without-doc-strings option.

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

index 2534a748cd95562a8fc56635173d25fa73d77110..77e6fead56f72f0b713d8e37a2477d9c222e4506 100644 (file)
@@ -3,6 +3,7 @@
 from ctypes import *
 from ctypes.test import is_resource_enabled
 import unittest, sys
+from test import test_support as 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 b71cc983beeb1a80f6d390838b8ae90a434070d5..f6a503b538ecca371d7239dc6fddeb89f3764729 100644 (file)
@@ -77,8 +77,9 @@ class BuildExtTestCase(support.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 test_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 a713314f1606e83896fe00f7c7e2b05a67fa0d34..af19ef7fec7528ac11a2a00e6945aae1c6c95cb4 100644 (file)
@@ -232,6 +232,7 @@ class TestUpdateWrapper(unittest.TestCase):
         self.assertEqual(wrapper.attr, 'This is a different test')
         self.assertEqual(wrapper.dict_attr, f.dict_attr)
 
+    @test_support.requires_docstrings
     def test_builtin_update(self):
         # Test for bug #1576241
         def wrapper():
index d95e7069ce1a395b3f988c2bf0b3d9264f1e24ac..382d6dc878fd972be79da21fd3a251a2c8ccc1df 100644 (file)
@@ -16,6 +16,14 @@ from test.test_support import (
 
 from test import pydoc_mod
 
+if test.test_support.HAVE_DOCSTRINGS:
+    expected_data_docstrings = (
+        'dictionary for instance variables (if defined)',
+        'list of weak references to the object (if defined)',
+        )
+else:
+    expected_data_docstrings = ('', '')
+
 expected_text_pattern = \
 """
 NAME
@@ -40,11 +48,9 @@ CLASSES
     class B(__builtin__.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:
@@ -75,6 +81,9 @@ CREDITS
     Nobody
 """.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">
@@ -121,10 +130,10 @@ expected_html_pattern = \
 <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>
@@ -168,6 +177,8 @@ war</tt></dd></dl>
 <td width="100%%">Nobody</td></tr></table>
 """.strip()
 
+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'"
@@ -229,7 +240,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")
@@ -238,8 +251,9 @@ 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 % \
-                        (inspect.getabsfile(pydoc_mod), doc_loc)
+        expected_text = expected_text_pattern % (
+                        (inspect.getabsfile(pydoc_mod), doc_loc) +
+                        expected_text_data_docstrings)
         if result != expected_text:
             print_diffs(expected_text, result)
             self.fail("outputs are not equal, see diff above")
index d11343b6b2a34b82779760f76d24643c5d25b869..0792c45c885c5dc8020c87ccb6fd7e54f05767e1 100644 (file)
@@ -1112,10 +1112,6 @@ def requires_resource(resource):
     else:
         return unittest.skip("resource {0!r} is not enabled".format(resource))
 
-requires_docstrings = unittest.skipUnless(
-    sysconfig.get_config_var('WITH_DOC_STRINGS'),
-    "test requires docstrings")
-
 def cpython_only(test):
     """
     Decorator for tests only applicable on CPython.
@@ -1193,6 +1189,16 @@ def run_unittest(*classes):
             suite.addTest(unittest.makeSuite(cls))
     _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 243781dd48162dd3215e3a69693af2879953bd0f..cd1667022287ba5b4de5537795175ec03b3f00a4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -674,6 +674,9 @@ Extension Modules
 Tests
 -----
 
+- Issue #17041: Fix testing when Python is configured with the
+  --without-doc-strings option.
+
 - Issue #15539: Added regression tests for Tools/scripts/pindent.py.
 
 - Issue #15324: Fix regrtest parsing of --fromfile and --randomize options.