diff options
Diffstat (limited to 'setuptools/tests/test_dist.py')
-rw-r--r-- | setuptools/tests/test_dist.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index c4c9bd03..0c10f05b 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -1,10 +1,13 @@ +# -*- coding: utf-8 -*- from setuptools import Distribution from setuptools.extern.six.moves.urllib.request import pathname2url from setuptools.extern.six.moves.urllib_parse import urljoin +from setuptools.extern.six import StringIO from .textwrap import DALS from .test_easy_install import make_nspkg_sdist +import pytest def test_dist_fetch_build_egg(tmpdir): """ @@ -45,3 +48,78 @@ def test_dist_fetch_build_egg(tmpdir): for r in reqs ] assert [dist.key for dist in resolved_dists if dist] == reqs + + +def __maintainer_test_cases(): + attrs = {"name": "package", + "version": "1.0", + "description": "xxx"} + + def merge_dicts(d1, d2): + d1 = d1.copy() + d1.update(d2) + + return d1 + + test_cases = [ + ('No author, no maintainer', attrs.copy()), + ('Author (no e-mail), no maintainer', merge_dicts(attrs, + {'author': 'Author Name'})), + ('Author (e-mail), no maintainer', merge_dicts(attrs, + {'author': 'Author Name', + 'author_email': 'author@name.com'})), + ('No author, maintainer (no e-mail)', merge_dicts(attrs, + {'maintainer': 'Maintainer Name'})), + ('No author, maintainer (e-mail)', merge_dicts(attrs, + {'maintainer': 'Maintainer Name', + 'maintainer_email': 'maintainer@name.com'})), + ('Author (no e-mail), Maintainer (no-email)', merge_dicts(attrs, + {'author': 'Author Name', + 'maintainer': 'Maintainer Name'})), + ('Author (e-mail), Maintainer (e-mail)', merge_dicts(attrs, + {'author': 'Author Name', + 'author_email': 'author@name.com', + 'maintainer': 'Maintainer Name', + 'maintainer_email': 'maintainer@name.com'})), + ('No author (e-mail), no maintainer (e-mail)', merge_dicts(attrs, + {'author_email': 'author@name.com', + 'maintainer_email': 'maintainer@name.com'})), + ('Author unicode', merge_dicts(attrs, + {'author': '鉄沢寛'})), + ('Maintainer unicode', merge_dicts(attrs, + {'maintainer': 'Jan Łukasiewicz'})), + ] + + return test_cases + +@pytest.mark.parametrize('name,attrs', __maintainer_test_cases()) +def test_maintainer_author(name, attrs): + tested_keys = { + 'author': 'Author', + 'author_email': 'Author-email', + 'maintainer': 'Maintainer', + 'maintainer_email': 'Maintainer-email', + } + + # Generate a PKG-INFO file + dist = Distribution(attrs) + PKG_INFO = StringIO() + dist.metadata.write_pkg_file(PKG_INFO) + PKG_INFO.seek(0) + + pkg_lines = PKG_INFO.readlines() + pkg_lines = [_ for _ in pkg_lines if _] # Drop blank lines + pkg_lines_set = set(pkg_lines) + + # Duplicate lines should not be generated + assert len(pkg_lines) == len(pkg_lines_set) + + for fkey, dkey in tested_keys.items(): + val = attrs.get(dkey, None) + if val is None: + for line in pkg_lines: + assert not line.startswith(fkey + ':') + else: + line = '%s: %s' % (fkey, val) + assert line in pkg_lines_set + |