CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
test_install_scripts.py90 linesDownload Raw Back to tests
1"""install_scripts tests"""2 3import sys4 5import pytest6 7from setuptools.command.install_scripts import install_scripts8from setuptools.dist import Distribution9 10from . import contexts11 12 13class TestInstallScripts:14    settings = dict(15        name='foo',16        entry_points={'console_scripts': ['foo=foo:foo']},17        version='0.0',18    )19    unix_exe = '/usr/dummy-test-path/local/bin/python'20    unix_spaces_exe = '/usr/bin/env dummy-test-python'21    win32_exe = 'C:\\Dummy Test Path\\Program Files\\Python 3.6\\python.exe'22 23    def _run_install_scripts(self, install_dir, executable=None):24        dist = Distribution(self.settings)25        dist.script_name = 'setup.py'26        cmd = install_scripts(dist)27        cmd.install_dir = install_dir28        if executable is not None:29            bs = cmd.get_finalized_command('build_scripts')30            bs.executable = executable31        cmd.ensure_finalized()32        with contexts.quiet():33            cmd.run()34 35    @pytest.mark.skipif(sys.platform == 'win32', reason='non-Windows only')36    def test_sys_executable_escaping_unix(self, tmpdir, monkeypatch):37        """38        Ensure that shebang is not quoted on Unix when getting the Python exe39        from sys.executable.40        """41        expected = f'#!{self.unix_exe}\n'42        monkeypatch.setattr('sys.executable', self.unix_exe)43        with tmpdir.as_cwd():44            self._run_install_scripts(str(tmpdir))45            with open(str(tmpdir.join('foo')), 'r', encoding="utf-8") as f:46                actual = f.readline()47        assert actual == expected48 49    @pytest.mark.skipif(sys.platform != 'win32', reason='Windows only')50    def test_sys_executable_escaping_win32(self, tmpdir, monkeypatch):51        """52        Ensure that shebang is quoted on Windows when getting the Python exe53        from sys.executable and it contains a space.54        """55        expected = f'#!"{self.win32_exe}"\n'56        monkeypatch.setattr('sys.executable', self.win32_exe)57        with tmpdir.as_cwd():58            self._run_install_scripts(str(tmpdir))59            with open(str(tmpdir.join('foo-script.py')), 'r', encoding="utf-8") as f:60                actual = f.readline()61        assert actual == expected62 63    @pytest.mark.skipif(sys.platform == 'win32', reason='non-Windows only')64    def test_executable_with_spaces_escaping_unix(self, tmpdir):65        """66        Ensure that shebang on Unix is not quoted, even when67        a value with spaces68        is specified using --executable.69        """70        expected = f'#!{self.unix_spaces_exe}\n'71        with tmpdir.as_cwd():72            self._run_install_scripts(str(tmpdir), self.unix_spaces_exe)73            with open(str(tmpdir.join('foo')), 'r', encoding="utf-8") as f:74                actual = f.readline()75        assert actual == expected76 77    @pytest.mark.skipif(sys.platform != 'win32', reason='Windows only')78    def test_executable_arg_escaping_win32(self, tmpdir):79        """80        Ensure that shebang on Windows is quoted when81        getting a path with spaces82        from --executable, that is itself properly quoted.83        """84        expected = f'#!"{self.win32_exe}"\n'85        with tmpdir.as_cwd():86            self._run_install_scripts(str(tmpdir), '"' + self.win32_exe + '"')87            with open(str(tmpdir.join('foo-script.py')), 'r', encoding="utf-8") as f:88                actual = f.readline()89        assert actual == expected90 
Aluode/PerceptionLabPortable · CoolFace