summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests
diff options
context:
space:
mode:
authorNeil Schemenauer <nas-github@arctrix.com>2017-12-05 02:58:12 (GMT)
committerGitHub <noreply@github.com>2017-12-05 02:58:12 (GMT)
commit8837dd092fe5ad5184889104e8036811ed839f98 (patch)
tree70b98ec438853e992d10338d7ff56da7d7a0b0d3 /Lib/distutils/tests
parent9625bf520e08828e36bc3b1d043af679eb5f993d (diff)
downloadcpython-8837dd092fe5ad5184889104e8036811ed839f98.zip
cpython-8837dd092fe5ad5184889104e8036811ed839f98.tar.gz
cpython-8837dd092fe5ad5184889104e8036811ed839f98.tar.bz2
bpo-19610: Warn if distutils is provided something other than a list to some fields (#4685)
* Rather than raise TypeError, warn and call list() on the value. * Fix tests, revise NEWS and whatsnew text. * Revise documentation, a string is okay as well. * Ensure 'requires' and 'obsoletes' are real lists. * Test that requires and obsoletes are turned to lists.
Diffstat (limited to 'Lib/distutils/tests')
-rw-r--r--Lib/distutils/tests/test_dist.py48
1 files changed, 38 insertions, 10 deletions
diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py
index 50b456e..0a19f0f 100644
--- a/Lib/distutils/tests/test_dist.py
+++ b/Lib/distutils/tests/test_dist.py
@@ -11,7 +11,9 @@ from unittest import mock
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
@@ -319,6 +321,13 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
"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",
@@ -341,6 +350,12 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
"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']}
@@ -353,9 +368,14 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
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 captured_stderr() as error:
+ d = Distribution(attrs)
+ # 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']))
def test_keywords(self):
attrs = {'name': 'Monty', 'version': '1.0',
@@ -367,9 +387,13 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
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 captured_stderr() as error:
+ d = Distribution(attrs)
+ # 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']))
def test_platforms(self):
attrs = {'name': 'Monty', 'version': '1.0',
@@ -381,9 +405,13 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
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 captured_stderr() as error:
+ d = Distribution(attrs)
+ # 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']))
def test_download_url(self):
attrs = {'name': 'Boa', 'version': '3.0',