diff --git a/distutils/compilers/C/tests/test_base.py b/distutils/compilers/C/tests/test_base.py index d23b907c..0d6c2a95 100644 --- a/distutils/compilers/C/tests/test_base.py +++ b/distutils/compilers/C/tests/test_base.py @@ -3,10 +3,11 @@ import sys import sysconfig import textwrap -from distutils import ccompiler import pytest +from .. import base + def _make_strs(paths): """ @@ -44,7 +45,7 @@ def test_set_include_dirs(c_file): Extensions should build even if set_include_dirs is invoked. In particular, compiler-specific paths should not be overridden. """ - compiler = ccompiler.new_compiler() + compiler = base.new_compiler() python = sysconfig.get_paths()['include'] compiler.set_include_dirs([python]) compiler.compile(_make_strs([c_file])) @@ -58,7 +59,7 @@ def test_has_function_prototype(): # Issue https://github.com/pypa/setuptools/issues/3648 # Test prototype-generating behavior. - compiler = ccompiler.new_compiler() + compiler = base.new_compiler() # Every C implementation should have these. assert compiler.has_function('abort') @@ -82,7 +83,7 @@ def test_include_dirs_after_multiple_compile_calls(c_file): Calling compile multiple times should not change the include dirs (regression test for setuptools issue #3591). """ - compiler = ccompiler.new_compiler() + compiler = base.new_compiler() python = sysconfig.get_paths()['include'] compiler.set_include_dirs([python]) compiler.compile(_make_strs([c_file])) diff --git a/distutils/compilers/C/tests/test_cygwin.py b/distutils/compilers/C/tests/test_cygwin.py index 677bc0ac..9adf6b8e 100644 --- a/distutils/compilers/C/tests/test_cygwin.py +++ b/distutils/compilers/C/tests/test_cygwin.py @@ -3,17 +3,12 @@ import os import sys from distutils import sysconfig -from distutils.cygwinccompiler import ( - CONFIG_H_NOTOK, - CONFIG_H_OK, - CONFIG_H_UNCERTAIN, - check_config_h, - get_msvcr, -) from distutils.tests import support import pytest +from .. import cygwin + @pytest.fixture(autouse=True) def stuff(request, monkeypatch, distutils_managed_tempdir): @@ -54,24 +49,24 @@ def test_check_config_h(self): '4.0.1 (Apple Computer, Inc. build 5370)]' ) - assert check_config_h()[0] == CONFIG_H_OK + assert cygwin.check_config_h()[0] == cygwin.CONFIG_H_OK # then it tries to see if it can find "__GNUC__" in pyconfig.h sys.version = 'something without the *CC word' # if the file doesn't exist it returns CONFIG_H_UNCERTAIN - assert check_config_h()[0] == CONFIG_H_UNCERTAIN + assert cygwin.check_config_h()[0] == cygwin.CONFIG_H_UNCERTAIN # if it exists but does not contain __GNUC__, it returns CONFIG_H_NOTOK self.write_file(self.python_h, 'xxx') - assert check_config_h()[0] == CONFIG_H_NOTOK + assert cygwin.check_config_h()[0] == cygwin.CONFIG_H_NOTOK # and CONFIG_H_OK if __GNUC__ is found self.write_file(self.python_h, 'xxx __GNUC__ xxx') - assert check_config_h()[0] == CONFIG_H_OK + assert cygwin.check_config_h()[0] == cygwin.CONFIG_H_OK def test_get_msvcr(self): - assert get_msvcr() == [] + assert cygwin.get_msvcr() == [] @pytest.mark.skipif('sys.platform != "cygwin"') def test_dll_libraries_not_none(self): diff --git a/distutils/compilers/C/tests/test_mingw.py b/distutils/compilers/C/tests/test_mingw.py index 3e3ad505..5bf2993f 100644 --- a/distutils/compilers/C/tests/test_mingw.py +++ b/distutils/compilers/C/tests/test_mingw.py @@ -1,26 +1,24 @@ from distutils import sysconfig -from distutils.errors import CCompilerError, DistutilsPlatformError +from distutils.errors import DistutilsPlatformError from distutils.util import is_mingw, split_quoted import pytest +from .. import cygwin, errors -class TestMingw32CCompiler: + +class TestMinGW32Compiler: @pytest.mark.skipif(not is_mingw(), reason='not on mingw') def test_compiler_type(self): - from distutils.cygwinccompiler import Mingw32CCompiler - - compiler = Mingw32CCompiler() + compiler = cygwin.MinGW32Compiler() assert compiler.compiler_type == 'mingw32' @pytest.mark.skipif(not is_mingw(), reason='not on mingw') def test_set_executables(self, monkeypatch): - from distutils.cygwinccompiler import Mingw32CCompiler - monkeypatch.setenv('CC', 'cc') monkeypatch.setenv('CXX', 'c++') - compiler = Mingw32CCompiler() + compiler = cygwin.MinGW32Compiler() assert compiler.compiler == split_quoted('cc -O -Wall') assert compiler.compiler_so == split_quoted('cc -shared -O -Wall') @@ -30,27 +28,21 @@ def test_set_executables(self, monkeypatch): @pytest.mark.skipif(not is_mingw(), reason='not on mingw') def test_runtime_library_dir_option(self): - from distutils.cygwinccompiler import Mingw32CCompiler - - compiler = Mingw32CCompiler() + compiler = cygwin.MinGW32Compiler() with pytest.raises(DistutilsPlatformError): compiler.runtime_library_dir_option('/usr/lib') @pytest.mark.skipif(not is_mingw(), reason='not on mingw') def test_cygwincc_error(self, monkeypatch): - import distutils.cygwinccompiler - - monkeypatch.setattr(distutils.cygwinccompiler, 'is_cygwincc', lambda _: True) + monkeypatch.setattr(cygwin, 'is_cygwincc', lambda _: True) - with pytest.raises(CCompilerError): - distutils.cygwinccompiler.Mingw32CCompiler() + with pytest.raises(errors.CompileError): + cygwin.MinGW32Compiler() @pytest.mark.skipif('sys.platform == "cygwin"') def test_customize_compiler_with_msvc_python(self): - from distutils.cygwinccompiler import Mingw32CCompiler - # In case we have an MSVC Python build, but still want to use - # Mingw32CCompiler, then customize_compiler() shouldn't fail at least. + # MinGW32Compiler, then customize_compiler() shouldn't fail at least. # https://github.com/pypa/setuptools/issues/4456 - compiler = Mingw32CCompiler() + compiler = cygwin.MinGW32Compiler() sysconfig.customize_compiler(compiler) diff --git a/distutils/compilers/C/tests/test_msvc.py b/distutils/compilers/C/tests/test_msvc.py index 4e0a5596..b92d28ee 100644 --- a/distutils/compilers/C/tests/test_msvc.py +++ b/distutils/compilers/C/tests/test_msvc.py @@ -1,17 +1,15 @@ -"""Tests for distutils._msvccompiler.""" - import os import sys import threading import unittest.mock as mock -from distutils import _msvccompiler -from distutils.compilers.C import msvc from distutils.errors import DistutilsPlatformError from distutils.tests import support import pytest -needs_winreg = pytest.mark.skipif('not hasattr(_msvccompiler, "winreg")') +from .. import msvc + +needs_winreg = pytest.mark.skipif('not hasattr(msvc, "winreg")') class Testmsvccompiler(support.TempdirManager): @@ -38,7 +36,7 @@ def test_get_vc_env_unicode(self): old_distutils_use_sdk = os.environ.pop('DISTUTILS_USE_SDK', None) os.environ[test_var] = test_value try: - env = _msvccompiler._get_vc_env('x86') + env = msvc._get_vc_env('x86') assert test_var.lower() in env assert test_value == env[test_var.lower()] finally: @@ -51,7 +49,7 @@ def test_get_vc_env_unicode(self): def test_get_vc(self, ver): # This function cannot be mocked, so pass if VC is found # and skip otherwise. - lookup = getattr(_msvccompiler, f'_find_vc{ver}') + lookup = getattr(msvc, f'_find_vc{ver}') expected_version = {2015: 14, 2017: 15}[ver] version, path = lookup() if not version: @@ -78,7 +76,7 @@ def test_concurrent_safe(self): """ Concurrent calls to spawn should have consistent results. """ - compiler = _msvccompiler.MSVCCompiler() + compiler = msvc.Compiler() compiler._paths = "expected" inner_cmd = 'import os; assert os.environ["PATH"] == "expected"' command = [sys.executable, '-c', inner_cmd] @@ -99,7 +97,7 @@ def test_concurrent_safe_fallback(self): """ from distutils import ccompiler - compiler = _msvccompiler.MSVCCompiler() + compiler = msvc.Compiler() compiler._paths = "expected" def CCompiler_spawn(self, cmd): diff --git a/distutils/compilers/C/tests/test_unix.py b/distutils/compilers/C/tests/test_unix.py index 82384525..dd070eef 100644 --- a/distutils/compilers/C/tests/test_unix.py +++ b/distutils/compilers/C/tests/test_unix.py @@ -8,11 +8,12 @@ from distutils.errors import DistutilsPlatformError from distutils.tests import support from distutils.tests.compat.py38 import EnvironmentVarGuard -from distutils.unixccompiler import UnixCCompiler from distutils.util import _clear_cached_macosx_ver import pytest +from .. import unix + @pytest.fixture(autouse=True) def save_values(monkeypatch): @@ -23,7 +24,7 @@ def save_values(monkeypatch): @pytest.fixture(autouse=True) def compiler_wrapper(request): - class CompilerWrapper(UnixCCompiler): + class CompilerWrapper(unix.Compiler): def rpath_foo(self): return self.runtime_library_dir_option('/foo') @@ -320,7 +321,7 @@ def test_has_function(self): self.cc.has_function('abort') def test_find_library_file(self, monkeypatch): - compiler = UnixCCompiler() + compiler = unix.Compiler() compiler._library_root = lambda dir: dir monkeypatch.setattr(os.path, 'exists', lambda d: 'existing' in d)