|
| 1 | +import pytest |
| 2 | +from testing.helpers import contains_exe, contains_ref |
| 3 | +from testing.path import join as path |
| 4 | + |
| 5 | +from virtualenv.create.via_global_ref.builtin.cpython.cpython3 import CPython3Windows |
| 6 | + |
| 7 | +CPYTHON3_PATH = ( |
| 8 | + "virtualenv.create.via_global_ref.builtin.cpython.common.Path", |
| 9 | + "virtualenv.create.via_global_ref.builtin.cpython.cpython3.Path", |
| 10 | +) |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.parametrize("py_info_name", ["cpython3_win_embed"]) |
| 14 | +def test_2_exe_on_default_py_host(py_info, mock_files): |
| 15 | + mock_files(CPYTHON3_PATH, [py_info.system_executable]) |
| 16 | + sources = tuple(CPython3Windows.sources(interpreter=py_info)) |
| 17 | + # Default Python exe. |
| 18 | + assert contains_exe(sources, py_info.system_executable) |
| 19 | + # Should always exist. |
| 20 | + assert contains_exe(sources, path(py_info.prefix, "pythonw.exe")) |
| 21 | + |
| 22 | + |
| 23 | +@pytest.mark.parametrize("py_info_name", ["cpython3_win_embed"]) |
| 24 | +def test_3_exe_on_not_default_py_host(py_info, mock_files): |
| 25 | + # Not default python host. |
| 26 | + py_info.system_executable = path(py_info.prefix, "python666.exe") |
| 27 | + mock_files(CPYTHON3_PATH, [py_info.system_executable]) |
| 28 | + sources = tuple(CPython3Windows.sources(interpreter=py_info)) |
| 29 | + # Not default Python exe linked to both the default name and origin. |
| 30 | + assert contains_exe(sources, py_info.system_executable, "python.exe") |
| 31 | + assert contains_exe(sources, py_info.system_executable, "python666.exe") |
| 32 | + # Should always exist. |
| 33 | + assert contains_exe(sources, path(py_info.prefix, "pythonw.exe")) |
| 34 | + |
| 35 | + |
| 36 | +@pytest.mark.parametrize("py_info_name", ["cpython3_win_embed"]) |
| 37 | +def test_only_shim(py_info, mock_files): |
| 38 | + shim = path(py_info.system_stdlib, "venv\\scripts\\nt\\python.exe") |
| 39 | + py_files = ( |
| 40 | + path(py_info.prefix, "libcrypto-1_1.dll"), |
| 41 | + path(py_info.prefix, "libffi-7.dll"), |
| 42 | + path(py_info.prefix, "_asyncio.pyd"), |
| 43 | + path(py_info.prefix, "_bz2.pyd"), |
| 44 | + ) |
| 45 | + mock_files(CPYTHON3_PATH, [shim, *py_files]) |
| 46 | + sources = tuple(CPython3Windows.sources(interpreter=py_info)) |
| 47 | + assert CPython3Windows.has_shim(interpreter=py_info) |
| 48 | + assert contains_exe(sources, shim) |
| 49 | + assert not contains_exe(sources, py_info.system_executable) |
| 50 | + for file in py_files: |
| 51 | + assert not contains_ref(sources, file) |
| 52 | + |
| 53 | + |
| 54 | +@pytest.mark.parametrize("py_info_name", ["cpython3_win_embed"]) |
| 55 | +def test_exe_dll_pyd_without_shim(py_info, mock_files): |
| 56 | + py_files = ( |
| 57 | + path(py_info.prefix, "libcrypto-1_1.dll"), |
| 58 | + path(py_info.prefix, "libffi-7.dll"), |
| 59 | + path(py_info.prefix, "_asyncio.pyd"), |
| 60 | + path(py_info.prefix, "_bz2.pyd"), |
| 61 | + ) |
| 62 | + mock_files(CPYTHON3_PATH, py_files) |
| 63 | + sources = tuple(CPython3Windows.sources(interpreter=py_info)) |
| 64 | + assert not CPython3Windows.has_shim(interpreter=py_info) |
| 65 | + assert contains_exe(sources, py_info.system_executable) |
| 66 | + for file in py_files: |
| 67 | + assert contains_ref(sources, file) |
| 68 | + |
| 69 | + |
| 70 | +@pytest.mark.parametrize("py_info_name", ["cpython3_win_embed"]) |
| 71 | +def test_python_zip_if_exists_and_set_in_path(py_info, mock_files): |
| 72 | + python_zip_name = "python{}.zip".format(py_info.version_nodot) |
| 73 | + python_zip = path(py_info.prefix, python_zip_name) |
| 74 | + mock_files(CPYTHON3_PATH, [python_zip]) |
| 75 | + sources = tuple(CPython3Windows.sources(interpreter=py_info)) |
| 76 | + assert python_zip in py_info.path |
| 77 | + assert contains_ref(sources, python_zip) |
| 78 | + |
| 79 | + |
| 80 | +@pytest.mark.parametrize("py_info_name", ["cpython3_win_embed"]) |
| 81 | +def test_no_python_zip_if_exists_and_not_set_in_path(py_info, mock_files): |
| 82 | + python_zip_name = "python{}.zip".format(py_info.version_nodot) |
| 83 | + python_zip = path(py_info.prefix, python_zip_name) |
| 84 | + py_info.path.remove(python_zip) |
| 85 | + mock_files(CPYTHON3_PATH, [python_zip]) |
| 86 | + sources = tuple(CPython3Windows.sources(interpreter=py_info)) |
| 87 | + assert python_zip not in py_info.path |
| 88 | + assert not contains_ref(sources, python_zip) |
| 89 | + |
| 90 | + |
| 91 | +@pytest.mark.parametrize("py_info_name", ["cpython3_win_embed"]) |
| 92 | +def test_no_python_zip_if_not_exists(py_info, mock_files): |
| 93 | + python_zip_name = "python{}.zip".format(py_info.version_nodot) |
| 94 | + python_zip = path(py_info.prefix, python_zip_name) |
| 95 | + # No `python_zip`, just python.exe file. |
| 96 | + mock_files(CPYTHON3_PATH, [py_info.system_executable]) |
| 97 | + sources = tuple(CPython3Windows.sources(interpreter=py_info)) |
| 98 | + assert python_zip in py_info.path |
| 99 | + assert not contains_ref(sources, python_zip) |
0 commit comments