Skip to content

Commit

Permalink
Merge pull request #2315 from pypa/feature/417-tests
Browse files Browse the repository at this point in the history
Add tests capturing expected distutils behavior.
  • Loading branch information
jaraco authored Aug 8, 2020
2 parents 5e60dc5 + 47ae38f commit 59e116c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ tests =
paver; python_version>="3.6"
futures; python_version=="2.7"
pip>=19.1 # For proper file:// URLs support.
jaraco.envs

docs =
# Keep these in sync with docs/requirements.txt
Expand Down
1 change: 1 addition & 0 deletions setuptools/tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
63 changes: 63 additions & 0 deletions setuptools/tests/test_distutils_adoption.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 59e116c

Please sign in to comment.