Index: Lib/collections.py =================================================================== --- Lib/collections.py (revision 76071) +++ 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/distutils/tests/test_build_py.py =================================================================== --- Lib/distutils/tests/test_build_py.py (revision 76071) +++ Lib/distutils/tests/test_build_py.py (working copy) @@ -16,7 +16,7 @@ support.LoggingSilencer, unittest.TestCase): - def test_package_data(self): + def _setup_package_data(self): sources = self.mkdtemp() f = open(os.path.join(sources, "__init__.py"), "w") f.write("# Pretend this is a package.") @@ -52,10 +52,19 @@ self.assertEqual(len(cmd.get_outputs()), 3) pkgdest = os.path.join(destination, "pkg") files = os.listdir(pkgdest) + return files + + def test_package_data(self): + files = self._setup_package_data() self.assertTrue("__init__.py" in files) - self.assertTrue("__init__.pyc" in files) self.assertTrue("README.txt" in files) + @unittest.skipIf(not sys.flags.optimize <= 1, + "pyc files are not written with -O2 and above") + def test_package_data_pyc(self): + files = self._setup_package_data() + self.assertTrue("__init__.pyc" in files) + def test_empty_package_dir (self): # See SF 1668596/1720897. cwd = os.getcwd() Index: Lib/distutils/tests/test_extension.py =================================================================== --- Lib/distutils/tests/test_extension.py (revision 76071) +++ 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 @@ -30,16 +31,22 @@ self.assertEquals(names, wanted) - def test_extension_init(self): - # the first argument, which is the name, must be a string + @unittest.skipIf(not sys.flags.optimize <= 1, + "Assertions are omitted with -O2 and above") + def test_extension_init_assertions(self): + # The first argument, which is the name, must be a string. 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]) + + def test_extension_init(self): + ext = Extension('name', []) + self.assertEquals(ext.name, 'name') + + ext = Extension('name', ['file1', 'file2']) self.assertEquals(ext.sources, ['file1', 'file2']) Index: Lib/distutils/tests/test_install_lib.py =================================================================== --- Lib/distutils/tests/test_install_lib.py (revision 76071) +++ 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 @@ -31,18 +31,27 @@ cmd.finalize_options() self.assertEquals(cmd.optimize, 2) - @unittest.skipUnless(not sys.dont_write_bytecode, - 'byte-compile not supported') - def test_byte_compile(self): + def _setup_byte_compile(self): pkg_dir, dist = self.create_dist() cmd = install_lib(dist) cmd.compile = cmd.optimize = 1 f = os.path.join(pkg_dir, 'foo.py') self.write_file(f, '# python file') - cmd.byte_compile([f]) + cmd.byte_compile([f]) + return pkg_dir + + @unittest.skipUnless(not sys.dont_write_bytecode, + 'byte-compile not supported') + def test_byte_compile_pyo(self): + pkg_dir = self._setup_byte_compile() + self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo'))) + + @unittest.skipIf(not sys.flags.optimize <= 1, + "pyc files are not written with -O2 and above") + def test_byte_compile_pyc(self): + pkg_dir = self._setup_byte_compile() self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc'))) - self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo'))) def test_get_outputs(self): pkg_dir, dist = self.create_dist() Index: Lib/doctest.py =================================================================== --- Lib/doctest.py (revision 76071) +++ Lib/doctest.py (working copy) @@ -2239,7 +2239,20 @@ def shortDescription(self): return "Doctest: " + self._dt_test.name + +class SkipDocTestCase(DocTestCase): + def __init__(self): + DocTestCase.__init__(self, None) + def setUp(self): + self.skipTest("DocTestSuite will not work with -O2 and above") + + def test_skip(self): + pass + + def shortDescription(self): + return "Skipping tests from %s" % module.__name__ + def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None, **options): """ @@ -2282,13 +2295,20 @@ module = _normalize_module(module) tests = test_finder.find(module, globs=globs, extraglobs=extraglobs) - if not tests: + + if not tests and not sys.flags.optimize <=1: + # Skip doctests when running with -O2 + suite = unittest.TestSuite() + suite.addTest(SkipDocTestCase()) + return suite + elif not tests: # Why do we want to do this? Because it reveals a bug that might # otherwise be hidden. raise ValueError(module, "has no tests") tests.sort() suite = unittest.TestSuite() + for test in tests: if len(test.examples) == 0: continue Index: Lib/lib2to3/tests/test_refactor.py =================================================================== --- Lib/lib2to3/tests/test_refactor.py (revision 76071) +++ Lib/lib2to3/tests/test_refactor.py (working copy) @@ -233,6 +233,9 @@ finally: os.linesep = old_sep + + @unittest.skipIf(not sys.flags.optimize <= 1, + "Docstrings are omitted with -O2 and above") def test_refactor_docstring(self): rt = self.rt() Index: Lib/test/test_collections.py =================================================================== --- Lib/test/test_collections.py (revision 76071) +++ 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,6 @@ def test_factory(self): Point = namedtuple('Point', 'x y') self.assertEqual(Point.__name__, 'Point') - self.assertEqual(Point.__doc__, 'Point(x, y)') self.assertEqual(Point.__slots__, ()) self.assertEqual(Point.__module__, __name__) self.assertEqual(Point.__getitem__, tuple.__getitem__) @@ -49,6 +49,12 @@ self.assertRaises(TypeError, Point._make, [11]) # catch too few args self.assertRaises(TypeError, Point._make, [11, 22, 33]) # catch too many args + @unittest.skipIf(not sys.flags.optimize <= 1, + "Docstrings are omitted with -O2 and above") + def test_factory_doc_attr(self): + Point = namedtuple('Point', 'x y') + self.assertEqual(Point.__doc__, 'Point(x, y)') + def test_name_fixer(self): for spec, renamed in [ [('efg', 'g%hi'), ('efg', '_1')], # field with non-alpha char Index: Lib/test/test_contextlib.py =================================================================== --- Lib/test/test_contextlib.py (revision 76071) +++ Lib/test/test_contextlib.py (working copy) @@ -86,7 +86,7 @@ raise ZeroDivisionError(999) self.assertEqual(state, [1, 42, 999]) - def test_contextmanager_attribs(self): + def _create_contextmanager_attribs(self): def attribs(**kw): def decorate(func): for k,v in kw.items(): @@ -97,8 +97,17 @@ @attribs(foo='bar') def baz(spam): """Whee!""" + return baz + + def test_contextmanager_attribs(self): + baz = self._create_contextmanager_attribs() self.assertEqual(baz.__name__,'baz') self.assertEqual(baz.foo, 'bar') + + @unittest.skipIf(not sys.flags.optimize <= 1, + "Docstrings are omitted with -O2 and above") + def test_contextmanager_doc_attrib(self): + baz = self._create_contextmanager_attribs() self.assertEqual(baz.__doc__, "Whee!") class NestedTestCase(unittest.TestCase): Index: Lib/test/test_descr.py =================================================================== --- Lib/test/test_descr.py (revision 76071) +++ Lib/test/test_descr.py (working copy) @@ -2044,6 +2044,18 @@ else: self.fail("expected ZeroDivisionError from bad property") + # this segfaulted in 2.5b2 + try: + import _testcapi + except ImportError: + pass + else: + class X(object): + p = property(_testcapi.test_with_docstring) + + @unittest.skipIf(not sys.flags.optimize <= 1, + "Docstrings are omitted with -O2 and above") + def test_properties_doc_attrib(self): class E(object): def getter(self): "getter method" @@ -2056,15 +2068,6 @@ prop2 = property(fset=setter) self.assertEqual(prop2.__doc__, None) - # this segfaulted in 2.5b2 - try: - import _testcapi - except ImportError: - pass - else: - class X(object): - p = property(_testcapi.test_with_docstring) - def test_properties_plus(self): class C(object): foo = property(doc="hello") Index: Lib/test/test_doctest2.py =================================================================== --- Lib/test/test_doctest2.py (revision 76071) +++ Lib/test/test_doctest2.py (working copy) @@ -12,6 +12,8 @@ """ +import sys +import unittest from test import test_support class C(object): @@ -104,17 +106,17 @@ """ return val -def test_main(): - from test import test_doctest2 - EXPECTED = 19 - f, t = test_support.run_doctest(test_doctest2) - if t != EXPECTED: - raise test_support.TestFailed("expected %d tests to run, not %d" % - (EXPECTED, t)) +class Doctest2(unittest.TestCase): + + @unittest.skipIf(not sys.flags.optimize <= 1, + "Docstrings are omitted with -O2 and above") + def test_main(self): + from test import test_doctest2 + test_support.run_doctest(test_doctest2) # Pollute the namespace with a bunch of imported functions and classes, # to make sure they don't get tested. from doctest import * if __name__ == '__main__': - test_main() + test_support.run_unittest(Doctest2) \ No newline at end of file Index: Lib/test/test_docxmlrpc.py =================================================================== --- Lib/test/test_docxmlrpc.py (revision 76071) +++ 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 @@ -70,6 +71,14 @@ self.client = httplib.HTTPConnection("localhost:%d" % PORT) def tearDown(self): + # If this test was skipped (last in skipped list), we make a request + # because the server blocks expecting one to come in. + skip_list = self._resultForDoCleanups.skipped + if (skip_list and + self._testMethodName == skip_list[-1][0]._testMethodName): + self.client.request("GET", "/") + self.client.getresponse() + self.client.close() self.evt.wait() @@ -111,10 +120,12 @@ """