Commits

r.david.murray  committed 5127851

[svn r78351] 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.

  • Participants
  • Parent commits 6267817

Comments (0)

Files changed (3)

File Lib/distutils/tests/test_build_py.py

                       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.")
         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("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)
-        self.assertTrue("README.txt" in files)
 
     def test_empty_package_dir (self):
         # See SF 1668596/1720897.

File Lib/distutils/tests/test_extension.py

 """Tests for distutils.extension."""
+import os
+import sys
 import unittest
-import os
 import warnings
 
 from test.test_support import check_warnings
 
         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'])
 

File Lib/distutils/tests/test_install_lib.py

 """Tests for distutils.command.install_data."""
+import os
 import sys
-import os
 import unittest
 
 from distutils.command.install_lib import install_lib
         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])
-        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()