From e5461b6ccc57596c7e9cf7837084f8a20eeec9b7 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Sat, 5 Aug 2017 18:31:53 +0200 Subject: workaround easy_install bug Don't reuse `easy_install` command in `Distribution.fetch_build_egg` implementation. Fix #196. --- setuptools/tests/test_dist.py | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 setuptools/tests/test_dist.py (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py new file mode 100644 index 00000000..435ffec0 --- /dev/null +++ b/setuptools/tests/test_dist.py @@ -0,0 +1,46 @@ +from setuptools import Distribution +from setuptools.extern.six.moves.urllib.request import pathname2url +from setuptools.extern.six.moves.urllib_parse import urljoin + +from .textwrap import DALS +from .test_easy_install import make_nspkg_sdist + + +def test_dist_fetch_build_egg(tmpdir): + """ + Check multiple calls to `Distribution.fetch_build_egg` work as expected. + """ + index = tmpdir.mkdir('index') + index_url = urljoin('file://', pathname2url(str(index))) + def sdist_with_index(distname, version): + dist_dir = index.mkdir(distname) + dist_sdist = '%s-%s.tar.gz' % (distname, version) + make_nspkg_sdist(str(dist_dir.join(dist_sdist)), distname, version) + with dist_dir.join('index.html').open('w') as fp: + fp.write(DALS( + ''' + + {dist_sdist}
+ + ''' + ).format(dist_sdist=dist_sdist)) + sdist_with_index('barbazquux', '3.2.0') + sdist_with_index('barbazquux-runner', '2.11.1') + with tmpdir.join('setup.cfg').open('w') as fp: + fp.write(DALS( + ''' + [easy_install] + index_url = {index_url} + ''' + ).format(index_url=index_url)) + reqs = ''' + barbazquux-runner + barbazquux + '''.split() + with tmpdir.as_cwd(): + dist = Distribution() + resolved_dists = [ + dist.fetch_build_egg(r) + for r in reqs + ] + assert [dist.key for dist in resolved_dists if dist] == reqs -- cgit v1.2.1 From 472c79f95cc41a3e85d6b212347d6b006c9c3c26 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Thu, 14 Sep 2017 22:07:13 +0200 Subject: support `setup_requires` in setup.cfg --- setuptools/tests/test_dist.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 435ffec0..c4c9bd03 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -39,6 +39,7 @@ def test_dist_fetch_build_egg(tmpdir): '''.split() with tmpdir.as_cwd(): dist = Distribution() + dist.parse_config_files() resolved_dists = [ dist.fetch_build_egg(r) for r in reqs -- cgit v1.2.1 From d8170d79a1059b6c58e1b54d94c6600f85354bf6 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Fri, 16 Mar 2018 18:23:24 -0400 Subject: Add support for maintainer in PKG-INFO Per PEP 345, metadata Version 1.2 should support the Author, Maintainer, Author-Email and Maintainer-Email fields. --- setuptools/tests/test_dist.py | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'setuptools/tests/test_dist.py') 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 + -- cgit v1.2.1 From 2005e53e887c4ce6ca6da27241e43e3686e8f298 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Sat, 17 Mar 2018 19:59:08 -0400 Subject: Make dist test fail under unicode --- setuptools/tests/test_dist.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 0c10f05b..ed75b546 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -2,7 +2,6 @@ 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 @@ -85,15 +84,15 @@ def __maintainer_test_cases(): {'author_email': 'author@name.com', 'maintainer_email': 'maintainer@name.com'})), ('Author unicode', merge_dicts(attrs, - {'author': '鉄沢寛'})), + {'author': u'鉄沢寛'})), ('Maintainer unicode', merge_dicts(attrs, - {'maintainer': 'Jan Łukasiewicz'})), + {'maintainer': u'Jan Łukasiewicz'})), ] return test_cases @pytest.mark.parametrize('name,attrs', __maintainer_test_cases()) -def test_maintainer_author(name, attrs): +def test_maintainer_author(name, attrs, tmpdir): tested_keys = { 'author': 'Author', 'author_email': 'Author-email', @@ -103,11 +102,14 @@ def test_maintainer_author(name, attrs): # Generate a PKG-INFO file dist = Distribution(attrs) - PKG_INFO = StringIO() - dist.metadata.write_pkg_file(PKG_INFO) - PKG_INFO.seek(0) + fn = tmpdir.mkdir('pkg_info') + fn_s = str(fn) + + dist.metadata.write_pkg_info(fn_s) + + with open(str(fn.join('PKG-INFO')), 'r') as f: + pkg_lines = f.readlines() - pkg_lines = PKG_INFO.readlines() pkg_lines = [_ for _ in pkg_lines if _] # Drop blank lines pkg_lines_set = set(pkg_lines) -- cgit v1.2.1 From ad2d7e483ef5531962f6ca0c463704505afeb471 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 18 Mar 2018 09:54:37 -0400 Subject: Use unicode literals --- setuptools/tests/test_dist.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index ed75b546..74bd8cc8 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- + +from __future__ import unicode_literals + from setuptools import Distribution from setuptools.extern.six.moves.urllib.request import pathname2url from setuptools.extern.six.moves.urllib_parse import urljoin @@ -84,9 +87,9 @@ def __maintainer_test_cases(): {'author_email': 'author@name.com', 'maintainer_email': 'maintainer@name.com'})), ('Author unicode', merge_dicts(attrs, - {'author': u'鉄沢寛'})), + {'author': '鉄沢寛'})), ('Maintainer unicode', merge_dicts(attrs, - {'maintainer': u'Jan Łukasiewicz'})), + {'maintainer': 'Jan Łukasiewicz'})), ] return test_cases -- cgit v1.2.1 From d92bc63ddd88729ad0bd892eacce29439b821fd2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 18 Mar 2018 09:55:59 -0400 Subject: Delint --- setuptools/tests/test_dist.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 74bd8cc8..28b46fd3 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -11,12 +11,14 @@ from .test_easy_install import make_nspkg_sdist import pytest + def test_dist_fetch_build_egg(tmpdir): """ Check multiple calls to `Distribution.fetch_build_egg` work as expected. """ index = tmpdir.mkdir('index') index_url = urljoin('file://', pathname2url(str(index))) + def sdist_with_index(distname, version): dist_dir = index.mkdir(distname) dist_sdist = '%s-%s.tar.gz' % (distname, version) @@ -65,35 +67,45 @@ def __maintainer_test_cases(): test_cases = [ ('No author, no maintainer', attrs.copy()), - ('Author (no e-mail), no maintainer', merge_dicts(attrs, + ('Author (no e-mail), no maintainer', merge_dicts( + attrs, {'author': 'Author Name'})), - ('Author (e-mail), no maintainer', merge_dicts(attrs, + ('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, + ('No author, maintainer (no e-mail)', merge_dicts( + attrs, {'maintainer': 'Maintainer Name'})), - ('No author, maintainer (e-mail)', merge_dicts(attrs, + ('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 (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 (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, + ('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 unicode', merge_dicts( + attrs, {'author': '鉄沢寛'})), - ('Maintainer unicode', merge_dicts(attrs, + ('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, tmpdir): tested_keys = { @@ -127,4 +139,3 @@ def test_maintainer_author(name, attrs, tmpdir): else: line = '%s: %s' % (fkey, val) assert line in pkg_lines_set - -- cgit v1.2.1 From b38d71f2935ce069f5f1f6b2ccaa7b99c838db67 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 18 Mar 2018 09:59:32 -0400 Subject: Open metadata file with UTF-8 decoding. --- setuptools/tests/test_dist.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 28b46fd3..8d5c9e38 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -2,6 +2,8 @@ from __future__ import unicode_literals +import io + from setuptools import Distribution from setuptools.extern.six.moves.urllib.request import pathname2url from setuptools.extern.six.moves.urllib_parse import urljoin @@ -122,7 +124,7 @@ def test_maintainer_author(name, attrs, tmpdir): dist.metadata.write_pkg_info(fn_s) - with open(str(fn.join('PKG-INFO')), 'r') as f: + with io.open(str(fn.join('PKG-INFO')), 'r', encoding='utf-8') as f: pkg_lines = f.readlines() pkg_lines = [_ for _ in pkg_lines if _] # Drop blank lines -- cgit v1.2.1 From b1b837df6846cc64bdfec94408fc2276fbfe93ab Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 18 Mar 2018 10:00:57 -0400 Subject: Use filter to filter blank lines --- setuptools/tests/test_dist.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 8d5c9e38..0279318b 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -127,7 +127,9 @@ def test_maintainer_author(name, attrs, tmpdir): with io.open(str(fn.join('PKG-INFO')), 'r', encoding='utf-8') as f: pkg_lines = f.readlines() - pkg_lines = [_ for _ in pkg_lines if _] # Drop blank lines + # Drop blank lines + pkg_lines = list(filter(None, pkg_lines)) + pkg_lines_set = set(pkg_lines) # Duplicate lines should not be generated -- cgit v1.2.1 From eb6502d70552df1fa1272497c05d8c5893f6befe Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 18 Mar 2018 10:01:39 -0400 Subject: Use another variable name to avoid masking prior value. --- setuptools/tests/test_dist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 0279318b..5162e1c9 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -125,10 +125,10 @@ def test_maintainer_author(name, attrs, tmpdir): dist.metadata.write_pkg_info(fn_s) with io.open(str(fn.join('PKG-INFO')), 'r', encoding='utf-8') as f: - pkg_lines = f.readlines() + raw_pkg_lines = f.readlines() # Drop blank lines - pkg_lines = list(filter(None, pkg_lines)) + pkg_lines = list(filter(None, raw_pkg_lines)) pkg_lines_set = set(pkg_lines) -- cgit v1.2.1 From 3a9dc2b03ef313ee7729606fb56ae9b41066dfd1 Mon Sep 17 00:00:00 2001 From: robinjhuang Date: Sat, 27 Oct 2018 18:46:55 -0400 Subject: Add unit tests for setuptools deprecation warnings These are tests to ensure that the specified deprecation warnings are raised when the functions are called. Co-authored-by: Junhan Huang Co-authored-by: Marton Pono --- setuptools/tests/test_dist.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 5162e1c9..223ad90c 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import io - +from setuptools.dist import DistDeprecationWarning, _get_unpatched from setuptools import Distribution from setuptools.extern.six.moves.urllib.request import pathname2url from setuptools.extern.six.moves.urllib_parse import urljoin @@ -56,6 +56,9 @@ def test_dist_fetch_build_egg(tmpdir): assert [dist.key for dist in resolved_dists if dist] == reqs +def test_dist__get_unpatched_deprecated(): + pytest.warns(DistDeprecationWarning, _get_unpatched, [""]) + def __maintainer_test_cases(): attrs = {"name": "package", "version": "1.0", -- cgit v1.2.1 From 9ffb099b1154662bf1fa8da2a9e0cbef22a2a809 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Tue, 6 Nov 2018 09:10:00 -0500 Subject: Add test for read_pkg_file --- setuptools/tests/test_dist.py | 96 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 223ad90c..36605cea 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -59,6 +59,102 @@ def test_dist_fetch_build_egg(tmpdir): def test_dist__get_unpatched_deprecated(): pytest.warns(DistDeprecationWarning, _get_unpatched, [""]) + +def __read_test_cases(): + # Metadata version 1.0 + base_attrs = { + "name": "package", + "version": "0.0.1", + "author": "Foo Bar", + "author_email": "foo@bar.net", + "long_description": "Long\ndescription", + "description": "Short description", + "keywords": ["one", "two"] + } + + def merge_dicts(d1, d2): + d1 = d1.copy() + d1.update(d2) + + return d1 + + test_cases = [ + ('Metadata version 1.0', base_attrs.copy()), + ('Metadata version 1.1: Provides', merge_dicts(base_attrs, { + 'provides': ['package'] + })), + ('Metadata version 1.1: Obsoletes', merge_dicts(base_attrs, { + 'obsoletes': ['foo'] + })), + ('Metadata version 1.1: Classifiers', merge_dicts(base_attrs, { + 'classifiers': [ + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.7', + 'License :: OSI Approved :: MIT License' + ]})), + ('Metadata version 1.1: Download URL', merge_dicts(base_attrs, { + 'download_url': 'https://example.com' + })), + ('Metadata Version 1.2: Requires-Python', merge_dicts(base_attrs, { + 'python_requires': '>=3.7' + })), + pytest.param('Metadata Version 1.2: Project-Url', + merge_dicts(base_attrs, { + 'project_urls': { + 'Foo': 'https://example.bar' + } + }), marks=pytest.mark.xfail( + reason="Issue #1578: project_urls not read" + )), + ('Metadata Version 2.1: Long Description Content Type', + merge_dicts(base_attrs, { + 'long_description_content_type': 'text/x-rst; charset=UTF-8' + })), + pytest.param('Metadata Version 2.1: Provides Extra', + merge_dicts(base_attrs, { + 'provides_extras': ['foo', 'bar'] + }), marks=pytest.mark.xfail(reason="provides_extras not read")), + ] + + return test_cases + + +@pytest.mark.parametrize('name,attrs', __read_test_cases()) +def test_read_metadata(name, attrs, tmpdir): + dist = Distribution(attrs) + metadata_out = dist.metadata + dist_class = metadata_out.__class__ + + # Write to PKG_INFO and then load into a new metadata object + fn = tmpdir.mkdir('pkg_info') + fn_s = str(fn) + + metadata_out.write_pkg_info(fn_s) + + metadata_in = dist_class() + with io.open(str(fn.join('PKG-INFO')), 'r', encoding='utf-8') as f: + metadata_in.read_pkg_file(f) + + tested_attrs = [ + ('name', dist_class.get_name), + ('version', dist_class.get_version), + ('metadata_version', dist_class.get_metadata_version), + ('provides', dist_class.get_provides), + ('description', dist_class.get_description), + ('download_url', dist_class.get_download_url), + ('keywords', dist_class.get_keywords), + ('platforms', dist_class.get_platforms), + ('obsoletes', dist_class.get_obsoletes), + ('requires', dist_class.get_requires), + ('classifiers', dist_class.get_classifiers), + ('project_urls', lambda s: getattr(s, 'project_urls', {})), + ('provides_extras', lambda s: getattr(s, 'provides_extras', set())), + ] + + for attr, getter in tested_attrs: + assert getter(metadata_in) == getter(metadata_out) + + def __maintainer_test_cases(): attrs = {"name": "package", "version": "1.0", -- cgit v1.2.1 From bef22678626f4e201ef1bb6c5bc753dd01e6bf5a Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Tue, 6 Nov 2018 11:51:42 -0500 Subject: Use an in-memory IO object instead of a temp file Rather than writing to a file in a temporary directory, we can write to and read from an in-memory buffer, now that the encoding functionality in write_pkg_file is fixed. --- setuptools/tests/test_dist.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 36605cea..a7f4452b 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -12,6 +12,7 @@ from .textwrap import DALS from .test_easy_install import make_nspkg_sdist import pytest +import six def test_dist_fetch_build_egg(tmpdir): @@ -120,20 +121,22 @@ def __read_test_cases(): @pytest.mark.parametrize('name,attrs', __read_test_cases()) -def test_read_metadata(name, attrs, tmpdir): +def test_read_metadata(name, attrs): dist = Distribution(attrs) metadata_out = dist.metadata dist_class = metadata_out.__class__ # Write to PKG_INFO and then load into a new metadata object - fn = tmpdir.mkdir('pkg_info') - fn_s = str(fn) + if six.PY2: + PKG_INFO = io.BytesIO() + else: + PKG_INFO = io.StringIO() - metadata_out.write_pkg_info(fn_s) + metadata_out.write_pkg_file(PKG_INFO) + PKG_INFO.seek(0) metadata_in = dist_class() - with io.open(str(fn.join('PKG-INFO')), 'r', encoding='utf-8') as f: - metadata_in.read_pkg_file(f) + metadata_in.read_pkg_file(PKG_INFO) tested_attrs = [ ('name', dist_class.get_name), -- cgit v1.2.1 From ac3cee396ff93f66afa86bc6e3aa3da3a2667514 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Mon, 12 Nov 2018 22:32:51 -0500 Subject: Fix issue with missing author metadata Prior to this patch, if the author or author_email were omitted from `setup`, a malformed `PKG-INFO` would be created. --- setuptools/tests/test_dist.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index a7f4452b..170d27ed 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -115,6 +115,20 @@ def __read_test_cases(): merge_dicts(base_attrs, { 'provides_extras': ['foo', 'bar'] }), marks=pytest.mark.xfail(reason="provides_extras not read")), + ('Missing author, missing author e-mail', + {'name': 'foo', 'version': '1.0.0'}), + ('Missing author', + {'name': 'foo', + 'version': '1.0.0', + 'author_email': 'snorri@sturluson.name'}), + ('Missing author e-mail', + {'name': 'foo', + 'version': '1.0.0', + 'author': 'Snorri Sturluson'}), + ('Missing author', + {'name': 'foo', + 'version': '1.0.0', + 'author': 'Snorri Sturluson'}), ] return test_cases @@ -141,6 +155,8 @@ def test_read_metadata(name, attrs): tested_attrs = [ ('name', dist_class.get_name), ('version', dist_class.get_version), + ('author', dist_class.get_contact), + ('author_email', dist_class.get_contact_email), ('metadata_version', dist_class.get_metadata_version), ('provides', dist_class.get_provides), ('description', dist_class.get_description), -- cgit v1.2.1 From ba7698287094f7274ae7cbabaf6baedc175ac213 Mon Sep 17 00:00:00 2001 From: Oleg Sharov Date: Tue, 13 Nov 2018 12:52:43 +0400 Subject: import internal version of six --- setuptools/tests/test_dist.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 170d27ed..cf830b43 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -7,13 +7,12 @@ from setuptools.dist import DistDeprecationWarning, _get_unpatched 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 import six from .textwrap import DALS from .test_easy_install import make_nspkg_sdist import pytest -import six - def test_dist_fetch_build_egg(tmpdir): """ -- cgit v1.2.1 From 5cd86987530892bfb01f68ad5f1a2b997a3d01e7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 26 Jan 2019 20:20:12 -0500 Subject: Feed the hobgoblins (delint). --- setuptools/tests/test_dist.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index cf830b43..390c3dfc 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -14,6 +14,7 @@ from .test_easy_install import make_nspkg_sdist import pytest + def test_dist_fetch_build_egg(tmpdir): """ Check multiple calls to `Distribution.fetch_build_egg` work as expected. @@ -90,30 +91,32 @@ def __read_test_cases(): 'classifiers': [ 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.7', - 'License :: OSI Approved :: MIT License' - ]})), + 'License :: OSI Approved :: MIT License', + ]})), ('Metadata version 1.1: Download URL', merge_dicts(base_attrs, { 'download_url': 'https://example.com' })), ('Metadata Version 1.2: Requires-Python', merge_dicts(base_attrs, { 'python_requires': '>=3.7' })), - pytest.param('Metadata Version 1.2: Project-Url', + pytest.param( + 'Metadata Version 1.2: Project-Url', merge_dicts(base_attrs, { 'project_urls': { 'Foo': 'https://example.bar' } }), marks=pytest.mark.xfail( reason="Issue #1578: project_urls not read" - )), + )), ('Metadata Version 2.1: Long Description Content Type', merge_dicts(base_attrs, { 'long_description_content_type': 'text/x-rst; charset=UTF-8' })), - pytest.param('Metadata Version 2.1: Provides Extra', + pytest.param( + 'Metadata Version 2.1: Provides Extra', merge_dicts(base_attrs, { 'provides_extras': ['foo', 'bar'] - }), marks=pytest.mark.xfail(reason="provides_extras not read")), + }), marks=pytest.mark.xfail(reason="provides_extras not read")), ('Missing author, missing author e-mail', {'name': 'foo', 'version': '1.0.0'}), ('Missing author', -- cgit v1.2.1 From 4a6b8ba7ced6bb841000a59bdef7f9879fb6578d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 17 Feb 2019 15:42:23 -0500 Subject: Add test capturing expectation that provides_extras are ordered. --- setuptools/tests/test_dist.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 390c3dfc..e349d068 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -263,3 +263,16 @@ def test_maintainer_author(name, attrs, tmpdir): else: line = '%s: %s' % (fkey, val) assert line in pkg_lines_set + + +def test_provides_extras_deterministic_order(): + attrs = dict(extras_require=dict( + a=['foo'], + b=['bar'], + )) + dist = Distribution(attrs) + assert dist.metadata.provides_extras == ['a', 'b'] + attrs['extras_require'] = dict( + reversed(list(attrs['extras_require'].items()))) + dist = Distribution(attrs) + assert dist.metadata.provides_extras == ['b', 'a'] -- cgit v1.2.1 From 7f7780e5b572d6fcacd63bf99389dd9f48c5345c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 17 Feb 2019 17:37:01 -0500 Subject: In tests, force deterministic ordering on extras_require so tests pass. --- setuptools/tests/test_dist.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index e349d068..0c0b9d66 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -3,6 +3,8 @@ from __future__ import unicode_literals import io +import collections + from setuptools.dist import DistDeprecationWarning, _get_unpatched from setuptools import Distribution from setuptools.extern.six.moves.urllib.request import pathname2url @@ -266,13 +268,13 @@ def test_maintainer_author(name, attrs, tmpdir): def test_provides_extras_deterministic_order(): - attrs = dict(extras_require=dict( - a=['foo'], - b=['bar'], - )) + extras = collections.OrderedDict() + extras['a'] = ['foo'] + extras['b'] = ['bar'] + attrs = dict(extras_require=extras) dist = Distribution(attrs) assert dist.metadata.provides_extras == ['a', 'b'] - attrs['extras_require'] = dict( + attrs['extras_require'] = collections.OrderedDict( reversed(list(attrs['extras_require'].items()))) dist = Distribution(attrs) assert dist.metadata.provides_extras == ['b', 'a'] -- cgit v1.2.1 From 8f848bd777278fc8dcb42dc45751cd8b95ec2a02 Mon Sep 17 00:00:00 2001 From: Daniel Himmelstein Date: Wed, 22 May 2019 17:45:44 -0400 Subject: improve `package_data` check Ensure the dictionary values are lists/tuples of strings. Fix #1459. --- setuptools/tests/test_dist.py | 53 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 390c3dfc..c771a19a 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -3,7 +3,13 @@ from __future__ import unicode_literals import io -from setuptools.dist import DistDeprecationWarning, _get_unpatched +import re +from distutils.errors import DistutilsSetupError +from setuptools.dist import ( + _get_unpatched, + check_package_data, + DistDeprecationWarning, +) from setuptools import Distribution from setuptools.extern.six.moves.urllib.request import pathname2url from setuptools.extern.six.moves.urllib_parse import urljoin @@ -263,3 +269,48 @@ def test_maintainer_author(name, attrs, tmpdir): else: line = '%s: %s' % (fkey, val) assert line in pkg_lines_set + + +CHECK_PACKAGE_DATA_TESTS = ( + # Valid. + ({ + '': ['*.txt', '*.rst'], + 'hello': ['*.msg'], + }, None), + # Not a dictionary. + (( + ('', ['*.txt', '*.rst']), + ('hello', ['*.msg']), + ), ( + "'package_data' must be a dictionary mapping package" + " names to lists of string wildcard patterns" + )), + # Invalid key type. + ({ + 400: ['*.txt', '*.rst'], + }, ( + "keys of 'package_data' dict must be strings (got 400)" + )), + # Invalid value type. + ({ + 'hello': str('*.msg'), + }, ( + "\"values of 'package_data' dict\" must be a list of strings (got '*.msg')" + )), + # Invalid value type (generators are single use) + ({ + 'hello': (x for x in "generator"), + }, ( + "\"values of 'package_data' dict\" must be a list of strings " + "(got Date: Sun, 19 Jan 2020 12:46:30 -0500 Subject: =?UTF-8?q?=F0=9F=91=B9=20Feed=20the=20hobgoblins=20(delint).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setuptools/tests/test_dist.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 36237f24..b93ef148 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -284,7 +284,7 @@ def test_provides_extras_deterministic_order(): dist = Distribution(attrs) assert dist.metadata.provides_extras == ['b', 'a'] - + CHECK_PACKAGE_DATA_TESTS = ( # Valid. ({ @@ -309,7 +309,8 @@ CHECK_PACKAGE_DATA_TESTS = ( ({ 'hello': str('*.msg'), }, ( - "\"values of 'package_data' dict\" must be a list of strings (got '*.msg')" + "\"values of 'package_data' dict\" " + "must be a list of strings (got '*.msg')" )), # Invalid value type (generators are single use) ({ @@ -321,10 +322,12 @@ CHECK_PACKAGE_DATA_TESTS = ( ) -@pytest.mark.parametrize('package_data, expected_message', CHECK_PACKAGE_DATA_TESTS) +@pytest.mark.parametrize( + 'package_data, expected_message', CHECK_PACKAGE_DATA_TESTS) def test_check_package_data(package_data, expected_message): if expected_message is None: assert check_package_data(None, 'package_data', package_data) is None else: - with pytest.raises(DistutilsSetupError, match=re.escape(expected_message)): + with pytest.raises( + DistutilsSetupError, match=re.escape(expected_message)): check_package_data(None, str('package_data'), package_data) -- cgit v1.2.1 From 7cd8b4966a6e7186ff45fe1f1c09a58f8a678113 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 19 Jan 2020 15:05:08 -0500 Subject: =?UTF-8?q?=F0=9F=91=B9=20Feed=20the=20hobgoblins=20(delint).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setuptools/tests/test_dist.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index b93ef148..6e8c45fd 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -61,7 +61,8 @@ def test_dist_fetch_build_egg(tmpdir): dist.fetch_build_egg(r) for r in reqs ] - assert [dist.key for dist in resolved_dists if dist] == reqs + # noqa below because on Python 2 it causes flakes + assert [dist.key for dist in resolved_dists if dist] == reqs # noqa def test_dist__get_unpatched_deprecated(): -- cgit v1.2.1 From b6076bee61984e6e05bf0d02e1daf09f0469e526 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 15 Mar 2020 21:14:59 -0400 Subject: Add test capturing use-case for normalized version. Ref #308. --- setuptools/tests/test_dist.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 6e8c45fd..26c271b1 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -139,6 +139,13 @@ def __read_test_cases(): {'name': 'foo', 'version': '1.0.0', 'author': 'Snorri Sturluson'}), + ( + 'Normalized version', + dict( + name='foo', + version='1.0.0a', + ), + ), ] return test_cases -- cgit v1.2.1 From b43c5b81b76d687b50b05f05155838c69919c42c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 15 Mar 2020 21:43:11 -0400 Subject: Remove superfluous test and re-organize tests for clarity. --- setuptools/tests/test_dist.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 6e8c45fd..97055d97 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -125,8 +125,6 @@ def __read_test_cases(): merge_dicts(base_attrs, { 'provides_extras': ['foo', 'bar'] }), marks=pytest.mark.xfail(reason="provides_extras not read")), - ('Missing author, missing author e-mail', - {'name': 'foo', 'version': '1.0.0'}), ('Missing author', {'name': 'foo', 'version': '1.0.0', @@ -135,10 +133,8 @@ def __read_test_cases(): {'name': 'foo', 'version': '1.0.0', 'author': 'Snorri Sturluson'}), - ('Missing author', - {'name': 'foo', - 'version': '1.0.0', - 'author': 'Snorri Sturluson'}), + ('Missing author and e-mail', + {'name': 'foo', 'version': '1.0.0'}), ] return test_cases -- cgit v1.2.1 From 0e1c968f36a5d6cf268fe3f1ffca9405bb99e20d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 15 Mar 2020 22:08:36 -0400 Subject: Trim up syntax on test cases, including removing hanging indents. --- setuptools/tests/test_dist.py | 110 +++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 56 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 97055d97..47c2de3e 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -70,71 +70,69 @@ def test_dist__get_unpatched_deprecated(): def __read_test_cases(): - # Metadata version 1.0 - base_attrs = { - "name": "package", - "version": "0.0.1", - "author": "Foo Bar", - "author_email": "foo@bar.net", - "long_description": "Long\ndescription", - "description": "Short description", - "keywords": ["one", "two"] - } - - def merge_dicts(d1, d2): - d1 = d1.copy() - d1.update(d2) - - return d1 + base = dict( + name="package", + version="0.0.1", + author="Foo Bar", + author_email="foo@bar.net", + long_description="Long\ndescription", + description="Short description", + keywords=["one", "two"], + ) + + def params(**update): + return dict(base, **update) test_cases = [ - ('Metadata version 1.0', base_attrs.copy()), - ('Metadata version 1.1: Provides', merge_dicts(base_attrs, { - 'provides': ['package'] - })), - ('Metadata version 1.1: Obsoletes', merge_dicts(base_attrs, { - 'obsoletes': ['foo'] - })), - ('Metadata version 1.1: Classifiers', merge_dicts(base_attrs, { - 'classifiers': [ + ('Metadata version 1.0', params()), + ('Metadata version 1.1: Provides', params( + provides=['package'], + )), + ('Metadata version 1.1: Obsoletes', params( + obsoletes=['foo'], + )), + ('Metadata version 1.1: Classifiers', params( + classifiers=[ 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.7', 'License :: OSI Approved :: MIT License', - ]})), - ('Metadata version 1.1: Download URL', merge_dicts(base_attrs, { - 'download_url': 'https://example.com' - })), - ('Metadata Version 1.2: Requires-Python', merge_dicts(base_attrs, { - 'python_requires': '>=3.7' - })), + ], + )), + ('Metadata version 1.1: Download URL', params( + download_url='https://example.com', + )), + ('Metadata Version 1.2: Requires-Python', params( + python_requires='>=3.7', + )), pytest.param( 'Metadata Version 1.2: Project-Url', - merge_dicts(base_attrs, { - 'project_urls': { - 'Foo': 'https://example.bar' - } - }), marks=pytest.mark.xfail( - reason="Issue #1578: project_urls not read" - )), - ('Metadata Version 2.1: Long Description Content Type', - merge_dicts(base_attrs, { - 'long_description_content_type': 'text/x-rst; charset=UTF-8' - })), + params(project_urls=dict(Foo='https://example.bar')), + marks=pytest.mark.xfail( + reason="Issue #1578: project_urls not read", + ), + ), + ('Metadata Version 2.1: Long Description Content Type', params( + long_description_content_type='text/x-rst; charset=UTF-8', + )), pytest.param( 'Metadata Version 2.1: Provides Extra', - merge_dicts(base_attrs, { - 'provides_extras': ['foo', 'bar'] - }), marks=pytest.mark.xfail(reason="provides_extras not read")), - ('Missing author', - {'name': 'foo', - 'version': '1.0.0', - 'author_email': 'snorri@sturluson.name'}), - ('Missing author e-mail', - {'name': 'foo', - 'version': '1.0.0', - 'author': 'Snorri Sturluson'}), - ('Missing author and e-mail', - {'name': 'foo', 'version': '1.0.0'}), + params(provides_extras=['foo', 'bar']), + marks=pytest.mark.xfail(reason="provides_extras not read"), + ), + ('Missing author', dict( + name='foo', + version='1.0.0', + author_email='snorri@sturluson.name', + )), + ('Missing author e-mail', dict( + name='foo', + version='1.0.0', + author='Snorri Sturluson', + )), + ('Missing author and e-mail', dict( + name='foo', + version='1.0.0', + )), ] return test_cases -- cgit v1.2.1 From b8c2ae517db14b03dfba263aa66707ca67ecee8f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 15 Mar 2020 22:22:04 -0400 Subject: Rely on partial now that pattern makes sense --- setuptools/tests/test_dist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 47c2de3e..a9837b16 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import io import collections import re +import functools from distutils.errors import DistutilsSetupError from setuptools.dist import ( _get_unpatched, @@ -80,8 +81,7 @@ def __read_test_cases(): keywords=["one", "two"], ) - def params(**update): - return dict(base, **update) + params = functools.partial(dict, base) test_cases = [ ('Metadata version 1.0', params()), -- cgit v1.2.1 From 8356ff3c6816d2a075098421252e096955d1fdbd Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 20 Mar 2020 21:43:22 -0400 Subject: Trim excess whitespace --- setuptools/tests/test_dist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index c531b440..531ea1b4 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -137,7 +137,7 @@ def __read_test_cases(): ('Bypass normalized version', dict( name='foo', version=sic('1.0.0a'), - )), + )), ] return test_cases -- cgit v1.2.1 From fb7ab81a3d080422687bad71f9ae9d36eeefbee2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 16 Aug 2020 00:29:24 -0400 Subject: Remove Python 2 compatibility --- setuptools/tests/test_dist.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 531ea1b4..cb47fb58 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -1,11 +1,9 @@ -# -*- coding: utf-8 -*- - -from __future__ import unicode_literals - import io import collections import re import functools +import urllib.request +import urllib.parse from distutils.errors import DistutilsSetupError from setuptools.dist import ( _get_unpatched, @@ -14,9 +12,6 @@ from setuptools.dist import ( ) from setuptools import sic 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 import six from .textwrap import DALS from .test_easy_install import make_nspkg_sdist @@ -29,7 +24,8 @@ def test_dist_fetch_build_egg(tmpdir): Check multiple calls to `Distribution.fetch_build_egg` work as expected. """ index = tmpdir.mkdir('index') - index_url = urljoin('file://', pathname2url(str(index))) + index_url = urllib.parse.urljoin( + 'file://', urllib.request.pathname2url(str(index))) def sdist_with_index(distname, version): dist_dir = index.mkdir(distname) @@ -63,8 +59,7 @@ def test_dist_fetch_build_egg(tmpdir): dist.fetch_build_egg(r) for r in reqs ] - # noqa below because on Python 2 it causes flakes - assert [dist.key for dist in resolved_dists if dist] == reqs # noqa + assert [dist.key for dist in resolved_dists if dist] == reqs def test_dist__get_unpatched_deprecated(): @@ -150,10 +145,7 @@ def test_read_metadata(name, attrs): dist_class = metadata_out.__class__ # Write to PKG_INFO and then load into a new metadata object - if six.PY2: - PKG_INFO = io.BytesIO() - else: - PKG_INFO = io.StringIO() + PKG_INFO = io.StringIO() metadata_out.write_pkg_file(PKG_INFO) -- cgit v1.2.1 From 20ced7533c2b737e9d99deacd97633f84b26567d Mon Sep 17 00:00:00 2001 From: Melissa Li Date: Sun, 28 Feb 2021 00:59:58 -0500 Subject: test check_specifier --- setuptools/tests/test_dist.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index cb47fb58..e4bba47b 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -9,6 +9,7 @@ from setuptools.dist import ( _get_unpatched, check_package_data, DistDeprecationWarning, + check_specifier, ) from setuptools import sic from setuptools import Distribution @@ -323,3 +324,15 @@ def test_check_package_data(package_data, expected_message): with pytest.raises( DistutilsSetupError, match=re.escape(expected_message)): check_package_data(None, str('package_data'), package_data) + + +def test_check_specifier(): + # valid specifier value + attrs = {'name': 'foo', 'python_requires': '>=3.0, !=3.1'} + dist = Distribution(attrs) + check_specifier(dist, attrs, attrs['python_requires']) + + # invalid specifier value + attrs = {'name': 'foo', 'python_requires': ['>=3.0', '!=3.1']} + with pytest.raises(DistutilsSetupError): + dist = Distribution(attrs) -- cgit v1.2.1 From c18ed8706d759e11d7bb7e9070a1897ee2f1e979 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 10 Apr 2021 11:30:10 +0200 Subject: Add rfc822_unescape --- setuptools/tests/test_dist.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index e4bba47b..dcec1734 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -10,6 +10,8 @@ from setuptools.dist import ( check_package_data, DistDeprecationWarning, check_specifier, + rfc822_escape, + rfc822_unescape, ) from setuptools import sic from setuptools import Distribution @@ -85,6 +87,9 @@ def __read_test_cases(): ('Metadata version 1.1: Provides', params( provides=['package'], )), + ('Metadata Version 1.0: Short long description', params( + long_description='Short long description', + )), ('Metadata version 1.1: Obsoletes', params( obsoletes=['foo'], )), @@ -162,6 +167,7 @@ def test_read_metadata(name, attrs): ('metadata_version', dist_class.get_metadata_version), ('provides', dist_class.get_provides), ('description', dist_class.get_description), + ('long_description', dist_class.get_long_description), ('download_url', dist_class.get_download_url), ('keywords', dist_class.get_keywords), ('platforms', dist_class.get_platforms), @@ -336,3 +342,37 @@ def test_check_specifier(): attrs = {'name': 'foo', 'python_requires': ['>=3.0', '!=3.1']} with pytest.raises(DistutilsSetupError): dist = Distribution(attrs) + + +@pytest.mark.parametrize( + 'content, result', + ( + pytest.param( + "Just a single line", + None, + id="single_line", + ), + pytest.param( + "Multiline\nText\nwithout\nextra indents\n", + None, + id="multiline", + ), + pytest.param( + "Multiline\n With\n\nadditional\n indentation", + None, + id="multiline_with_indentation", + ), + pytest.param( + " Leading whitespace", + "Leading whitespace", + id="remove_leading_whitespace", + ), + pytest.param( + " Leading whitespace\nIn\n Multiline comment", + "Leading whitespace\nIn\n Multiline comment", + id="remove_leading_whitespace_multiline", + ), + ) +) +def test_rfc822_unescape(content, result): + assert (result or content) == rfc822_unescape(rfc822_escape(content)) -- cgit v1.2.1 From c36033859ec2f7d9034a93c363ffc858ffbae172 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 15 Apr 2021 22:32:45 +0200 Subject: Add escaping to license field --- setuptools/tests/test_dist.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index dcec1734..e09ed4cb 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -116,6 +116,10 @@ def __read_test_cases(): ('Metadata Version 2.1: Long Description Content Type', params( long_description_content_type='text/x-rst; charset=UTF-8', )), + ('License', params(license='MIT', )), + ('License multiline', params( + license='This is a long license \nover multiple lines', + )), pytest.param( 'Metadata Version 2.1: Provides Extra', params(provides_extras=['foo', 'bar']), -- cgit v1.2.1 From 417b02b79d8b29c6af85cbaedcab05c47c159e30 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 16 Apr 2021 14:18:43 +0200 Subject: Always use latest mv version for PKG-INFO --- setuptools/tests/test_dist.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index dcec1734..50464e29 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -84,15 +84,9 @@ def __read_test_cases(): test_cases = [ ('Metadata version 1.0', params()), - ('Metadata version 1.1: Provides', params( - provides=['package'], - )), ('Metadata Version 1.0: Short long description', params( long_description='Short long description', )), - ('Metadata version 1.1: Obsoletes', params( - obsoletes=['foo'], - )), ('Metadata version 1.1: Classifiers', params( classifiers=[ 'Programming Language :: Python :: 3', -- cgit v1.2.1 From 34c31ebe437edf9d6d4ee5010461668156793569 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 9 May 2021 20:16:37 +0200 Subject: Changes after rebase --- setuptools/tests/test_dist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_dist.py') diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 6378caef..c4279f0b 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -251,8 +251,8 @@ def test_maintainer_author(name, attrs, tmpdir): with io.open(str(fn.join('PKG-INFO')), 'r', encoding='utf-8') as f: raw_pkg_lines = f.readlines() - # Drop blank lines - pkg_lines = list(filter(None, raw_pkg_lines)) + # Drop blank lines and strip lines from default description + pkg_lines = list(filter(None, raw_pkg_lines[:-2])) pkg_lines_set = set(pkg_lines) -- cgit v1.2.1