PHP 8.2.30
Preview: test_install_scripts.py Size: 3.35 KB
/opt/cloudlinux/venv/lib64/python3.11/site-packages/setuptools/tests/test_install_scripts.py

"""install_scripts tests"""

import sys

import pytest

from setuptools.command.install_scripts import install_scripts
from setuptools.dist import Distribution

from . import contexts


class TestInstallScripts:
    settings = dict(
        name='foo',
        entry_points={'console_scripts': ['foo=foo:foo']},
        version='0.0',
    )
    unix_exe = '/usr/dummy-test-path/local/bin/python'
    unix_spaces_exe = '/usr/bin/env dummy-test-python'
    win32_exe = 'C:\\Dummy Test Path\\Program Files\\Python 3.6\\python.exe'

    def _run_install_scripts(self, install_dir, executable=None):
        dist = Distribution(self.settings)
        dist.script_name = 'setup.py'
        cmd = install_scripts(dist)
        cmd.install_dir = install_dir
        if executable is not None:
            bs = cmd.get_finalized_command('build_scripts')
            bs.executable = executable
        cmd.ensure_finalized()
        with contexts.quiet():
            cmd.run()

    @pytest.mark.skipif(sys.platform == 'win32', reason='non-Windows only')
    def test_sys_executable_escaping_unix(self, tmpdir, monkeypatch):
        """
        Ensure that shebang is not quoted on Unix when getting the Python exe
        from sys.executable.
        """
        expected = f'#!{self.unix_exe}\n'
        monkeypatch.setattr('sys.executable', self.unix_exe)
        with tmpdir.as_cwd():
            self._run_install_scripts(str(tmpdir))
            with open(str(tmpdir.join('foo')), 'r', encoding="utf-8") as f:
                actual = f.readline()
        assert actual == expected

    @pytest.mark.skipif(sys.platform != 'win32', reason='Windows only')
    def test_sys_executable_escaping_win32(self, tmpdir, monkeypatch):
        """
        Ensure that shebang is quoted on Windows when getting the Python exe
        from sys.executable and it contains a space.
        """
        expected = f'#!"{self.win32_exe}"\n'
        monkeypatch.setattr('sys.executable', self.win32_exe)
        with tmpdir.as_cwd():
            self._run_install_scripts(str(tmpdir))
            with open(str(tmpdir.join('foo-script.py')), 'r', encoding="utf-8") as f:
                actual = f.readline()
        assert actual == expected

    @pytest.mark.skipif(sys.platform == 'win32', reason='non-Windows only')
    def test_executable_with_spaces_escaping_unix(self, tmpdir):
        """
        Ensure that shebang on Unix is not quoted, even when
        a value with spaces
        is specified using --executable.
        """
        expected = f'#!{self.unix_spaces_exe}\n'
        with tmpdir.as_cwd():
            self._run_install_scripts(str(tmpdir), self.unix_spaces_exe)
            with open(str(tmpdir.join('foo')), 'r', encoding="utf-8") as f:
                actual = f.readline()
        assert actual == expected

    @pytest.mark.skipif(sys.platform != 'win32', reason='Windows only')
    def test_executable_arg_escaping_win32(self, tmpdir):
        """
        Ensure that shebang on Windows is quoted when
        getting a path with spaces
        from --executable, that is itself properly quoted.
        """
        expected = f'#!"{self.win32_exe}"\n'
        with tmpdir.as_cwd():
            self._run_install_scripts(str(tmpdir), '"' + self.win32_exe + '"')
            with open(str(tmpdir.join('foo-script.py')), 'r', encoding="utf-8") as f:
                actual = f.readline()
        assert actual == expected

Directory Contents

Dirs: 5 × Files: 45

Name Size Perms Modified Actions
compat DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
config DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
indexes DIR
- drwxr-xr-x 2026-01-20 13:01:47
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:01:49
Edit Download
3.09 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.03 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
11.43 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
22 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.71 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
18 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
845 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
775 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.91 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
22.54 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
798 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.05 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
9.86 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
32.51 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
13.85 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
22.05 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
20.39 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
424 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.00 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
8.68 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
5.85 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
4.87 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
41.62 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
43.89 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
296 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
7.64 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.35 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
887 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.35 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.05 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
18.13 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
4.41 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
379 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
32.10 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.33 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
8.80 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
641 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
316 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.64 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.27 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
18.31 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
7.68 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
123 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
98 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
335 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).