Aluode/PerceptionLabPortable
0
1import os2import subprocess3import sys4from urllib.error import URLError5from urllib.request import urlopen6 7import pytest8 9 10@pytest.fixture(autouse=True)11def pytest_virtualenv_works(venv):12 """13 pytest_virtualenv may not work. if it doesn't, skip these14 tests. See #1284.15 """16 venv_prefix = venv.run(["python", "-c", "import sys; print(sys.prefix)"]).strip()17 if venv_prefix == sys.prefix:18 pytest.skip("virtualenv is broken (see pypa/setuptools#1284)")19 20 21def test_clean_env_install(venv_without_setuptools, setuptools_wheel):22 """23 Check setuptools can be installed in a clean environment.24 """25 cmd = ["python", "-m", "pip", "install", str(setuptools_wheel)]26 venv_without_setuptools.run(cmd)27 28 29def access_pypi():30 # Detect if tests are being run without connectivity31 if not os.environ.get('NETWORK_REQUIRED', False): # pragma: nocover32 try:33 urlopen('https://pypi.org', timeout=1)34 except URLError:35 # No network, disable most of these tests36 return False37 38 return True39 40 41@pytest.mark.skipif(42 'platform.python_implementation() == "PyPy"',43 reason="https://github.com/pypa/setuptools/pull/2865#issuecomment-965834995",44)45@pytest.mark.skipif(not access_pypi(), reason="no network")46# ^-- Even when it is not necessary to install a different version of `pip`47# the build process will still try to download `wheel`, see #3147 and #2986.48@pytest.mark.parametrize(49 'pip_version',50 [51 None,52 pytest.param(53 'pip<20.1',54 marks=pytest.mark.xfail(55 'sys.version_info >= (3, 12)',56 reason="pip 23.1.2 required for Python 3.12 and later",57 ),58 ),59 pytest.param(60 'pip<21',61 marks=pytest.mark.xfail(62 'sys.version_info >= (3, 12)',63 reason="pip 23.1.2 required for Python 3.12 and later",64 ),65 ),66 pytest.param(67 'pip<22',68 marks=pytest.mark.xfail(69 'sys.version_info >= (3, 12)',70 reason="pip 23.1.2 required for Python 3.12 and later",71 ),72 ),73 pytest.param(74 'pip<23',75 marks=pytest.mark.xfail(76 'sys.version_info >= (3, 12)',77 reason="pip 23.1.2 required for Python 3.12 and later",78 ),79 ),80 pytest.param(81 'https://github.com/pypa/pip/archive/main.zip',82 marks=pytest.mark.xfail(reason='#2975'),83 ),84 ],85)86def test_pip_upgrade_from_source(87 pip_version, venv_without_setuptools, setuptools_wheel, setuptools_sdist88):89 """90 Check pip can upgrade setuptools from source.91 """92 # Install pip/wheel, in a venv without setuptools (as it93 # should not be needed for bootstrapping from source)94 venv = venv_without_setuptools95 venv.run(["pip", "install", "-U", "wheel"])96 if pip_version is not None:97 venv.run(["python", "-m", "pip", "install", "-U", pip_version, "--retries=1"])98 with pytest.raises(subprocess.CalledProcessError):99 # Meta-test to make sure setuptools is not installed100 venv.run(["python", "-c", "import setuptools"])101 102 # Then install from wheel.103 venv.run(["pip", "install", str(setuptools_wheel)])104 # And finally try to upgrade from source.105 venv.run(["pip", "install", "--no-cache-dir", "--upgrade", str(setuptools_sdist)])106 107 108def test_no_missing_dependencies(bare_venv, request):109 """110 Quick and dirty test to ensure all external dependencies are vendored.111 """112 setuptools_dir = request.config.rootdir113 bare_venv.run(['python', 'setup.py', '--help'], cwd=setuptools_dir)114 