mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-19610: setup() now raises TypeError for invalid types (GH-4519)
The Distribution class now explicitly raises an exception when 'classifiers', 'keywords' and 'platforms' fields are not specified as a list.
This commit is contained in:
parent
6a54c676e6
commit
dcaed6b2d9
6 changed files with 112 additions and 12 deletions
|
@ -195,6 +195,13 @@ class DistributionTestCase(support.LoggingSilencer,
|
|||
self.assertEqual(dist.metadata.platforms, ['one', 'two'])
|
||||
self.assertEqual(dist.metadata.keywords, ['one', 'two'])
|
||||
|
||||
attrs = {'keywords': 'foo bar',
|
||||
'platforms': 'foo bar'}
|
||||
dist = Distribution(attrs=attrs)
|
||||
dist.finalize_options()
|
||||
self.assertEqual(dist.metadata.platforms, ['foo bar'])
|
||||
self.assertEqual(dist.metadata.keywords, ['foo bar'])
|
||||
|
||||
def test_get_command_packages(self):
|
||||
dist = Distribution()
|
||||
self.assertEqual(dist.command_packages, None)
|
||||
|
@ -338,9 +345,46 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
|
|||
attrs = {'name': 'Boa', 'version': '3.0',
|
||||
'classifiers': ['Programming Language :: Python :: 3']}
|
||||
dist = Distribution(attrs)
|
||||
self.assertEqual(dist.get_classifiers(),
|
||||
['Programming Language :: Python :: 3'])
|
||||
meta = self.format_metadata(dist)
|
||||
self.assertIn('Metadata-Version: 1.1', meta)
|
||||
|
||||
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)
|
||||
|
||||
def test_keywords(self):
|
||||
attrs = {'name': 'Monty', 'version': '1.0',
|
||||
'keywords': ['spam', 'eggs', 'life of brian']}
|
||||
dist = Distribution(attrs)
|
||||
self.assertEqual(dist.get_keywords(),
|
||||
['spam', 'eggs', 'life of brian'])
|
||||
|
||||
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)
|
||||
|
||||
def test_platforms(self):
|
||||
attrs = {'name': 'Monty', 'version': '1.0',
|
||||
'platforms': ['GNU/Linux', 'Some Evil Platform']}
|
||||
dist = Distribution(attrs)
|
||||
self.assertEqual(dist.get_platforms(),
|
||||
['GNU/Linux', 'Some Evil Platform'])
|
||||
|
||||
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)
|
||||
|
||||
def test_download_url(self):
|
||||
attrs = {'name': 'Boa', 'version': '3.0',
|
||||
'download_url': 'http://example.org/boa'}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue