]> granicus.if.org Git - python/commitdiff
Issue 26931: Skip the test_distutils tests using a compiler executable
authorXavier de Gaye <xdegaye@users.sourceforge.net>
Thu, 17 Nov 2016 08:00:19 +0000 (09:00 +0100)
committerXavier de Gaye <xdegaye@users.sourceforge.net>
Thu, 17 Nov 2016 08:00:19 +0000 (09:00 +0100)
that is not found

Lib/distutils/tests/test_build_clib.py
Lib/distutils/tests/test_build_ext.py
Lib/distutils/tests/test_config_cmd.py
Lib/distutils/tests/test_install.py
Lib/distutils/tests/test_sysconfig.py
Lib/test/support/__init__.py

index acc99e78c18f076efbc9610c489fb9282d355df1..85d09906f228d4025b9bc051e9e0be94c81cda38 100644 (file)
@@ -3,7 +3,7 @@ import unittest
 import os
 import sys
 
-from test.support import run_unittest
+from test.support import run_unittest, missing_compiler_executable
 
 from distutils.command.build_clib import build_clib
 from distutils.errors import DistutilsSetupError
@@ -116,19 +116,11 @@ class BuildCLibTestCase(support.TempdirManager,
         cmd.build_temp = build_temp
         cmd.build_clib = build_temp
 
-        # before we run the command, we want to make sure
-        # all commands are present on the system
-        # by creating a compiler and checking its executables
-        from distutils.ccompiler import new_compiler
-        from distutils.sysconfig import customize_compiler
-
-        compiler = new_compiler()
-        customize_compiler(compiler)
-        for ccmd in compiler.executables.values():
-            if ccmd is None:
-                continue
-            if find_executable(ccmd[0]) is None:
-                self.skipTest('The %r command is not found' % ccmd[0])
+        # Before we run the command, we want to make sure
+        # all commands are present on the system.
+        ccmd = missing_compiler_executable()
+        if ccmd is not None:
+            self.skipTest('The %r command is not found' % ccmd)
 
         # this should work
         cmd.run()
index 6be0ca233bff0b014a0b4b499265ef512901a452..be7f5f38aafda74be66ec231d1d8f2ca18899ae8 100644 (file)
@@ -41,6 +41,9 @@ class BuildExtTestCase(TempdirManager,
         return build_ext(*args, **kwargs)
 
     def test_build_ext(self):
+        cmd = support.missing_compiler_executable()
+        if cmd is not None:
+            self.skipTest('The %r command is not found' % cmd)
         global ALREADY_TESTED
         copy_xxmodule_c(self.tmp_dir)
         xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
@@ -295,6 +298,9 @@ class BuildExtTestCase(TempdirManager,
         self.assertEqual(cmd.compiler, 'unix')
 
     def test_get_outputs(self):
+        cmd = support.missing_compiler_executable()
+        if cmd is not None:
+            self.skipTest('The %r command is not found' % cmd)
         tmp_dir = self.mkdtemp()
         c_file = os.path.join(tmp_dir, 'foo.c')
         self.write_file(c_file, 'void PyInit_foo(void) {}\n')
index 0c8dbd8269bed59925301f8d6e72dc2a7e2a5268..6e566e79152a54a09cb8753095df49dba76f0339 100644 (file)
@@ -2,7 +2,7 @@
 import unittest
 import os
 import sys
-from test.support import run_unittest
+from test.support import run_unittest, missing_compiler_executable
 
 from distutils.command.config import dump_file, config
 from distutils.tests import support
@@ -39,6 +39,9 @@ class ConfigTestCase(support.LoggingSilencer,
 
     @unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
     def test_search_cpp(self):
+        cmd = missing_compiler_executable(['preprocessor'])
+        if cmd is not None:
+            self.skipTest('The %r command is not found' % cmd)
         pkg_dir, dist = self.create_dist()
         cmd = config(dist)
 
index 9313330e2b722afc56096c7ca5e963a56aa6037d..287ab1989e40836de196d3cfe560afbe6fb79a29 100644 (file)
@@ -17,6 +17,7 @@ from distutils.errors import DistutilsOptionError
 from distutils.extension import Extension
 
 from distutils.tests import support
+from test import support as test_support
 
 
 def _make_ext_name(modname):
@@ -196,6 +197,9 @@ class InstallTestCase(support.TempdirManager,
         self.assertEqual(found, expected)
 
     def test_record_extensions(self):
+        cmd = test_support.missing_compiler_executable()
+        if cmd is not None:
+            self.skipTest('The %r command is not found' % cmd)
         install_dir = self.mkdtemp()
         project_dir, dist = self.create_dist(ext_modules=[
             Extension('xx', ['xxmodule.c'])])
index fc4d1de185cf593e066a8e9d23174ab73e519f56..fe4a2994e3b0cd3a79c295255a4396d14c06b104 100644 (file)
@@ -39,15 +39,6 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
         self.assertNotEqual(sysconfig.get_python_lib(),
                             sysconfig.get_python_lib(prefix=TESTFN))
 
-    def test_get_python_inc(self):
-        inc_dir = sysconfig.get_python_inc()
-        # This is not much of a test.  We make sure Python.h exists
-        # in the directory returned by get_python_inc() but we don't know
-        # it is the correct file.
-        self.assertTrue(os.path.isdir(inc_dir), inc_dir)
-        python_h = os.path.join(inc_dir, "Python.h")
-        self.assertTrue(os.path.isfile(python_h), python_h)
-
     def test_get_config_vars(self):
         cvars = sysconfig.get_config_vars()
         self.assertIsInstance(cvars, dict)
index 81136100f03c511de59399bb4c119bc4fd456c06..f10672383e44503f4338b63d183370600b74505f 100644 (file)
@@ -105,7 +105,7 @@ __all__ = [
     "check_warnings", "check_no_resource_warning", "EnvironmentVarGuard",
     "run_with_locale", "swap_item",
     "swap_attr", "Matcher", "set_memlimit", "SuppressCrashReport", "sortdict",
-    "run_with_tz", "PGO",
+    "run_with_tz", "PGO", "missing_compiler_executable",
     ]
 
 class Error(Exception):
@@ -2491,3 +2491,28 @@ def check_free_after_iterating(test, iter, cls, args=()):
     # The sequence should be deallocated just after the end of iterating
     gc_collect()
     test.assertTrue(done)
+
+
+def missing_compiler_executable(cmd_names=[]):
+    """Check if the compiler components used to build the interpreter exist.
+
+    Check for the existence of the compiler executables whose names are listed
+    in 'cmd_names' or all the compiler executables when 'cmd_names' is empty
+    and return the first missing executable or None when none is found
+    missing.
+
+    """
+    from distutils import ccompiler, sysconfig, spawn
+    compiler = ccompiler.new_compiler()
+    sysconfig.customize_compiler(compiler)
+    for name in compiler.executables:
+        if cmd_names and name not in cmd_names:
+            continue
+        cmd = getattr(compiler, name)
+        if cmd_names:
+            assert cmd is not None, \
+                    "the '%s' executable is not configured" % name
+        elif cmd is None:
+            continue
+        if spawn.find_executable(cmd[0]) is None:
+            return cmd[0]