diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-08-08 19:22:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-08 19:22:32 -0400 |
commit | 59e116c84d76adc9548d1e9a71e7d8f5c22a8b85 (patch) | |
tree | 6f9567ad8f43ee004a026772ae82ec15b0d016c3 /setuptools | |
parent | 5e60dc50e540a942aeb558aabe7d92ab7eb13d4b (diff) | |
parent | 47ae38fd6f233e6423404bfebfd24d3b98fb897c (diff) | |
download | external_python_setuptools-59e116c84d76adc9548d1e9a71e7d8f5c22a8b85.tar.gz external_python_setuptools-59e116c84d76adc9548d1e9a71e7d8f5c22a8b85.tar.bz2 external_python_setuptools-59e116c84d76adc9548d1e9a71e7d8f5c22a8b85.zip |
Merge pull request #2315 from pypa/feature/417-tests
Add tests capturing expected distutils behavior.
Diffstat (limited to 'setuptools')
-rw-r--r-- | setuptools/tests/requirements.txt | 1 | ||||
-rw-r--r-- | setuptools/tests/test_distutils_adoption.py | 63 |
2 files changed, 64 insertions, 0 deletions
diff --git a/setuptools/tests/requirements.txt b/setuptools/tests/requirements.txt index 19bf5aef..d0d07f70 100644 --- a/setuptools/tests/requirements.txt +++ b/setuptools/tests/requirements.txt @@ -10,3 +10,4 @@ pytest-cov>=2.5.1 paver; python_version>="3.6" futures; python_version=="2.7" pip>=19.1 # For proper file:// URLs support. +jaraco.envs diff --git a/setuptools/tests/test_distutils_adoption.py b/setuptools/tests/test_distutils_adoption.py new file mode 100644 index 00000000..7f28a217 --- /dev/null +++ b/setuptools/tests/test_distutils_adoption.py @@ -0,0 +1,63 @@ +import os +import sys +import functools +import subprocess +import platform + +import pytest +import jaraco.envs +import path + + +class VirtualEnv(jaraco.envs.VirtualEnv): + name = '.env' + + def run(self, cmd, *args, **kwargs): + cmd = [self.exe(cmd[0])] + cmd[1:] + return subprocess.check_output(cmd, *args, cwd=self.root, **kwargs) + + +@pytest.fixture +def venv(tmpdir): + env = VirtualEnv() + env.root = path.Path(tmpdir) + env.req = os.getcwd() + return env.create() + + +def popen_text(call): + """ + Augment the Popen call with the parameters to ensure unicode text. + """ + return functools.partial(call, universal_newlines=True) \ + if sys.version_info < (3, 7) else functools.partial(call, text=True) + + +def find_distutils(venv, imports='distutils', env=None, **kwargs): + py_cmd = 'import {imports}; print(distutils.__file__)'.format(**locals()) + cmd = ['python', '-c', py_cmd] + if platform.system() == 'Windows': + env['SYSTEMROOT'] = os.environ['SYSTEMROOT'] + return popen_text(venv.run)(cmd, env=env, **kwargs) + + +def test_distutils_stdlib(venv): + """ + Ensure stdlib distutils is used when appropriate. + """ + assert venv.name not in find_distutils(venv, env=dict()).split(os.sep) + + +def test_distutils_local_with_setuptools(venv): + """ + Ensure local distutils is used when appropriate. + """ + env = dict(SETUPTOOLS_USE_DISTUTILS='local') + loc = find_distutils(venv, imports='setuptools, distutils', env=env) + assert venv.name in loc.split(os.sep) + + +@pytest.mark.xfail(reason="#2259") +def test_distutils_local(venv): + env = dict(SETUPTOOLS_USE_DISTUTILS='local') + assert venv.name in find_distutils(venv, env=env).split(os.sep) |