diff -r f7eda8165e6f Lib/ctypes/test/test_win32.py --- a/Lib/ctypes/test/test_win32.py Sat Jan 26 12:14:02 2013 +0200 +++ b/Lib/ctypes/test/test_win32.py Sat Jan 26 16:59:32 2013 +0200 @@ -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 @@ def test_COMError(self): from _ctypes import COMError - self.assertEqual(COMError.__doc__, "Raised when a COM method call failed.") + if test.support.HAVE_DOCSTRINGS: + self.assertEqual(COMError.__doc__, + "Raised when a COM method call failed.") ex = COMError(-1, "text", ("details",)) self.assertEqual(ex.hresult, -1) diff -r f7eda8165e6f Lib/distutils/tests/test_build_ext.py --- a/Lib/distutils/tests/test_build_ext.py Sat Jan 26 12:14:02 2013 +0200 +++ b/Lib/distutils/tests/test_build_ext.py Sat Jan 26 16:59:32 2013 +0200 @@ -73,8 +73,9 @@ 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)) diff -r f7eda8165e6f Lib/test/support.py --- a/Lib/test/support.py Sat Jan 26 12:14:02 2013 +0200 +++ b/Lib/test/support.py Sat Jan 26 16:59:32 2013 +0200 @@ -1477,6 +1477,16 @@ _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. diff -r f7eda8165e6f Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py Sat Jan 26 12:14:02 2013 +0200 +++ b/Lib/test/test_bytes.py Sat Jan 26 16:59:32 2013 +0200 @@ -986,6 +986,7 @@ 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__) diff -r f7eda8165e6f Lib/test/test_functools.py --- a/Lib/test/test_functools.py Sat Jan 26 12:14:02 2013 +0200 +++ b/Lib/test/test_functools.py Sat Jan 26 16:59:32 2013 +0200 @@ -287,6 +287,7 @@ 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): diff -r f7eda8165e6f Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py Sat Jan 26 12:14:02 2013 +0200 +++ b/Lib/test/test_pydoc.py Sat Jan 26 16:59:32 2013 +0200 @@ -14,6 +14,7 @@ import textwrap from io import StringIO from collections import namedtuple +import sysconfig from test.script_helper import assert_python_ok from test.support import ( TESTFN, rmtree, @@ -30,6 +31,14 @@ 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 +59,16 @@ | ---------------------------------------------------------------------- | 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 +100,9 @@ %s """.strip() +expected_text_data_docstrings = tuple('\n | ' + s if s else '' + for s in expected_data_docstrings) + expected_html_pattern = """ @@ -134,10 +142,10 @@
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 +156,10 @@
     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 +201,8 @@
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 +272,9 @@ 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 +283,10 @@ "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 +360,10 @@ 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)