コード例 #1
0
    def test_get_script_header_jython_workaround(self, tmpdir):
        # Create a mock sys.executable that uses a shebang line
        header = DALS("""
            #!/usr/bin/python
            # -*- coding: utf-8 -*-
            """)
        exe = tmpdir / 'exe.py'
        with exe.open('w') as f:
            f.write(header)
        exe = str(exe)

        header = ScriptWriter.get_script_header('#!/usr/local/bin/python',
            executable=exe)
        assert header == '#!/usr/bin/env %s\n' % exe

        expect_out = 'stdout' if sys.version_info < (2,7) else 'stderr'

        with contexts.quiet() as (stdout, stderr):
            # When options are included, generate a broken shebang line
            # with a warning emitted
            candidate = ScriptWriter.get_script_header('#!/usr/bin/python -x',
                executable=exe)
            assert candidate == '#!%s -x\n' % exe
            output = locals()[expect_out]
            assert 'Unable to adapt shebang line' in output.getvalue()

        with contexts.quiet() as (stdout, stderr):
            candidate = ScriptWriter.get_script_header('#!/usr/bin/python',
                executable=self.non_ascii_exe)
            assert candidate == '#!%s -x\n' % self.non_ascii_exe
            output = locals()[expect_out]
            assert 'Unable to adapt shebang line' in output.getvalue()
コード例 #2
0
    def test_get_script_header_jython_workaround(self, tmpdir):
        # Create a mock sys.executable that uses a shebang line
        header = DALS("""
            #!/usr/bin/python
            # -*- coding: utf-8 -*-
            """)
        exe = tmpdir / 'exe.py'
        with exe.open('w') as f:
            f.write(header)
        exe = str(exe)

        header = ScriptWriter.get_script_header('#!/usr/local/bin/python',
            executable=exe)
        assert header == '#!/usr/bin/env %s\n' % exe

        expect_out = 'stdout' if sys.version_info < (2,7) else 'stderr'

        with contexts.quiet() as (stdout, stderr):
            # When options are included, generate a broken shebang line
            # with a warning emitted
            candidate = ScriptWriter.get_script_header('#!/usr/bin/python -x',
                executable=exe)
            assert candidate == '#!%s -x\n' % exe
            output = locals()[expect_out]
            assert 'Unable to adapt shebang line' in output.getvalue()

        with contexts.quiet() as (stdout, stderr):
            candidate = ScriptWriter.get_script_header('#!/usr/bin/python',
                executable=self.non_ascii_exe)
            assert candidate == '#!%s -x\n' % self.non_ascii_exe
            output = locals()[expect_out]
            assert 'Unable to adapt shebang line' in output.getvalue()
コード例 #3
0
    def test_get_script_args(self):
        dist = FakeDist()

        args = next(ScriptWriter.get_args(dist))
        name, script = itertools.islice(args, 2)

        assert script == WANTED
コード例 #4
0
    def test_get_script_args(self):
        dist = FakeDist()

        args = next(ScriptWriter.get_args(dist))
        name, script = itertools.islice(args, 2)

        assert script == WANTED
コード例 #5
0
 def test_sys_executable(self):
     """
     CommandSpec.from_string(sys.executable) should contain just that param.
     """
     writer = ScriptWriter.best()
     cmd = writer.command_spec_class.from_string(sys.executable)
     assert len(cmd) == 1
     assert cmd[0] == sys.executable
コード例 #6
0
    def test_get_script_header(self):
        expected = '#!%s\n' % nt_quote_arg(os.path.normpath(sys.executable))
        actual = ScriptWriter.get_script_header('#!/usr/local/bin/python')
        assert actual == expected

        expected = '#!%s -x\n' % nt_quote_arg(os.path.normpath(sys.executable))
        actual = ScriptWriter.get_script_header('#!/usr/bin/python -x')
        assert actual == expected

        actual = ScriptWriter.get_script_header('#!/usr/bin/python',
            executable=self.non_ascii_exe)
        expected = '#!%s -x\n' % self.non_ascii_exe
        assert actual == expected

        actual = ScriptWriter.get_script_header('#!/usr/bin/python',
            executable='"'+self.exe_with_spaces+'"')
        expected = '#!"%s"\n' % self.exe_with_spaces
        assert actual == expected
コード例 #7
0
def install_py3_cmd(installer):
    """Attempt to overwrite /bin/py3-cmd with efficient version"""
    py_cmd = ScriptWriter.get_header()
    script_text = PY3_CMD_SCRIPT_TEXT.format(py_cmd)
    try:
        installer.write_script('py3-cmd', _to_ascii(script_text), 'b')
    except AttributeError:
        # building wheel etc
        pass
コード例 #8
0
ファイル: setup.py プロジェクト: Cypher1/py3status
def install_py3_cmd(installer):
    """Attempt to overwrite /bin/py3-cmd with efficient version"""
    py_cmd = ScriptWriter.get_header()
    script_text = PY3_CMD_SCRIPT_TEXT.format(py_cmd)
    try:
        installer.write_script('py3-cmd', _to_ascii(script_text), 'b')
    except AttributeError:
        # building wheel etc
        pass
コード例 #9
0
    def test_get_script_header(self):
        expected = '#!%s\n' % nt_quote_arg(os.path.normpath(sys.executable))
        actual = ScriptWriter.get_script_header('#!/usr/local/bin/python')
        assert actual == expected

        expected = '#!%s -x\n' % nt_quote_arg(os.path.normpath(sys.executable))
        actual = ScriptWriter.get_script_header('#!/usr/bin/python -x')
        assert actual == expected

        actual = ScriptWriter.get_script_header('#!/usr/bin/python',
            executable=self.non_ascii_exe)
        expected = '#!%s -x\n' % self.non_ascii_exe
        assert actual == expected

        actual = ScriptWriter.get_script_header('#!/usr/bin/python',
            executable='"'+self.exe_with_spaces+'"')
        expected = '#!"%s"\n' % self.exe_with_spaces
        assert actual == expected
コード例 #10
0
 def test_dist_get_writer_deprecated(self):
     with pytest.warns(EasyInstallDeprecationWarning):
         ScriptWriter.get_writer(None)