diff options
| -rw-r--r-- | setuptools/tests/test_easy_install.py | 70 | ||||
| -rw-r--r-- | setuptools/tests/test_resources.py | 69 |
2 files changed, 70 insertions, 69 deletions
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 30789e83..b8918b17 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -1,3 +1,7 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# NOTE: the shebang and encoding lines are for TestScriptHeader do not remove + """Easy install Tests """ from __future__ import absolute_import @@ -16,10 +20,13 @@ import pytest import mock from setuptools import sandbox +from setuptools import compat from setuptools.compat import StringIO, BytesIO, urlparse from setuptools.sandbox import run_setup, SandboxViolation from setuptools.command.easy_install import ( - easy_install, fix_jython_executable, get_script_args, nt_quote_arg) + easy_install, fix_jython_executable, get_script_args, nt_quote_arg, + get_script_header, +) from setuptools.command.easy_install import PthDistributions from setuptools.command import easy_install as easy_install_pkg from setuptools.dist import Distribution @@ -414,3 +421,64 @@ def make_trivial_sdist(dist_path, setup_py): 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) + + +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): + 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 + + def test_get_script_header_jython_workaround(self): + # This test doesn't work with Python 3 in some locales + if compat.PY3 and os.environ.get("LC_CTYPE") in (None, "C", "POSIX"): + return + + class java: + class lang: + class System: + @staticmethod + def getProperty(property): + return "" + sys.modules["java"] = java + + platform = sys.platform + sys.platform = 'java1.5.0_13' + stdout, stderr = sys.stdout, sys.stderr + try: + # A mock sys.executable that uses a shebang line (this file) + exe = os.path.normpath(os.path.splitext(__file__)[0] + '.py') + assert ( + get_script_header('#!/usr/local/bin/python', executable=exe) + == + '#!/usr/bin/env %s\n' % exe + ) + + # Ensure we generate what is basically a broken shebang line + # when there's options, with a warning emitted + sys.stdout = sys.stderr = StringIO() + candidate = get_script_header('#!/usr/bin/python -x', + executable=exe) + assert candidate == '#!%s -x\n' % exe + assert 'Unable to adapt shebang line' in sys.stdout.getvalue() + sys.stdout = sys.stderr = StringIO() + candidate = get_script_header('#!/usr/bin/python', + executable=self.non_ascii_exe) + assert candidate == '#!%s -x\n' % self.non_ascii_exe + assert 'Unable to adapt shebang line' in sys.stdout.getvalue() + finally: + del sys.modules["java"] + sys.platform = platform + sys.stdout, sys.stderr = stdout, stderr diff --git a/setuptools/tests/test_resources.py b/setuptools/tests/test_resources.py index 94370ff1..39d7ba49 100644 --- a/setuptools/tests/test_resources.py +++ b/setuptools/tests/test_resources.py @@ -1,7 +1,3 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# NOTE: the shebang and encoding lines are for TestScriptHeader do not remove - import os import sys import tempfile @@ -16,9 +12,7 @@ from pkg_resources import (parse_requirements, VersionConflict, parse_version, packaging = pkg_resources.packaging -from setuptools.command.easy_install import (get_script_header, is_sh, - nt_quote_arg) -from setuptools.compat import StringIO, iteritems, PY3 +from setuptools.compat import iteritems def safe_repr(obj, short=False): """ copied from Python2.7""" @@ -560,67 +554,6 @@ class TestParsing: ) -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): - 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 - - def test_get_script_header_jython_workaround(self): - # This test doesn't work with Python 3 in some locales - if PY3 and os.environ.get("LC_CTYPE") in (None, "C", "POSIX"): - return - - class java: - class lang: - class System: - @staticmethod - def getProperty(property): - return "" - sys.modules["java"] = java - - platform = sys.platform - sys.platform = 'java1.5.0_13' - stdout, stderr = sys.stdout, sys.stderr - try: - # A mock sys.executable that uses a shebang line (this file) - exe = os.path.normpath(os.path.splitext(__file__)[0] + '.py') - assert ( - get_script_header('#!/usr/local/bin/python', executable=exe) - == - '#!/usr/bin/env %s\n' % exe - ) - - # Ensure we generate what is basically a broken shebang line - # when there's options, with a warning emitted - sys.stdout = sys.stderr = StringIO() - candidate = get_script_header('#!/usr/bin/python -x', - executable=exe) - assert candidate == '#!%s -x\n' % exe - assert 'Unable to adapt shebang line' in sys.stdout.getvalue() - sys.stdout = sys.stderr = StringIO() - candidate = get_script_header('#!/usr/bin/python', - executable=self.non_ascii_exe) - assert candidate == '#!%s -x\n' % self.non_ascii_exe - assert 'Unable to adapt shebang line' in sys.stdout.getvalue() - finally: - del sys.modules["java"] - sys.platform = platform - sys.stdout, sys.stderr = stdout, stderr - - class TestNamespaces: def setup_method(self, method): |
