From 2459267c206311b46bcf22fd03b791219cd7c2ee Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sat, 2 Dec 2017 20:36:22 -0800 Subject: [PATCH 01/11] Import warnings unconditionally. The try/except was for Python 2.0. --- Lib/distutils/dist.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index 78c29ede6c2c4e..054af8c219b232 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -9,10 +9,7 @@ import re from email import message_from_file -try: - import warnings -except ImportError: - warnings = None +import warnings from distutils.errors import * from distutils.fancy_getopt import FancyGetopt, translate_longopt @@ -241,10 +238,7 @@ def __init__(self, attrs=None): attrs['license'] = attrs['licence'] del attrs['licence'] msg = "'licence' distribution option is deprecated; use 'license'" - if warnings is not None: - warnings.warn(msg) - else: - sys.stderr.write(msg + "\n") + warnings.warn(msg) # Now work on the rest of the attributes. Any attribute that's # not already defined is invalid! @@ -257,10 +251,7 @@ def __init__(self, attrs=None): setattr(self, key, val) else: msg = "Unknown distribution option: %s" % repr(key) - if warnings is not None: - warnings.warn(msg) - else: - sys.stderr.write(msg + "\n") + warnings.warn(msg) # no-user-cfg is handled before other command line args # because other args override the config files, and this From a440128460de904de6cf37f90b7682ce3514fa8f Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sat, 2 Dec 2017 20:50:33 -0800 Subject: [PATCH 02/11] Rather than raise TypeError, warn and call list() on the value. --- Lib/distutils/dist.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index 054af8c219b232..6566e51a8485f4 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -1186,7 +1186,8 @@ def set_keywords(self, value): # a string. if not isinstance(value, (list, str)): msg = "'keywords' should be a 'list', not %r" - raise TypeError(msg % type(value).__name__) + warnings.warn(msg % type(value).__name__, RuntimeWarning, 2) + value = list(value) self.keywords = value def get_platforms(self): @@ -1199,7 +1200,8 @@ def set_platforms(self, value): # a string. if not isinstance(value, (list, str)): msg = "'platforms' should be a 'list', not %r" - raise TypeError(msg % type(value).__name__) + warnings.warn(msg % type(value).__name__, RuntimeWarning, 2) + value = list(value) self.platforms = value def get_classifiers(self): @@ -1208,7 +1210,8 @@ def get_classifiers(self): def set_classifiers(self, value): if not isinstance(value, list): msg = "'classifiers' should be a 'list', not %r" - raise TypeError(msg % type(value).__name__) + warnings.warn(msg % type(value).__name__, RuntimeWarning, 2) + value = list(value) self.classifiers = value def get_download_url(self): From 4a7bfe3f459a8d1f678368bc350b1e8f8582f747 Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sat, 2 Dec 2017 20:50:58 -0800 Subject: [PATCH 03/11] Fix tests, revise NEWS and whatsnew text. --- Doc/whatsnew/3.7.rst | 8 ++++---- Lib/distutils/tests/test_dist.py | 19 +++++++++++++------ .../2017-11-23-16-15-55.bpo-19610.Dlca2P.rst | 7 +++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 3d23aa773d77c7..4df0413dcbd3c9 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -298,10 +298,10 @@ README.rst is now included in the list of distutils standard READMEs and therefore included in source distributions. (Contributed by Ryan Gonzalez in :issue:`11913`.) -:class:`distutils.core.setup` now raises a :exc:`TypeError` if -``classifiers``, ``keywords`` and ``platforms`` fields are not specified -as a list. However, to minimize backwards incompatibility concerns, -``keywords`` and ``platforms`` fields still accept a comma separated string. +:class:`distutils.core.setup` now warns if the ``classifiers``, ``keywords`` +and ``platforms`` fields are not specified as a list. However, to minimize +backwards incompatibility concerns, ``keywords`` and ``platforms`` fields +still accept a comma separated string. (Contributed by Berker Peksag in :issue:`19610`.) http.client diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py index 50b456ec9471c7..b03032058599a6 100644 --- a/Lib/distutils/tests/test_dist.py +++ b/Lib/distutils/tests/test_dist.py @@ -354,8 +354,11 @@ def test_classifier_invalid_type(self): attrs = {'name': 'Boa', 'version': '3.0', 'classifiers': ('Programming Language :: Python :: 3',)} msg = "'classifiers' should be a 'list', not 'tuple'" - with self.assertRaises(TypeError, msg=msg): - Distribution(attrs) + with self.assertWarns(RuntimeWarning) as warns: + d = Distribution(attrs) + self.assertIsInstance(d.metadata.classifiers, list) + self.assertEqual(d.metadata.classifiers, + list(attrs['classifiers'])) def test_keywords(self): attrs = {'name': 'Monty', 'version': '1.0', @@ -368,8 +371,10 @@ def test_keywords_invalid_type(self): attrs = {'name': 'Monty', 'version': '1.0', 'keywords': ('spam', 'eggs', 'life of brian')} msg = "'keywords' should be a 'list', not 'tuple'" - with self.assertRaises(TypeError, msg=msg): - Distribution(attrs) + with self.assertWarns(RuntimeWarning) as warns: + d = Distribution(attrs) + self.assertIsInstance(d.metadata.keywords, list) + self.assertEqual(d.metadata.keywords, list(attrs['keywords'])) def test_platforms(self): attrs = {'name': 'Monty', 'version': '1.0', @@ -382,8 +387,10 @@ def test_platforms_invalid_types(self): attrs = {'name': 'Monty', 'version': '1.0', 'platforms': ('GNU/Linux', 'Some Evil Platform')} msg = "'platforms' should be a 'list', not 'tuple'" - with self.assertRaises(TypeError, msg=msg): - Distribution(attrs) + with self.assertWarns(RuntimeWarning) as warns: + d = Distribution(attrs) + self.assertIsInstance(d.metadata.platforms, list) + self.assertEqual(d.metadata.platforms, list(attrs['platforms'])) def test_download_url(self): attrs = {'name': 'Boa', 'version': '3.0', diff --git a/Misc/NEWS.d/next/Library/2017-11-23-16-15-55.bpo-19610.Dlca2P.rst b/Misc/NEWS.d/next/Library/2017-11-23-16-15-55.bpo-19610.Dlca2P.rst index 5ea87a45722c0e..17273ae6027d39 100644 --- a/Misc/NEWS.d/next/Library/2017-11-23-16-15-55.bpo-19610.Dlca2P.rst +++ b/Misc/NEWS.d/next/Library/2017-11-23-16-15-55.bpo-19610.Dlca2P.rst @@ -1,5 +1,4 @@ -``setup()`` now raises :exc:`TypeError` for invalid types. +``setup()`` now warns about invalid types for some fields. -The ``distutils.dist.Distribution`` class now explicitly raises an exception -when ``classifiers``, ``keywords`` and ``platforms`` fields are not -specified as a list. +The ``distutils.dist.Distribution`` class now warns when ``classifiers``, +``keywords`` and ``platforms`` fields are not specified as a list. From 8024d4747ec979435d8c6bd7fd07c329c8420275 Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sun, 3 Dec 2017 09:36:40 -0800 Subject: [PATCH 04/11] Improve tests using assertWarnsRegex(). --- Lib/distutils/tests/test_dist.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py index b03032058599a6..b76f74c7c3b590 100644 --- a/Lib/distutils/tests/test_dist.py +++ b/Lib/distutils/tests/test_dist.py @@ -354,11 +354,11 @@ def test_classifier_invalid_type(self): attrs = {'name': 'Boa', 'version': '3.0', 'classifiers': ('Programming Language :: Python :: 3',)} msg = "'classifiers' should be a 'list', not 'tuple'" - with self.assertWarns(RuntimeWarning) as warns: + with self.assertWarnsRegex(RuntimeWarning, msg): d = Distribution(attrs) - self.assertIsInstance(d.metadata.classifiers, list) - self.assertEqual(d.metadata.classifiers, - list(attrs['classifiers'])) + self.assertIsInstance(d.metadata.classifiers, list) + self.assertEqual(d.metadata.classifiers, + list(attrs['classifiers'])) def test_keywords(self): attrs = {'name': 'Monty', 'version': '1.0', @@ -371,10 +371,10 @@ def test_keywords_invalid_type(self): attrs = {'name': 'Monty', 'version': '1.0', 'keywords': ('spam', 'eggs', 'life of brian')} msg = "'keywords' should be a 'list', not 'tuple'" - with self.assertWarns(RuntimeWarning) as warns: + with self.assertWarnsRegex(RuntimeWarning, msg): d = Distribution(attrs) - self.assertIsInstance(d.metadata.keywords, list) - self.assertEqual(d.metadata.keywords, list(attrs['keywords'])) + self.assertIsInstance(d.metadata.keywords, list) + self.assertEqual(d.metadata.keywords, list(attrs['keywords'])) def test_platforms(self): attrs = {'name': 'Monty', 'version': '1.0', @@ -387,10 +387,10 @@ def test_platforms_invalid_types(self): attrs = {'name': 'Monty', 'version': '1.0', 'platforms': ('GNU/Linux', 'Some Evil Platform')} msg = "'platforms' should be a 'list', not 'tuple'" - with self.assertWarns(RuntimeWarning) as warns: + with self.assertWarnsRegex(RuntimeWarning, msg): d = Distribution(attrs) - self.assertIsInstance(d.metadata.platforms, list) - self.assertEqual(d.metadata.platforms, list(attrs['platforms'])) + self.assertIsInstance(d.metadata.platforms, list) + self.assertEqual(d.metadata.platforms, list(attrs['platforms'])) def test_download_url(self): attrs = {'name': 'Boa', 'version': '3.0', From 8a4c09ede9df6e969e209cc32904fce85751b75b Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sun, 3 Dec 2017 09:42:41 -0800 Subject: [PATCH 05/11] Revise documentation, a string is okay as well. --- Doc/distutils/apiref.rst | 6 +++--- Doc/whatsnew/3.7.rst | 4 +--- .../next/Library/2017-11-23-16-15-55.bpo-19610.Dlca2P.rst | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst index ced8837d37363f..9fce46ad266962 100644 --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -286,9 +286,9 @@ the full reference. Distribution constructor. :func:`setup` creates a Distribution instance. .. versionchanged:: 3.7 - :class:`~distutils.core.Distribution` now raises a :exc:`TypeError` if - ``classifiers``, ``keywords`` and ``platforms`` fields are not specified - as a list. + :class:`~distutils.core.Distribution` now warns if ``classifiers``, + ``keywords`` and ``platforms`` fields are not specified as a list or + a string. .. class:: Command diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 4df0413dcbd3c9..9363730bf1fd64 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -299,9 +299,7 @@ therefore included in source distributions. (Contributed by Ryan Gonzalez in :issue:`11913`.) :class:`distutils.core.setup` now warns if the ``classifiers``, ``keywords`` -and ``platforms`` fields are not specified as a list. However, to minimize -backwards incompatibility concerns, ``keywords`` and ``platforms`` fields -still accept a comma separated string. +and ``platforms`` fields are not specified as a list or a string. (Contributed by Berker Peksag in :issue:`19610`.) http.client diff --git a/Misc/NEWS.d/next/Library/2017-11-23-16-15-55.bpo-19610.Dlca2P.rst b/Misc/NEWS.d/next/Library/2017-11-23-16-15-55.bpo-19610.Dlca2P.rst index 17273ae6027d39..514740b433f38d 100644 --- a/Misc/NEWS.d/next/Library/2017-11-23-16-15-55.bpo-19610.Dlca2P.rst +++ b/Misc/NEWS.d/next/Library/2017-11-23-16-15-55.bpo-19610.Dlca2P.rst @@ -1,4 +1,4 @@ ``setup()`` now warns about invalid types for some fields. The ``distutils.dist.Distribution`` class now warns when ``classifiers``, -``keywords`` and ``platforms`` fields are not specified as a list. +``keywords`` and ``platforms`` fields are not specified as a list or a string. From eeecfdd1914d9cdb23a9d1c3c1e88748e7f43df8 Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sun, 3 Dec 2017 12:27:26 -0800 Subject: [PATCH 06/11] Revert change to try/except for warnings import. --- Lib/distutils/dist.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index 6566e51a8485f4..b14761fabc5e15 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -9,7 +9,10 @@ import re from email import message_from_file -import warnings +try: + import warnings +except ImportError: + warnings = None from distutils.errors import * from distutils.fancy_getopt import FancyGetopt, translate_longopt @@ -238,7 +241,10 @@ def __init__(self, attrs=None): attrs['license'] = attrs['licence'] del attrs['licence'] msg = "'licence' distribution option is deprecated; use 'license'" - warnings.warn(msg) + if warnings is not None: + warnings.warn(msg) + else: + sys.stderr.write(msg + "\n") # Now work on the rest of the attributes. Any attribute that's # not already defined is invalid! From 76a1cecef2923543e903b7e7be6c19dc803824cd Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sun, 3 Dec 2017 12:28:11 -0800 Subject: [PATCH 07/11] Use distutils.log rather than warnings module to warn. Introduce a helper function _ensure_list() that reduces code duplication. --- Lib/distutils/dist.py | 38 +++++++++++++------------------- Lib/distutils/tests/test_dist.py | 18 +++++++++------ 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index b14761fabc5e15..d03c7de3b0caf9 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -26,6 +26,18 @@ # to look for a Python module named after the command. command_re = re.compile(r'^[a-zA-Z]([a-zA-Z0-9_]*)$') +def _ensure_list(value, fieldname): + if isinstance(value, str): + # a string containing comma separated values is okay. It will + # be converted to a list by Distribution.finalize_options(). + pass + elif not isinstance(value, list): + # passing a tuple or an iterator perhaps, warn and convert + typename = type(value).__name__ + msg = f"Warning: '{fieldname}' should be a list, got type '{typename}'" + log.log(log.WARN, msg) + value = list(value) + return value class Distribution: """The core of the Distutils. Most of the work hiding behind 'setup' @@ -1186,39 +1198,19 @@ def get_keywords(self): return self.keywords or [] def set_keywords(self, value): - # If 'keywords' is a string, it will be converted to a list - # by Distribution.finalize_options(). To maintain backwards - # compatibility, do not raise an exception if 'keywords' is - # a string. - if not isinstance(value, (list, str)): - msg = "'keywords' should be a 'list', not %r" - warnings.warn(msg % type(value).__name__, RuntimeWarning, 2) - value = list(value) - self.keywords = value + self.keywords = _ensure_list(value, 'keywords') def get_platforms(self): return self.platforms or ["UNKNOWN"] def set_platforms(self, value): - # If 'platforms' is a string, it will be converted to a list - # by Distribution.finalize_options(). To maintain backwards - # compatibility, do not raise an exception if 'platforms' is - # a string. - if not isinstance(value, (list, str)): - msg = "'platforms' should be a 'list', not %r" - warnings.warn(msg % type(value).__name__, RuntimeWarning, 2) - value = list(value) - self.platforms = value + self.platforms = _ensure_list(value, 'platforms') def get_classifiers(self): return self.classifiers or [] def set_classifiers(self, value): - if not isinstance(value, list): - msg = "'classifiers' should be a 'list', not %r" - warnings.warn(msg % type(value).__name__, RuntimeWarning, 2) - value = list(value) - self.classifiers = value + self.classifiers = _ensure_list(value, 'classifiers') def get_download_url(self): return self.download_url or "UNKNOWN" diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py index b76f74c7c3b590..70a92b438afb17 100644 --- a/Lib/distutils/tests/test_dist.py +++ b/Lib/distutils/tests/test_dist.py @@ -11,7 +11,8 @@ from distutils.dist import Distribution, fix_help_options, DistributionMetadata from distutils.cmd import Command -from test.support import TESTFN, captured_stdout, run_unittest +from test.support import TESTFN, captured_stdout, captured_stderr, \ + run_unittest from distutils.tests import support from distutils import log @@ -353,9 +354,10 @@ def test_classifier(self): def test_classifier_invalid_type(self): attrs = {'name': 'Boa', 'version': '3.0', 'classifiers': ('Programming Language :: Python :: 3',)} - msg = "'classifiers' should be a 'list', not 'tuple'" - with self.assertWarnsRegex(RuntimeWarning, msg): + msg = "should be a list" + with captured_stderr() as error: d = Distribution(attrs) + self.assertIn(msg, error.getvalue()) self.assertIsInstance(d.metadata.classifiers, list) self.assertEqual(d.metadata.classifiers, list(attrs['classifiers'])) @@ -370,9 +372,10 @@ def test_keywords(self): def test_keywords_invalid_type(self): attrs = {'name': 'Monty', 'version': '1.0', 'keywords': ('spam', 'eggs', 'life of brian')} - msg = "'keywords' should be a 'list', not 'tuple'" - with self.assertWarnsRegex(RuntimeWarning, msg): + msg = "should be a list" + with captured_stderr() as error: d = Distribution(attrs) + self.assertIn(msg, error.getvalue()) self.assertIsInstance(d.metadata.keywords, list) self.assertEqual(d.metadata.keywords, list(attrs['keywords'])) @@ -386,9 +389,10 @@ def test_platforms(self): def test_platforms_invalid_types(self): attrs = {'name': 'Monty', 'version': '1.0', 'platforms': ('GNU/Linux', 'Some Evil Platform')} - msg = "'platforms' should be a 'list', not 'tuple'" - with self.assertWarnsRegex(RuntimeWarning, msg): + msg = "should be a list" + with captured_stderr() as error: d = Distribution(attrs) + self.assertIn(msg, error.getvalue()) self.assertIsInstance(d.metadata.platforms, list) self.assertEqual(d.metadata.platforms, list(attrs['platforms'])) From d27b625a40e408aebb26e21d6687cc7e809c4e1f Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Sun, 3 Dec 2017 12:35:56 -0800 Subject: [PATCH 08/11] Ensure 'requires' and 'obsoletes' are real lists. --- Lib/distutils/dist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index d03c7de3b0caf9..ad5860e55657e7 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -1223,7 +1223,7 @@ def set_requires(self, value): import distutils.versionpredicate for v in value: distutils.versionpredicate.VersionPredicate(v) - self.requires = value + self.requires = list(value) def get_provides(self): return self.provides or [] @@ -1242,7 +1242,7 @@ def set_obsoletes(self, value): import distutils.versionpredicate for v in value: distutils.versionpredicate.VersionPredicate(v) - self.obsoletes = value + self.obsoletes = list(value) def fix_help_options(options): """Convert a 4-tuple 'help_options' list as found in various command From 1f79d9f1196d2eabe270d06d4fc36779cacd94f8 Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Mon, 4 Dec 2017 18:34:54 -0800 Subject: [PATCH 09/11] style nits --- Lib/distutils/dist.py | 2 ++ Lib/distutils/tests/test_dist.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py index ad5860e55657e7..6cf0a0d6632dc7 100644 --- a/Lib/distutils/dist.py +++ b/Lib/distutils/dist.py @@ -26,6 +26,7 @@ # to look for a Python module named after the command. command_re = re.compile(r'^[a-zA-Z]([a-zA-Z0-9_]*)$') + def _ensure_list(value, fieldname): if isinstance(value, str): # a string containing comma separated values is okay. It will @@ -39,6 +40,7 @@ def _ensure_list(value, fieldname): value = list(value) return value + class Distribution: """The core of the Distutils. Most of the work hiding behind 'setup' is really done within a Distribution instance, which farms the work out diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py index 70a92b438afb17..1e0d9da5afac38 100644 --- a/Lib/distutils/tests/test_dist.py +++ b/Lib/distutils/tests/test_dist.py @@ -11,8 +11,9 @@ from distutils.dist import Distribution, fix_help_options, DistributionMetadata from distutils.cmd import Command -from test.support import TESTFN, captured_stdout, captured_stderr, \ - run_unittest +from test.support import ( + TESTFN, captured_stdout, captured_stderr, run_unittest +) from distutils.tests import support from distutils import log From e31669a2540fc0806ebd21c142492dbf4ca840df Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Mon, 4 Dec 2017 18:35:06 -0800 Subject: [PATCH 10/11] Test that requires and obsoletes are turned to lists. --- Lib/distutils/tests/test_dist.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py index 1e0d9da5afac38..2636b50fe36b93 100644 --- a/Lib/distutils/tests/test_dist.py +++ b/Lib/distutils/tests/test_dist.py @@ -321,6 +321,13 @@ def test_requires_illegal(self): "version": "1.0", "requires": ["my.pkg (splat)"]}) + def test_requires_to_list(self): + attrs = {"name": "package", + "requires": iter(["other"])} + dist = Distribution(attrs) + self.assertIsInstance(dist.metadata.requires, list) + + def test_obsoletes(self): attrs = {"name": "package", "version": "1.0", @@ -343,6 +350,12 @@ def test_obsoletes_illegal(self): "version": "1.0", "obsoletes": ["my.pkg (splat)"]}) + def test_obsoletes_to_list(self): + attrs = {"name": "package", + "obsoletes": iter(["other"])} + dist = Distribution(attrs) + self.assertIsInstance(dist.metadata.obsoletes, list) + def test_classifier(self): attrs = {'name': 'Boa', 'version': '3.0', 'classifiers': ['Programming Language :: Python :: 3']} From 67503b5fa2742a75f8fdeac3282ec7a09b88bb3c Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Mon, 4 Dec 2017 18:35:33 -0800 Subject: [PATCH 11/11] style nits --- Lib/distutils/tests/test_dist.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py index 2636b50fe36b93..0a19f0fb6274cb 100644 --- a/Lib/distutils/tests/test_dist.py +++ b/Lib/distutils/tests/test_dist.py @@ -368,10 +368,11 @@ def test_classifier(self): def test_classifier_invalid_type(self): attrs = {'name': 'Boa', 'version': '3.0', 'classifiers': ('Programming Language :: Python :: 3',)} - msg = "should be a list" with captured_stderr() as error: d = Distribution(attrs) - self.assertIn(msg, error.getvalue()) + # should have warning about passing a non-list + self.assertIn('should be a list', error.getvalue()) + # should be converted to a list self.assertIsInstance(d.metadata.classifiers, list) self.assertEqual(d.metadata.classifiers, list(attrs['classifiers'])) @@ -386,10 +387,11 @@ def test_keywords(self): def test_keywords_invalid_type(self): attrs = {'name': 'Monty', 'version': '1.0', 'keywords': ('spam', 'eggs', 'life of brian')} - msg = "should be a list" with captured_stderr() as error: d = Distribution(attrs) - self.assertIn(msg, error.getvalue()) + # should have warning about passing a non-list + self.assertIn('should be a list', error.getvalue()) + # should be converted to a list self.assertIsInstance(d.metadata.keywords, list) self.assertEqual(d.metadata.keywords, list(attrs['keywords'])) @@ -403,10 +405,11 @@ def test_platforms(self): def test_platforms_invalid_types(self): attrs = {'name': 'Monty', 'version': '1.0', 'platforms': ('GNU/Linux', 'Some Evil Platform')} - msg = "should be a list" with captured_stderr() as error: d = Distribution(attrs) - self.assertIn(msg, error.getvalue()) + # should have warning about passing a non-list + self.assertIn('should be a list', error.getvalue()) + # should be converted to a list self.assertIsInstance(d.metadata.platforms, list) self.assertEqual(d.metadata.platforms, list(attrs['platforms']))