Ejemplo n.º 1
0
class TestScriptHeader:
    non_ascii_exe = '/Users/José/bin/python'
    exe_with_spaces = r'C:\Program Files\Python33\python.exe'

    @pytest.mark.skipif(
        sys.platform.startswith('java') and ei.is_sh(sys.executable),
        reason="Test cannot run under java when executable is sh")
    def test_get_script_header(self):
        expected = '#!%s\n' % ei.nt_quote_arg(os.path.normpath(sys.executable))
        actual = ei.ScriptWriter.get_script_header('#!/usr/local/bin/python')
        assert actual == expected

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

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

        actual = ei.ScriptWriter.get_script_header('#!/usr/bin/python',
                                                   executable='"' +
                                                   self.exe_with_spaces + '"')
        expected = '#!"%s"\n' % self.exe_with_spaces
        assert actual == expected
Ejemplo n.º 2
0
class TestScriptHeader:
    non_ascii_exe = '/Users/José/bin/python'
    exe_with_spaces = r'C:\Program Files\Python33\python.exe'

    @pytest.mark.skipif(
        sys.platform.startswith('java') and is_sh(sys.executable),
        reason="Test cannot run under java when executable is sh")
    def test_get_script_header(self):
        expected = '#!%s\n' % nt_quote_arg(os.path.normpath(sys.executable))
        assert get_script_header('#!/usr/local/bin/python') == expected
        expected = '#!%s  -x\n' % nt_quote_arg(os.path.normpath(
            sys.executable))
        assert get_script_header('#!/usr/bin/python -x') == expected
        candidate = get_script_header('#!/usr/bin/python',
                                      executable=self.non_ascii_exe)
        assert candidate == '#!%s -x\n' % self.non_ascii_exe
        candidate = get_script_header('#!/usr/bin/python',
                                      executable=self.exe_with_spaces)
        assert candidate == '#!"%s"\n' % self.exe_with_spaces

    @pytest.mark.xfail(compat.PY3
                       and os.environ.get("LC_CTYPE") in ("C", "POSIX"),
                       reason="Test fails in this locale on Python 3")
    @mock.patch.dict(sys.modules,
                     java=mock.Mock(lang=mock.Mock(System=mock.Mock(
                         getProperty=mock.Mock(return_value="")))))
    @mock.patch('sys.platform', 'java1.5.0_13')
    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 = 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 = 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 = 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()
Ejemplo n.º 3
0
 def test_get_script_header(self):
     if not sys.platform.startswith('java') or not is_sh(sys.executable):
         # This test is for non-Jython platforms
         self.assertEqual(get_script_header('#!/usr/local/bin/python'),
                          '#!%s\n' % os.path.normpath(sys.executable))
         self.assertEqual(get_script_header('#!/usr/bin/python -x'),
                          '#!%s  -x\n' % os.path.normpath(sys.executable))
         self.assertEqual(get_script_header('#!/usr/bin/python',
                                            executable=self.non_ascii_exe),
                          '#!%s -x\n' % self.non_ascii_exe)
Ejemplo n.º 4
0
 def test_get_script_header(self):
     if not sys.platform.startswith('java') or not is_sh(sys.executable):
         # This test is for non-Jython platforms
         self.assertEqual(get_script_header('#!/usr/local/bin/python'),
                          '#!%s\n' % os.path.normpath(sys.executable))
         self.assertEqual(get_script_header('#!/usr/bin/python -x'),
                          '#!%s  -x\n' % os.path.normpath(sys.executable))
         self.assertEqual(get_script_header('#!/usr/bin/python',
                                            executable=self.non_ascii_exe),
                          '#!%s -x\n' % self.non_ascii_exe)
Ejemplo n.º 5
0
 def test_get_script_header(self):
     if not sys.platform.startswith('java') or not is_sh(sys.executable):
         # This test is for non-Jython platforms
         expected = '#!%s\n' % nt_quote_arg(os.path.normpath(sys.executable))
         assert get_script_header('#!/usr/local/bin/python') == expected
         expected = '#!%s  -x\n' % nt_quote_arg(os.path.normpath(sys.executable))
         assert get_script_header('#!/usr/bin/python -x') == expected
         candidate = get_script_header('#!/usr/bin/python',
             executable=self.non_ascii_exe)
         assert candidate == '#!%s -x\n' % self.non_ascii_exe
         candidate = get_script_header('#!/usr/bin/python',
             executable=self.exe_with_spaces)
         assert candidate == '#!"%s"\n' % self.exe_with_spaces
