Merged revisions 78351 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78351 | r.david.murray | 2010-02-22 19:24:49 -0500 (Mon, 22 Feb 2010) | 5 lines

  Issue 6292: for the moment at least, the test suite passes if run
  with -OO.  Tests requiring docstrings are skipped.  Patch by
  Brian Curtin, thanks to Matias Torchinsky for helping review and
  improve the patch.
........
diff --git a/Lib/distutils/tests/test_build_py.py b/Lib/distutils/tests/test_build_py.py
index 3e45f6e..61e213a 100644
--- a/Lib/distutils/tests/test_build_py.py
+++ b/Lib/distutils/tests/test_build_py.py
@@ -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(sys.flags.optimize >= 2,
+                     "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()
diff --git a/Lib/distutils/tests/test_extension.py b/Lib/distutils/tests/test_extension.py
index 9d3cfe6..857284d 100755
--- a/Lib/distutils/tests/test_extension.py
+++ b/Lib/distutils/tests/test_extension.py
@@ -1,6 +1,7 @@
 """Tests for distutils.extension."""
-import unittest
 import os
+import sys
+import unittest
 import warnings
 
 from test.support import check_warnings
@@ -32,16 +33,22 @@
 
         self.assertEquals(names, wanted)
 
-    def test_extension_init(self):
-        # the first argument, which is the name, must be a string
+    @unittest.skipIf(sys.flags.optimize >= 2,
+                     "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'])
 
diff --git a/Lib/distutils/tests/test_install_lib.py b/Lib/distutils/tests/test_install_lib.py
index 99a6d90..13d27ab 100644
--- a/Lib/distutils/tests/test_install_lib.py
+++ b/Lib/distutils/tests/test_install_lib.py
@@ -1,6 +1,6 @@
 """Tests for distutils.command.install_data."""
-import sys
 import os
+import sys
 import unittest
 
 from distutils.command.install_lib import install_lib
@@ -31,9 +31,7 @@
         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
@@ -41,8 +39,15 @@
         f = os.path.join(pkg_dir, 'foo.py')
         self.write_file(f, '# python file')
         cmd.byte_compile([f])
-        self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
-        self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
+        return pkg_dir
+
+    @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile not enabled')
+    def test_byte_compile(self):
+        pkg_dir = self._setup_byte_compile()
+        if sys.flags.optimize < 1:
+            self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
+        else:
+            self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
 
     def test_get_outputs(self):
         pkg_dir, dist = self.create_dist()