Index: Lib/json/tests/__init__.py =================================================================== --- Lib/json/tests/__init__.py (revision 73446) +++ Lib/json/tests/__init__.py (working copy) @@ -21,8 +21,10 @@ import json.encoder import json.decoder suite = unittest.TestSuite() - for mod in (json, json.encoder, json.decoder): - suite.addTest(doctest.DocTestSuite(mod)) + # These tests depend on docstrings, which are omitted when -OO is given. + if sys.flags.optimize <= 1: + for mod in (json, json.encoder, json.decoder): + suite.addTest(doctest.DocTestSuite(mod)) return suite def main(): Index: Lib/distutils/tests/test_install_lib.py =================================================================== --- Lib/distutils/tests/test_install_lib.py (revision 73446) +++ Lib/distutils/tests/test_install_lib.py (working copy) @@ -1,6 +1,6 @@ """Tests for distutils.command.install_data.""" +import os import sys -import os import unittest from distutils.command.install_lib import install_lib @@ -39,8 +39,10 @@ f = os.path.join(pkg_dir, 'foo.py') self.write_file(f, '# python file') cmd.byte_compile([f]) - self.assert_(os.path.exists(os.path.join(pkg_dir, 'foo.pyc'))) self.assert_(os.path.exists(os.path.join(pkg_dir, 'foo.pyo'))) + # This assertion will never be true when -OO is given, so skip it. + if sys.flags.optimize <= 1: + self.assert_(os.path.exists(os.path.join(pkg_dir, 'foo.pyc'))) def test_get_outputs(self): pkg_dir, dist = self.create_dist() Index: Lib/distutils/tests/test_versionpredicate.py =================================================================== --- Lib/distutils/tests/test_versionpredicate.py (revision 73446) +++ Lib/distutils/tests/test_versionpredicate.py (working copy) @@ -4,6 +4,12 @@ import distutils.versionpredicate import doctest +import sys +import unittest def test_suite(): - return doctest.DocTestSuite(distutils.versionpredicate) + # Docstrings are omitted at this optimization level, so skip all doctests. + if sys.flags.optimize >= 2: + return unittest.TestSuite() + else: + return doctest.DocTestSuite(distutils.versionpredicate) Index: Lib/distutils/tests/test_build_py.py =================================================================== --- Lib/distutils/tests/test_build_py.py (revision 73446) +++ Lib/distutils/tests/test_build_py.py (working copy) @@ -53,8 +53,9 @@ pkgdest = os.path.join(destination, "pkg") files = os.listdir(pkgdest) self.assert_("__init__.py" in files) - self.assert_("__init__.pyc" in files) self.assert_("README.txt" in files) + if sys.flags.optimize <= 1: + self.assert_("__init__.pyc" in files) def test_empty_package_dir (self): # See SF 1668596/1720897. Index: Lib/distutils/tests/test_extension.py =================================================================== --- Lib/distutils/tests/test_extension.py (revision 73446) +++ Lib/distutils/tests/test_extension.py (working copy) @@ -1,6 +1,7 @@ """Tests for distutils.extension.""" +import os +import sys import unittest -import os import warnings from test.test_support import check_warnings @@ -31,15 +32,18 @@ self.assertEquals(names, wanted) def test_extension_init(self): - # the first argument, which is the name, must be a string - self.assertRaises(AssertionError, Extension, 1, []) + # The first argument, which is the name, must be a string. Assertions + # are omitted with -OO, so skip this test. + if sys.flags.optimize <= 1: + self.assertRaises(AssertionError, Extension, 1, []) ext = Extension('name', []) self.assertEquals(ext.name, 'name') # the second argument, which is the list of files, must # be a list of strings - self.assertRaises(AssertionError, Extension, 'name', 'file') - self.assertRaises(AssertionError, Extension, 'name', ['file', 1]) + if sys.flags.optimize <= 1: + self.assertRaises(AssertionError, Extension, 'name', 'file') + self.assertRaises(AssertionError, Extension, 'name', ['file', 1]) ext = Extension('name', ['file1', 'file2']) self.assertEquals(ext.sources, ['file1', 'file2']) Index: Lib/collections.py =================================================================== --- Lib/collections.py (revision 73446) +++ Lib/collections.py (working copy) @@ -171,8 +171,6 @@ """Returns a new subclass of tuple with named fields. >>> Point = namedtuple('Point', 'x y') - >>> Point.__doc__ # docstring for the new class - 'Point(x, y)' >>> p = Point(11, y=22) # instantiate with positional args or keywords >>> p[0] + p[1] # indexable like a plain tuple 33 Index: Lib/lib2to3/tests/test_refactor.py =================================================================== --- Lib/lib2to3/tests/test_refactor.py (revision 73446) +++ Lib/lib2to3/tests/test_refactor.py (working copy) @@ -159,24 +159,26 @@ finally: os.linesep = old_sep - def test_refactor_docstring(self): - rt = self.rt() + # Docstrings are omitted when Python is passed -OO, so skip this test. + if sys.flags.optimize <= 1: + def test_refactor_docstring(self): + rt = self.rt() - def example(): - """ - >>> example() - 42 - """ - out = rt.refactor_docstring(example.__doc__, "") - self.assertEqual(out, example.__doc__) + def example(): + """ + >>> example() + 42 + """ + out = rt.refactor_docstring(example.__doc__, "") + self.assertEqual(out, example.__doc__) - def parrot(): - """ - >>> def parrot(): - ... return 43 - """ - out = rt.refactor_docstring(parrot.__doc__, "") - self.assertNotEqual(out, parrot.__doc__) + def parrot(): + """ + >>> def parrot(): + ... return 43 + """ + out = rt.refactor_docstring(parrot.__doc__, "") + self.assertNotEqual(out, parrot.__doc__) def test_explicit(self): from myfixes.fix_explicit import FixExplicit Index: Lib/test/test_xmlrpc.py =================================================================== --- Lib/test/test_xmlrpc.py (revision 73446) +++ Lib/test/test_xmlrpc.py (working copy) @@ -439,17 +439,21 @@ # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) - def test_introspection3(self): - try: - # test native doc - p = xmlrpclib.ServerProxy(URL) - myfunction = p.system.methodHelp('my_function') - self.assertEqual(myfunction, 'This is my function') - except (xmlrpclib.ProtocolError, socket.error), e: - # ignore failures due to non-blocking socket 'unavailable' errors - if not is_unavailable_exception(e): - # protocol error; provide additional information in test output - self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) + # This test depends on docstrings, which are omitted with -OO. + if sys.flags.optimize <= 1: + def test_introspection3(self): + try: + # test native doc + p = xmlrpclib.ServerProxy(URL) + myfunction = p.system.methodHelp('my_function') + self.assertEqual(myfunction, 'This is my function') + except (xmlrpclib.ProtocolError, socket.error), e: + # ignore failures due to non-blocking socket 'unavailable' + # errors + if not is_unavailable_exception(e): + # protocol error; provide additional information in test + # output + self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) def test_introspection4(self): # the SimpleXMLRPCServer doesn't support signatures, but @@ -760,6 +764,9 @@ self.assert_("X-Test: test_send_content\r\n" in req) def test_main(): + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_xmlrpc -- skipping some tests due to -O flag." + sys.stderr.flush() xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase, BinaryTestCase, FaultTestCase, TransportSubclassTestCase] xmlrpc_tests.append(SimpleServerTestCase) Index: Lib/test/test_descr.py =================================================================== --- Lib/test/test_descr.py (revision 73446) +++ Lib/test/test_descr.py (working copy) @@ -2048,17 +2048,20 @@ else: self.fail("expected ZeroDivisionError from bad property") - class E(object): - def getter(self): - "getter method" - return 0 - def setter(self_, value): - "setter method" - pass - prop = property(getter) - self.assertEqual(prop.__doc__, "getter method") - prop2 = property(fset=setter) - self.assertEqual(prop2.__doc__, None) + # Docstrings are omitted with -O2 and above, so these tests don't make + # any sense. + if sys.flags.optimize <= 1: + class E(object): + def getter(self): + "getter method" + return 0 + def setter(self_, value): + "setter method" + pass + prop = property(getter) + self.assertEqual(prop.__doc__, "getter method") + prop2 = property(fset=setter) + self.assertEqual(prop2.__doc__, None) # this segfaulted in 2.5b2 try: @@ -4582,6 +4585,9 @@ def test_main(): + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_descr -- skipping some tests due to -O flag." + sys.stderr.flush() # Run all local test cases, with PTypesLongInitTest first. test_support.run_unittest(PTypesLongInitTest, OperatorsTest, ClassPropertiesAndMethods, DictProxyTests) Index: Lib/test/test_doctest2.py =================================================================== --- Lib/test/test_doctest2.py (revision 73446) +++ Lib/test/test_doctest2.py (working copy) @@ -12,6 +12,7 @@ """ +import sys from test import test_support class C(object): @@ -106,7 +107,13 @@ def test_main(): from test import test_doctest2 - EXPECTED = 19 + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_doctest2 --", + print >>sys.stderr, "skipping some tests due to -O flag." + sys.stderr.flush() + EXPECTED = 3 + else: + EXPECTED = 19 f, t = test_support.run_doctest(test_doctest2) if t != EXPECTED: raise test_support.TestFailed("expected %d tests to run, not %d" % Index: Lib/test/test_inspect.py =================================================================== --- Lib/test/test_inspect.py (revision 73446) +++ Lib/test/test_inspect.py (working copy) @@ -207,12 +207,14 @@ self.assertEqual(functions, [('eggs', mod.eggs), ('spam', mod.spam)]) - def test_getdoc(self): - self.assertEqual(inspect.getdoc(mod), 'A module docstring.') - self.assertEqual(inspect.getdoc(mod.StupidGit), - 'A longer,\n\nindented\n\ndocstring.') - self.assertEqual(inspect.getdoc(git.abuse), - 'Another\n\ndocstring\n\ncontaining\n\ntabs') + # This test depends on docstrings, which are omitted with -OO. + if sys.flags.optimize <= 1: + def test_getdoc(self): + self.assertEqual(inspect.getdoc(mod), 'A module docstring.') + self.assertEqual(inspect.getdoc(mod.StupidGit), + 'A longer,\n\nindented\n\ndocstring.') + self.assertEqual(inspect.getdoc(git.abuse), + 'Another\n\ndocstring\n\ncontaining\n\ntabs') def test_cleandoc(self): self.assertEqual(inspect.cleandoc('An\n indented\n docstring.'), @@ -527,6 +529,10 @@ self.assert_(('datablob', 'data', A) in attrs, 'missing data') def test_main(): + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_inspect --", + print >>sys.stderr, "skipping some tests due to -O flag." + sys.stderr.flush() run_unittest(TestDecorators, TestRetrievingSourceCode, TestOneliners, TestBuggyCases, TestInterpreterStack, TestClassesAndFunctions, TestPredicates) Index: Lib/test/test_pkg.py =================================================================== --- Lib/test/test_pkg.py (revision 73446) +++ Lib/test/test_pkg.py (working copy) @@ -102,7 +102,8 @@ self.mkhier(hier) import t2 - self.assertEqual(t2.__doc__, "doc for t2") + if sys.flags.optimize <= 1: + self.assertEqual(t2.__doc__, "doc for t2") import t2.sub import t2.sub.subsub @@ -276,6 +277,9 @@ def test_main(): + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_pkg -- skipping some tests due to -O flag." + sys.stderr.flush() test_support.run_unittest(__name__) Index: Lib/test/test_distutils.py =================================================================== --- Lib/test/test_distutils.py (revision 73446) +++ Lib/test/test_distutils.py (working copy) @@ -6,6 +6,7 @@ """ import distutils.tests +import sys import test.test_support @@ -14,4 +15,8 @@ if __name__ == "__main__": + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_distutils --", + print >>sys.stderr, "skipping some tests due to -O flag." + sys.stderr.flush() test_main() Index: Lib/test/test_docxmlrpc.py =================================================================== --- Lib/test/test_docxmlrpc.py (revision 73446) +++ Lib/test/test_docxmlrpc.py (working copy) @@ -1,5 +1,6 @@ from DocXMLRPCServer import DocXMLRPCServer import httplib +import sys from test import test_support import threading import time @@ -109,32 +110,35 @@ """
<lambda>(x, y)
""" in response.read()) - def test_autolinking(self): - """Test that the server correctly automatically wraps references to PEPS - and RFCs with links, and that it linkifies text starting with http or - ftp protocol prefixes. + # These tests depends on docstrings, which are omitted when -OO is passed. + if sys.flags.optimize <= 1: + def test_autolinking(self): + """Test that the server correctly automatically wraps references to + PEPS and RFCs with links, and that it linkifies text starting with + http or ftp protocol prefixes. - The documentation for the "add" method contains the test material. - """ - self.client.request("GET", "/") - response = self.client.getresponse() + The documentation for the "add" method contains the test material. + """ + self.client.request("GET", "/") + response = self.client.getresponse() - self.assert_( # This is ugly ... how can it be made better? -"""
add(x, y)
Add two instances together. This follows PEP008, but has nothing
\nto do with RFC1952. Case should matter: pEp008 and rFC1952.  Things
\nthat start with http and ftp should be auto-linked, too:
\nhttp://google.com.
""" - in response.read()) + data = response.read() + self.assert_( # This is ugly ... how can it be made better? + """
add(x, y)
Add two instances together. This follows PEP008, but has nothing
\nto do with RFC1952. Case should matter: pEp008 and rFC1952.  Things
\nthat start with http and ftp should be auto-linked, too:
\nhttp://google.com.
""" + in data, data) - def test_system_methods(self): - """Test the precense of three consecutive system.* methods. + def test_system_methods(self): + """Test the precense of three consecutive system.* methods. - This also tests their use of parameter type recognition and the systems - related to that process. - """ - self.client.request("GET", "/") - response = self.client.getresponse() + This also tests their use of parameter type recognition and the + systems related to that process. + """ + self.client.request("GET", "/") + response = self.client.getresponse() - self.assert_( -"""
system.listMethods()
system.listMethods() => [\'add\', \'subtract\', \'multiple\']
\n 
\nReturns a list of the methods supported by the server.
\n
system.methodHelp(method_name)
system.methodHelp(\'add\') => "Adds two integers together"
\n 
\nReturns a string containing documentation for the specified method.
\n
system.methodSignature(method_name)
system.methodSignature(\'add\') => [double, int, int]
\n 
\nReturns a list describing the signature of the method. In the
\nabove example, the add method takes two integers as arguments
\nand returns a double result.
\n 
\nThis server does NOT support system.methodSignature.
""" - in response.read()) + self.assert_( + """
system.listMethods()
system.listMethods() => [\'add\', \'subtract\', \'multiple\']
\n 
\nReturns a list of the methods supported by the server.
\n
system.methodHelp(method_name)
system.methodHelp(\'add\') => "Adds two integers together"
\n 
\nReturns a string containing documentation for the specified method.
\n
system.methodSignature(method_name)
system.methodSignature(\'add\') => [double, int, int]
\n 
\nReturns a list describing the signature of the method. In the
\nabove example, the add method takes two integers as arguments
\nand returns a double result.
\n 
\nThis server does NOT support system.methodSignature.
""" + in response.read()) def test_autolink_dotted_methods(self): """Test that selfdot values are made strong automatically in the @@ -146,6 +150,10 @@ response.read()) def test_main(): + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_docxmlrpc --", + print >>sys.stderr, "skipping some tests due to -O flag." + sys.stderr.flush() test_support.run_unittest(DocXMLRPCHTTPGETServer) if __name__ == '__main__': Index: Lib/test/test_functools.py =================================================================== --- Lib/test/test_functools.py (revision 73446) +++ Lib/test/test_functools.py (working copy) @@ -1,4 +1,5 @@ import functools +import sys import unittest from test import test_support from weakref import proxy @@ -190,8 +191,9 @@ functools.update_wrapper(wrapper, f) self.check_wrapper(wrapper, f) self.assertEqual(wrapper.__name__, 'f') - self.assertEqual(wrapper.__doc__, 'This is a test') self.assertEqual(wrapper.attr, 'This is also a test') + if sys.flags.optimize <= 1: + self.assertEqual(wrapper.__doc__, 'This is a test') def test_no_update(self): def f(): @@ -243,8 +245,9 @@ pass self.check_wrapper(wrapper, f) self.assertEqual(wrapper.__name__, 'f') - self.assertEqual(wrapper.__doc__, 'This is a test') self.assertEqual(wrapper.attr, 'This is also a test') + if sys.flags.optimize <= 1: + self.assertEqual(wrapper.__doc__, 'This is a test') def test_no_update(self): def f(): @@ -324,7 +327,6 @@ def test_main(verbose=None): - import sys test_classes = ( TestPartial, TestPartialSubclass, @@ -333,6 +335,10 @@ TestWraps, TestReduce, ) + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_functools --", + print >>sys.stderr, "skipping some tests due to -O flag." + sys.stderr.flush() test_support.run_unittest(*test_classes) # verify reference counting Index: Lib/test/test_json.py =================================================================== --- Lib/test/test_json.py (revision 73446) +++ Lib/test/test_json.py (working copy) @@ -6,6 +6,7 @@ """ import json.tests +import sys import test.test_support @@ -14,4 +15,7 @@ if __name__ == "__main__": + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_json -- skipping some tests due to -O flag." + sys.stderr.flush() test_main() Index: Lib/test/test_pydoc.py =================================================================== --- Lib/test/test_pydoc.py (revision 73446) +++ Lib/test/test_pydoc.py (working copy) @@ -209,26 +209,29 @@ class PyDocDocTest(unittest.TestCase): - def test_html_doc(self): - result, doc_loc = get_pydoc_html(pydoc_mod) - mod_file = inspect.getabsfile(pydoc_mod) - if sys.platform == 'win32': - import nturl2path - mod_url = nturl2path.pathname2url(mod_file) - else: - mod_url = mod_file - expected_html = expected_html_pattern % (mod_url, mod_file, doc_loc) - if result != expected_html: - print_diffs(expected_html, result) - self.fail("outputs are not equal, see diff above") + # These two tests rely on docstrings, which are not present when -OO is + # passed. + if sys.flags.optimize <= 1: + def test_html_doc(self): + result, doc_loc = get_pydoc_html(pydoc_mod) + mod_file = inspect.getabsfile(pydoc_mod) + if sys.platform == 'win32': + import nturl2path + mod_url = nturl2path.pathname2url(mod_file) + else: + mod_url = mod_file + expected_html = expected_html_pattern % (mod_url, mod_file, doc_loc) + if result != expected_html: + print_diffs(expected_html, result) + self.fail("outputs are not equal, see diff 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) - if result != expected_text: - print_diffs(expected_text, result) - self.fail("outputs are not equal, see diff 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) + if result != expected_text: + print_diffs(expected_text, result) + self.fail("outputs are not equal, see diff above") def test_not_here(self): missing_module = "test.i_am_not_here" @@ -273,6 +276,9 @@ def test_main(): + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_pydoc -- skipping some tests due to -O flag." + sys.stderr.flush() test.test_support.run_unittest(PyDocDocTest, TestDescriptions) Index: Lib/test/test_contextlib.py =================================================================== --- Lib/test/test_contextlib.py (revision 73446) +++ Lib/test/test_contextlib.py (working copy) @@ -99,7 +99,10 @@ """Whee!""" self.assertEqual(baz.__name__,'baz') self.assertEqual(baz.foo, 'bar') - self.assertEqual(baz.__doc__, "Whee!") + # Docstrings are omitted with -O2 and above, so this test doesn't make + # any sense. + if sys.flags.optimize <= 1: + self.assertEqual(baz.__doc__, "Whee!") class NestedTestCase(unittest.TestCase): @@ -332,6 +335,10 @@ # This is needed to make the test actually run under regrtest.py! def test_main(): + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_contextlib --", + print >>sys.stderr, "skipping some tests due to -O flag." + sys.stderr.flush() with warnings.catch_warnings(): warnings.simplefilter('ignore') test_support.run_unittest(__name__) Index: Lib/test/test_unittest.py =================================================================== --- Lib/test/test_unittest.py (revision 73446) +++ Lib/test/test_unittest.py (working copy) @@ -2413,27 +2413,29 @@ 'testShortDescriptionWithoutDocstring (' + __name__ + '.Test_TestCase)') - def testShortDescriptionWithOneLineDocstring(self): - """Tests shortDescription() for a method with a docstring.""" - self.assertEqual( - self.shortDescription(), - ('testShortDescriptionWithOneLineDocstring ' - '(' + __name__ + '.Test_TestCase)\n' - 'Tests shortDescription() for a method with a docstring.')) + # Docstrings are omitted with -OO, so skip these tests. + if sys.flags.optimize <= 1: + def testShortDescriptionWithOneLineDocstring(self): + """Tests shortDescription() for a method with a docstring.""" + self.assertEqual( + self.shortDescription(), + ('testShortDescriptionWithOneLineDocstring ' + '(' + __name__ + '.Test_TestCase)\n' + 'Tests shortDescription() for a method with a docstring.')) - def testShortDescriptionWithMultiLineDocstring(self): - """Tests shortDescription() for a method with a longer docstring. + def testShortDescriptionWithMultiLineDocstring(self): + """Tests shortDescription() for a method with a longer docstring. - This method ensures that only the first line of a docstring is - returned used in the short description, no matter how long the - whole thing is. - """ - self.assertEqual( - self.shortDescription(), - ('testShortDescriptionWithMultiLineDocstring ' - '(' + __name__ + '.Test_TestCase)\n' - 'Tests shortDescription() for a method with a longer ' - 'docstring.')) + This method ensures that only the first line of a docstring is + returned used in the short description, no matter how long the + whole thing is. + """ + self.assertEqual( + self.shortDescription(), + ('testShortDescriptionWithMultiLineDocstring ' + '(' + __name__ + '.Test_TestCase)\n' + 'Tests shortDescription() for a method with a longer ' + 'docstring.')) def testAddTypeEqualityFunc(self): class SadSnake(object): @@ -3689,6 +3691,10 @@ ###################################################################### def test_main(): + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_unittest --", + print >>sys.stderr, "skipping some tests due to -O flag." + sys.stderr.flush() test_support.run_unittest(Test_TestCase, Test_TestLoader, Test_TestSuite, Test_TestResult, Test_FunctionTestCase, Test_TestSkipping, Test_Assertions, TestLongMessage, Index: Lib/test/test_property.py =================================================================== --- Lib/test/test_property.py (revision 73446) +++ Lib/test/test_property.py (working copy) @@ -1,6 +1,7 @@ # Test case for property # more tests are in test_descr +import sys import unittest from test.test_support import run_unittest @@ -91,7 +92,8 @@ base.spam = 20 self.assertEqual(base.spam, 20) self.assertEqual(base._spam, 20) - self.assertEqual(base.__class__.spam.__doc__, "BaseClass.getter") + if sys.flags.optimize <= 1: + self.assertEqual(base.__class__.spam.__doc__, "BaseClass.getter") def test_property_decorator_subclass(self): # see #1620 @@ -99,7 +101,8 @@ self.assertRaises(PropertyGet, getattr, sub, "spam") self.assertRaises(PropertySet, setattr, sub, "spam", None) self.assertRaises(PropertyDel, delattr, sub, "spam") - self.assertEqual(sub.__class__.spam.__doc__, "SubClass.getter") + if sys.flags.optimize <= 1: + self.assertEqual(sub.__class__.spam.__doc__, "SubClass.getter") def test_property_decorator_doc(self): base = PropertyDocBase() @@ -110,10 +113,13 @@ def test_property_getter_doc_override(self): newgettersub = PropertySubNewGetter() self.assertEqual(newgettersub.spam, 5) - self.assertEqual(newgettersub.__class__.spam.__doc__, "new docstring") + if sys.flags.optimize <= 1: + self.assertEqual(newgettersub.__class__.spam.__doc__, + "new docstring") newgetter = PropertyNewGetter() self.assertEqual(newgetter.spam, 8) - self.assertEqual(newgetter.__class__.spam.__doc__, "new docstring") + if sys.flags.optimize <= 1: + self.assertEqual(newgetter.__class__.spam.__doc__, "new docstring") # Issue 5890: subclasses of property do not preserve method __doc__ strings @@ -126,16 +132,6 @@ class PropertySubclassTests(unittest.TestCase): - def test_docstring_copy(self): - class Foo(object): - @PropertySub - def spam(self): - """spam wrapped in property subclass""" - return 1 - self.assertEqual( - Foo.spam.__doc__, - "spam wrapped in property subclass") - def test_slots_docstring_copy_exception(self): try: class Foo(object): @@ -148,63 +144,75 @@ else: raise Exception("AttributeError not raised") - def test_property_setter_copies_getter_docstring(self): - class Foo(object): - def __init__(self): self._spam = 1 - @PropertySub - def spam(self): - """spam wrapped in property subclass""" - return self._spam - @spam.setter - def spam(self, value): - """this docstring is ignored""" - self._spam = value - foo = Foo() - self.assertEqual(foo.spam, 1) - foo.spam = 2 - self.assertEqual(foo.spam, 2) - self.assertEqual( - Foo.spam.__doc__, - "spam wrapped in property subclass") - class FooSub(Foo): - @Foo.spam.setter - def spam(self, value): - """another ignored docstring""" - self._spam = 'eggs' - foosub = FooSub() - self.assertEqual(foosub.spam, 1) - foosub.spam = 7 - self.assertEqual(foosub.spam, 'eggs') - self.assertEqual( - FooSub.spam.__doc__, - "spam wrapped in property subclass") + # Docstrings are omitted with -OO, so skip these next three tests. + if sys.flags.optimize <= 1: + def test_docstring_copy(self): + class Foo(object): + @PropertySub + def spam(self): + """spam wrapped in property subclass""" + return 1 + self.assertEqual( + Foo.spam.__doc__, + "spam wrapped in property subclass") - def test_property_new_getter_new_docstring(self): + def test_property_setter_copies_getter_docstring(self): + class Foo(object): + def __init__(self): self._spam = 1 + @PropertySub + def spam(self): + """spam wrapped in property subclass""" + return self._spam + @spam.setter + def spam(self, value): + """this docstring is ignored""" + self._spam = value + foo = Foo() + self.assertEqual(foo.spam, 1) + foo.spam = 2 + self.assertEqual(foo.spam, 2) + self.assertEqual( + Foo.spam.__doc__, + "spam wrapped in property subclass") + class FooSub(Foo): + @Foo.spam.setter + def spam(self, value): + """another ignored docstring""" + self._spam = 'eggs' + foosub = FooSub() + self.assertEqual(foosub.spam, 1) + foosub.spam = 7 + self.assertEqual(foosub.spam, 'eggs') + self.assertEqual( + FooSub.spam.__doc__, + "spam wrapped in property subclass") - class Foo(object): - @PropertySub - def spam(self): - """a docstring""" - return 1 - @spam.getter - def spam(self): - """a new docstring""" - return 2 - self.assertEqual(Foo.spam.__doc__, "a new docstring") - class FooBase(object): - @PropertySub - def spam(self): - """a docstring""" - return 1 - class Foo2(FooBase): - @FooBase.spam.getter - def spam(self): - """a new docstring""" - return 2 - self.assertEqual(Foo.spam.__doc__, "a new docstring") + def test_property_new_getter_new_docstring(self): + class Foo(object): + @PropertySub + def spam(self): + """a docstring""" + return 1 + @spam.getter + def spam(self): + """a new docstring""" + return 2 + self.assertEqual(Foo.spam.__doc__, "a new docstring") + class FooBase(object): + @PropertySub + def spam(self): + """a docstring""" + return 1 + class Foo2(FooBase): + @FooBase.spam.getter + def spam(self): + """a new docstring""" + return 2 + self.assertEqual(Foo.spam.__doc__, "a new docstring") + def test_main(): run_unittest(PropertyTests, PropertySubclassTests) Index: Lib/test/test_threading_local.py =================================================================== --- Lib/test/test_threading_local.py (revision 73446) +++ Lib/test/test_threading_local.py (working copy) @@ -4,6 +4,7 @@ import threading import weakref import gc +import sys class Weak(object): pass @@ -70,7 +71,12 @@ def test_main(): suite = unittest.TestSuite() - suite.addTest(DocTestSuite('_threading_local')) + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_threading_local --", + print >>sys.stderr, "skipping some tests due to -O flag." + sys.stderr.flush() + else: + suite.addTest(DocTestSuite('_threading_local')) suite.addTest(unittest.makeSuite(ThreadingLocalTest)) try: @@ -78,15 +84,16 @@ except ImportError: pass else: - import _threading_local - local_orig = _threading_local.local - def setUp(test): - _threading_local.local = _local - def tearDown(test): - _threading_local.local = local_orig - suite.addTest(DocTestSuite('_threading_local', - setUp=setUp, tearDown=tearDown) - ) + if sys.flags.optimize <= 1: + import _threading_local + local_orig = _threading_local.local + def setUp(test): + _threading_local.local = _local + def tearDown(test): + _threading_local.local = local_orig + suite.addTest(DocTestSuite('_threading_local', + setUp=setUp, tearDown=tearDown) + ) test_support.run_unittest(suite) Index: Lib/test/test_lib2to3.py =================================================================== --- Lib/test/test_lib2to3.py (revision 73446) +++ Lib/test/test_lib2to3.py (working copy) @@ -1,8 +1,9 @@ # Skipping test_parser and test_all_fixers # because of running from lib2to3.tests import test_fixers, test_pytree, test_util, test_refactor +import sys +from test.test_support import run_unittest import unittest -from test.test_support import run_unittest def suite(): tests = unittest.TestSuite() @@ -16,4 +17,8 @@ if __name__ == '__main__': + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_lib2to3 --", + print >>sys.stderr, "skipping some tests due to -O flag." + sys.stderr.flush() test_main() Index: Lib/test/test_collections.py =================================================================== --- Lib/test/test_collections.py (revision 73446) +++ Lib/test/test_collections.py (working copy) @@ -9,6 +9,7 @@ import operator import keyword import re +import sys from collections import Hashable, Iterable, Iterator from collections import Sized, Container, Callable from collections import Set, MutableSet @@ -22,7 +23,10 @@ def test_factory(self): Point = namedtuple('Point', 'x y') self.assertEqual(Point.__name__, 'Point') - self.assertEqual(Point.__doc__, 'Point(x, y)') + # Docstrings are omitted with -O2 and above, so this test doesn't make + # any sense. + if sys.flags.optimize <= 1: + self.assertEqual(Point.__doc__, 'Point(x, y)') self.assertEqual(Point.__slots__, ()) self.assertEqual(Point.__module__, __name__) self.assertEqual(Point.__getitem__, tuple.__getitem__) @@ -850,6 +854,10 @@ import doctest, collections def test_main(verbose=None): + if sys.flags.optimize >= 2: + print >>sys.stderr, "test_collections --", + print >>sys.stderr, "skipping some tests due to -O flag." + sys.stderr.flush() NamedTupleDocs = doctest.DocTestSuite(module=collections) test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs, TestCollectionABCs, TestCounter,