Ejemplo n.º 6
0
 def test_get_script_header(self):
     if not sys.platform.startswith('java') or not is_sh(sys.executable):
         # This test is for non-Jython platforms
         expected = '#!%s\n' % nt_quote_arg(os.path.normpath(sys.executable))
         self.assertEqual(get_script_header('#!/usr/local/bin/python'),
             expected)
         expected = '#!%s  -x\n' % nt_quote_arg(os.path.normpath(sys.executable))
         self.assertEqual(get_script_header('#!/usr/bin/python -x'),
             expected)
         self.assertEqual(get_script_header('#!/usr/bin/python',
                                            executable=self.non_ascii_exe),
                          '#!%s -x\n' % self.non_ascii_exe)
         candidate = get_script_header('#!/usr/bin/python',
             executable=self.exe_with_spaces)
         self.assertEqual(candidate, '#!"%s"\n' % self.exe_with_spaces)
Ejemplo n.º 7
0
def _jython_as_header(self):
    '''Workaround Jython's sys.executable being a .sh (an invalid
    shebang line interpreter)
    '''
    if not ez.is_sh(self[0]):
        return _as_header(self)

    if self.options:
        # Can't apply the workaround, leave it broken
        log.warn(
            "WARNING: Unable to adapt shebang line for Jython,"
            " the following script is NOT executable\n"
            "         see http://bugs.jython.org/issue1112 for"
            " more information.")
        return _as_header(self)

    items = ['/usr/bin/env'] + self + list(self.options)
    return self._render(items)
Ejemplo n.º 8
0
    if setup_py_template is None:
        setup_py_template = DALS("""\
            import setuptools
            setuptools.setup(**%r)
        """)
    with open(test_setup_py, 'w') as f:
        f.write(setup_py_template % test_setup_attrs)

    foobar_path = os.path.join(path, '%s-%s.tar.gz' % (distname, version))
    make_package(foobar_path, distname, version)

    return test_pkg


@pytest.mark.skipif(sys.platform.startswith('java')
                    and ei.is_sh(sys.executable),
                    reason="Test cannot run under java when executable is sh")
class TestScriptHeader:
    non_ascii_exe = '/Users/José/bin/python'
    if six.PY2:
        non_ascii_exe = non_ascii_exe.encode('utf-8')
    exe_with_spaces = r'C:\Program Files\Python36\python.exe'

    def test_get_script_header(self):
        expected = '#!%s\n' % ei.nt_quote_arg(os.path.normpath(sys.executable))
        actual = ei.ScriptWriter.get_header('#!/usr/local/bin/python')
        assert actual == expected

    def test_get_script_header_args(self):
        expected = '#!%s -x\n' % ei.nt_quote_arg(
            os.path.normpath(sys.executable))
Ejemplo n.º 9
0

def make_trivial_sdist(dist_path, setup_py):
    """Create a simple sdist tarball at dist_path, containing just a
    setup.py, the contents of which are provided by the setup_py string.
    """

    setup_py_file = tarfile.TarInfo(name='setup.py')
    setup_py_bytes = io.BytesIO(setup_py.encode('utf-8'))
    setup_py_file.size = len(setup_py_bytes.getvalue())
    with tarfile_open(dist_path, 'w:gz') as dist:
        dist.addfile(setup_py_file, fileobj=setup_py_bytes)


@pytest.mark.skipif(
    sys.platform.startswith('java') and ei.is_sh(sys.executable),
    reason="Test cannot run under java when executable is sh"
)
class TestScriptHeader:
    non_ascii_exe = '/Users/José/bin/python'
    exe_with_spaces = r'C:\Program Files\Python33\python.exe'

    def test_get_script_header(self):
        expected = '#!%s\n' % ei.nt_quote_arg(os.path.normpath(sys.executable))
        actual = ei.ScriptWriter.get_script_header('#!/usr/local/bin/python')
        assert actual == expected

    def test_get_script_header_args(self):
        expected = '#!%s -x\n' % ei.nt_quote_arg(os.path.normpath
            (sys.executable))
        actual = ei.ScriptWriter.get_script_header('#!/usr/bin/python -x')
Ejemplo n.º 10
0
    if setup_py_template is None:
        setup_py_template = DALS("""\
            import setuptools
            setuptools.setup(**%r)
        """)
    with open(os.path.join(test_pkg, 'setup.py'), 'w') as f:
        f.write(setup_py_template % test_setup_attrs)

    foobar_path = os.path.join(path, '%s-%s.tar.gz' % (distname, version))
    make_package(foobar_path, distname, version)

    return test_pkg


@pytest.mark.skipif(
    sys.platform.startswith('java') and ei.is_sh(sys.executable),
    reason="Test cannot run under java when executable is sh"
)
class TestScriptHeader:
    non_ascii_exe = '/Users/José/bin/python'
    exe_with_spaces = r'C:\Program Files\Python36\python.exe'

    def test_get_script_header(self):
        expected = '#!%s\n' % ei.nt_quote_arg(os.path.normpath(sys.executable))
        actual = ei.ScriptWriter.get_header('#!/usr/local/bin/python')
        assert actual == expected

    def test_get_script_header_args(self):
        expected = '#!%s -x\n' % ei.nt_quote_arg(
            os.path.normpath(sys.executable))
        actual = ei.ScriptWriter.get_header('#!/usr/bin/python -x')