summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-09-24 21:10:43 -0400
committerJason R. Coombs <jaraco@jaraco.com>2022-09-24 21:10:43 -0400
commit7064287cff55aeca6684b61408f46042937399d9 (patch)
tree6a7c9527769085a3ca41fef692c8084e70253d1c
parent7a881198509222de7c374b98fa072bffadc56f8f (diff)
downloadpython-setuptools-git-7064287cff55aeca6684b61408f46042937399d9.tar.gz
In test_sysconfig, prefer fixtures to TESTFN.
-rw-r--r--distutils/tests/test_sysconfig.py71
-rw-r--r--tox.ini1
2 files changed, 38 insertions, 34 deletions
diff --git a/distutils/tests/test_sysconfig.py b/distutils/tests/test_sysconfig.py
index cb63fca7..5c350ac6 100644
--- a/distutils/tests/test_sysconfig.py
+++ b/distutils/tests/test_sysconfig.py
@@ -3,12 +3,12 @@ import contextlib
import os
import subprocess
import sys
-import textwrap
import pathlib
import pytest
import jaraco.envs
import path
+from jaraco.text import trim
import distutils
from distutils import sysconfig
@@ -16,11 +16,8 @@ from distutils.ccompiler import get_default_compiler # noqa: F401
from distutils.unixccompiler import UnixCCompiler
from test.support import swap_item
-from .py38compat import TESTFN
-
@pytest.mark.usefixtures('save_env')
-@pytest.mark.usefixtures('cleanup_testfn')
class TestSysconfig:
def test_get_config_h_filename(self):
config_h = sysconfig.get_config_h_filename()
@@ -32,8 +29,8 @@ class TestSysconfig:
makefile = sysconfig.get_makefile_filename()
assert os.path.isfile(makefile)
- def test_get_python_lib(self):
- assert sysconfig.get_python_lib() != sysconfig.get_python_lib(prefix=TESTFN)
+ def test_get_python_lib(self, tmp_path):
+ assert sysconfig.get_python_lib() != sysconfig.get_python_lib(prefix=tmp_path)
def test_get_config_vars(self):
cvars = sysconfig.get_config_vars()
@@ -166,26 +163,32 @@ class TestSysconfig:
assert comp.shared_lib_extension == 'sc_shutil_suffix'
assert 'ranlib' not in comp.exes
- def test_parse_makefile_base(self):
- self.makefile = TESTFN
- fd = open(self.makefile, 'w')
- try:
- fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'" '\n')
- fd.write('VAR=$OTHER\nOTHER=foo')
- finally:
- fd.close()
- d = sysconfig.parse_makefile(self.makefile)
+ def test_parse_makefile_base(self, tmp_path):
+ makefile = tmp_path / 'Makefile'
+ makefile.write_text(
+ trim(
+ """
+ CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'
+ VAR=$OTHER
+ OTHER=foo
+ """
+ )
+ )
+ d = sysconfig.parse_makefile(makefile)
assert d == {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'", 'OTHER': 'foo'}
- def test_parse_makefile_literal_dollar(self):
- self.makefile = TESTFN
- fd = open(self.makefile, 'w')
- try:
- fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=\$$LIB'" '\n')
- fd.write('VAR=$OTHER\nOTHER=foo')
- finally:
- fd.close()
- d = sysconfig.parse_makefile(self.makefile)
+ def test_parse_makefile_literal_dollar(self, tmp_path):
+ makefile = tmp_path / 'Makefile'
+ makefile.write_text(
+ trim(
+ """
+ CONFIG_ARGS= '--arg1=optarg1' 'ENV=\\$$LIB'
+ VAR=$OTHER
+ OTHER=foo
+ """
+ )
+ )
+ d = sysconfig.parse_makefile(makefile)
assert d == {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'", 'OTHER': 'foo'}
def test_sysconfig_module(self):
@@ -228,24 +231,24 @@ class TestSysconfig:
with pytest.warns(DeprecationWarning):
sysconfig.get_config_var('SO')
- def test_customize_compiler_before_get_config_vars(self):
+ def test_customize_compiler_before_get_config_vars(self, tmp_path):
# Issue #21923: test that a Distribution compiler
# instance can be called without an explicit call to
# get_config_vars().
- with open(TESTFN, 'w') as f:
- f.writelines(
- textwrap.dedent(
- '''\
+ file = tmp_path / 'file'
+ file.write_text(
+ trim(
+ """
from distutils.core import Distribution
config = Distribution().get_command_obj('config')
# try_compile may pass or it may fail if no compiler
# is found but it should not raise an exception.
rc = config.try_compile('int x;')
- '''
- )
+ """
)
+ )
p = subprocess.Popen(
- [str(sys.executable), TESTFN],
+ [str(sys.executable), file],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
@@ -275,11 +278,11 @@ class TestSysconfig:
'\\PCbuild\\'.casefold() not in sys.executable.casefold(),
reason='Need sys.executable to be in a source tree',
)
- def test_win_build_venv_from_source_tree(self):
+ def test_win_build_venv_from_source_tree(self, tmp_path):
"""Ensure distutils.sysconfig detects venvs from source tree builds."""
env = jaraco.envs.VEnv()
env.create_opts = env.clean_opts
- env.root = TESTFN
+ env.root = tmp_path
env.ensure_env()
cmd = [
env.exe(),
diff --git a/tox.ini b/tox.ini
index 5facd6b9..3d031d20 100644
--- a/tox.ini
+++ b/tox.ini
@@ -17,6 +17,7 @@ deps =
jaraco.envs>=2.4
jaraco.path
+ jaraco.text
path
docutils
commands =