diff options
| author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2021-12-24 22:34:34 +0000 |
|---|---|---|
| committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-01-06 21:43:33 +0000 |
| commit | 60e561c0a3747c2e862791f4cc5a4e530448a9a4 (patch) | |
| tree | 34c7b5ef2535cbbc430053d8db6f205ff4a655fc /setuptools/tests | |
| parent | 2445fdd0d1be06d3d32155505c80831235b2af5e (diff) | |
| download | python-setuptools-git-60e561c0a3747c2e862791f4cc5a4e530448a9a4.tar.gz | |
Extract venv fixtures from test_distutils_adoption
… and change it to install the pre-build setuptools wheel (fixture)
instead of installing from the source tree
Diffstat (limited to 'setuptools/tests')
| -rw-r--r-- | setuptools/tests/environment.py | 17 | ||||
| -rw-r--r-- | setuptools/tests/fixtures.py | 32 | ||||
| -rw-r--r-- | setuptools/tests/test_distutils_adoption.py | 24 |
3 files changed, 47 insertions, 26 deletions
diff --git a/setuptools/tests/environment.py b/setuptools/tests/environment.py index c0274c33..e3ced27c 100644 --- a/setuptools/tests/environment.py +++ b/setuptools/tests/environment.py @@ -1,9 +1,24 @@ import os import sys +import subprocess import unicodedata - from subprocess import Popen as _Popen, PIPE as _PIPE +import jaraco.envs + + +class VirtualEnv(jaraco.envs.VirtualEnv): + name = '.env' + # Some version of PyPy will import distutils on startup, implicitly + # importing setuptools, and thus leading to BackendInvalid errors + # when upgrading Setuptools. Bypass this behavior by avoiding the + # early availability and need to upgrade. + create_opts = ['--no-setuptools'] + + def run(self, cmd, *args, **kwargs): + cmd = [self.exe(cmd[0])] + cmd[1:] + return subprocess.check_output(cmd, *args, cwd=self.root, **kwargs) + def _which_dirs(cmd): result = set() diff --git a/setuptools/tests/fixtures.py b/setuptools/tests/fixtures.py index 9219412f..317254d9 100644 --- a/setuptools/tests/fixtures.py +++ b/setuptools/tests/fixtures.py @@ -4,8 +4,9 @@ import shutil import subprocess import pytest +import path -from . import contexts +from . import contexts, environment @pytest.fixture @@ -104,3 +105,32 @@ def setuptools_wheel(tmp_path_factory, request): "--outdir", str(tmp) , str(request.config.rootdir) ]) return next(tmp.glob("*.whl")) + + +@pytest.fixture +def venv(tmp_path, setuptools_wheel): + """Virtual env with the version of setuptools under test installed""" + env = environment.VirtualEnv() + env.root = path.Path(tmp_path / 'venv') + env.req = str(setuptools_wheel) + return env.create() + + +@pytest.fixture +def venv_without_setuptools(tmp_path): + """Virtual env without any version of setuptools installed""" + env = environment.VirtualEnv() + env.root = path.Path(tmp_path / 'venv_without_setuptools') + env.create_opts = ['--no-setuptools'] + env.ensure_env() + return env + + +@pytest.fixture +def bare_venv(tmp_path): + """Virtual env without any common packages installed""" + env = environment.VirtualEnv() + env.root = path.Path(tmp_path / 'bare_venv') + env.create_opts = ['--no-setuptools', '--no-pip', '--no-wheel', '--no-seed'] + env.ensure_env() + return env diff --git a/setuptools/tests/test_distutils_adoption.py b/setuptools/tests/test_distutils_adoption.py index 1e73f9aa..70075483 100644 --- a/setuptools/tests/test_distutils_adoption.py +++ b/setuptools/tests/test_distutils_adoption.py @@ -1,39 +1,15 @@ import os import sys import functools -import subprocess import platform import textwrap import pytest -import jaraco.envs -import path IS_PYPY = '__pypy__' in sys.builtin_module_names -class VirtualEnv(jaraco.envs.VirtualEnv): - name = '.env' - # Some version of PyPy will import distutils on startup, implicitly - # importing setuptools, and thus leading to BackendInvalid errors - # when upgrading Setuptools. Bypass this behavior by avoiding the - # early availability and need to upgrade. - create_opts = ['--no-setuptools'] - - 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(tmp_path, tmp_src): - env = VirtualEnv() - env.root = path.Path(tmp_path / 'venv') - env.req = str(tmp_src) - return env.create() - - def popen_text(call): """ Augment the Popen call with the parameters to ensure unicode text. |
