Skip to content

Commit

Permalink
Direct tests to the new names
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Sep 6, 2024
1 parent ef7c98d commit 1110ebe
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 48 deletions.
9 changes: 5 additions & 4 deletions distutils/compilers/C/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import sys
import sysconfig
import textwrap
from distutils import ccompiler

import pytest

from .. import base


def _make_strs(paths):
"""
Expand Down Expand Up @@ -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]))
Expand All @@ -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')
Expand All @@ -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]))
Expand Down
19 changes: 7 additions & 12 deletions distutils/compilers/C/tests/test_cygwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
32 changes: 12 additions & 20 deletions distutils/compilers/C/tests/test_mingw.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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)
16 changes: 7 additions & 9 deletions distutils/compilers/C/tests/test_msvc.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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]
Expand All @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions distutils/compilers/C/tests/test_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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')

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1110ebe

Please sign in to comment.