diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2019-01-27 09:11:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-27 09:11:50 -0500 |
commit | b31997dbcd935ded39868b42d765830ad6e29808 (patch) | |
tree | c33f768bcfec750fb567100303aa30dae488acdb /setuptools/tests | |
parent | 5cd86987530892bfb01f68ad5f1a2b997a3d01e7 (diff) | |
parent | 249f24a1f04ce390a9e48a4d8a5bff7982714c86 (diff) | |
download | external_python_setuptools-b31997dbcd935ded39868b42d765830ad6e29808.tar.gz external_python_setuptools-b31997dbcd935ded39868b42d765830ad6e29808.tar.bz2 external_python_setuptools-b31997dbcd935ded39868b42d765830ad6e29808.zip |
Merge pull request #1180 from benoit-pierre/fix_889_and_non-ascii_in_setup.cfg_take_2
improve encoding handling for `setup.cfg`
Diffstat (limited to 'setuptools/tests')
-rw-r--r-- | setuptools/tests/test_config.py | 75 | ||||
-rw-r--r-- | setuptools/tests/test_egg_info.py | 46 |
2 files changed, 119 insertions, 2 deletions
diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py index a6b44b9f..6b177709 100644 --- a/setuptools/tests/test_config.py +++ b/setuptools/tests/test_config.py @@ -1,3 +1,6 @@ +# -*- coding: UTF-8 -*- +from __future__ import unicode_literals + import contextlib import pytest @@ -5,6 +8,8 @@ from distutils.errors import DistutilsOptionError, DistutilsFileError from mock import patch from setuptools.dist import Distribution, _Distribution from setuptools.config import ConfigHandler, read_configuration +from setuptools.extern.six.moves.configparser import InterpolationMissingOptionError +from setuptools.tests import is_ascii from . import py2_only, py3_only from .textwrap import DALS @@ -24,7 +29,7 @@ def make_package_dir(name, base_dir, ns=False): return dir_package, init_file -def fake_env(tmpdir, setup_cfg, setup_py=None, package_path='fake_package'): +def fake_env(tmpdir, setup_cfg, setup_py=None, encoding='ascii', package_path='fake_package'): if setup_py is None: setup_py = ( @@ -34,7 +39,7 @@ def fake_env(tmpdir, setup_cfg, setup_py=None, package_path='fake_package'): tmpdir.join('setup.py').write(setup_py) config = tmpdir.join('setup.cfg') - config.write(setup_cfg) + config.write(setup_cfg.encode(encoding), mode='wb') package_dir, init_file = make_package_dir(package_path, tmpdir) @@ -429,6 +434,72 @@ class TestMetadata: assert metadata.description == 'Some description' assert metadata.requires == ['some', 'requirement'] + def test_interpolation(self, tmpdir): + fake_env( + tmpdir, + '[metadata]\n' + 'description = %(message)s\n' + ) + with pytest.raises(InterpolationMissingOptionError): + with get_dist(tmpdir): + pass + + skip_if_not_ascii = pytest.mark.skipif(not is_ascii, reason='Test not supported with this locale') + + @skip_if_not_ascii + def test_non_ascii_1(self, tmpdir): + fake_env( + tmpdir, + '[metadata]\n' + 'description = éàïôñ\n', + encoding='utf-8' + ) + with pytest.raises(UnicodeDecodeError): + with get_dist(tmpdir): + pass + + def test_non_ascii_2(self, tmpdir): + fake_env( + tmpdir, + '# -*- coding: invalid\n' + ) + with pytest.raises(LookupError): + with get_dist(tmpdir): + pass + + def test_non_ascii_3(self, tmpdir): + fake_env( + tmpdir, + '\n' + '# -*- coding: invalid\n' + ) + with get_dist(tmpdir): + pass + + @skip_if_not_ascii + def test_non_ascii_4(self, tmpdir): + fake_env( + tmpdir, + '# -*- coding: utf-8\n' + '[metadata]\n' + 'description = éàïôñ\n', + encoding='utf-8' + ) + with get_dist(tmpdir) as dist: + assert dist.metadata.description == 'éàïôñ' + + @skip_if_not_ascii + def test_non_ascii_5(self, tmpdir): + fake_env( + tmpdir, + '# vim: set fileencoding=iso-8859-15 :\n' + '[metadata]\n' + 'description = éàïôñ\n', + encoding='iso-8859-15' + ) + with get_dist(tmpdir) as dist: + assert dist.metadata.description == 'éàïôñ' + class TestOptions: diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index 571e6054..d5fa2558 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -652,3 +652,49 @@ class TestEggInfo: def test_get_pkg_info_revision_deprecated(self): pytest.warns(EggInfoDeprecationWarning, get_pkg_info_revision) + + EGG_INFO_TESTS = ( + # Check for issue #1136: invalid string type when + # reading declarative `setup.cfg` under Python 2. + { + 'setup.py': DALS( + """ + from setuptools import setup + setup( + name="foo", + ) + """), + 'setup.cfg': DALS( + """ + [options] + package_dir = + = src + """), + 'src': {}, + }, + # Check Unicode can be used in `setup.py` under Python 2. + { + 'setup.py': DALS( + """ + # -*- coding: utf-8 -*- + from __future__ import unicode_literals + from setuptools import setup, find_packages + setup( + name="foo", + package_dir={'': 'src'}, + ) + """), + 'src': {}, + } + ) + + @pytest.mark.parametrize('package_files', EGG_INFO_TESTS) + def test_egg_info(self, tmpdir_cwd, env, package_files): + """ + """ + build_files(package_files) + code, data = environment.run_setup_py( + cmd=['egg_info'], + data_stream=1, + ) + assert not code, data |