summaryrefslogtreecommitdiff
path: root/setuptools/tests/test_config.py
diff options
context:
space:
mode:
authorIan Wienand <iwienand@redhat.com>2018-04-30 19:08:58 +1000
committerIan Wienand <iwienand@redhat.com>2018-05-17 07:22:25 +1000
commit07cd2e4e716264fd51aededcb77cefe37aafb25a (patch)
tree08c8395e42ab13e3d66ea5f903840993909aefb6 /setuptools/tests/test_config.py
parent1252d1b3b34261acd6c8051c4fe97f206a7118b7 (diff)
downloadpython-setuptools-git-07cd2e4e716264fd51aededcb77cefe37aafb25a.tar.gz
Allow setting long_description_content_type externally
Some tools, such as PBR, might want to set long_description_content_type during the parent object's Distribution.__init__() call (during distutils setup_keywords entry points). However, that field is currently unconditionally overwritten after these calls, erasing the value. We would rather not duplicate the existing method of copying into dist.metadata as done with project_urls. This preserves the fields within Distribution.metadata described by self._DISTUTIULS_UNUPPORTED_METADATA, or otherwise takes it from arguments. A test case that simulates setting the long description and overriding the arguments is added.
Diffstat (limited to 'setuptools/tests/test_config.py')
-rw-r--r--setuptools/tests/test_config.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py
index 17ac09c8..91471306 100644
--- a/setuptools/tests/test_config.py
+++ b/setuptools/tests/test_config.py
@@ -1,7 +1,8 @@
import contextlib
import pytest
from distutils.errors import DistutilsOptionError, DistutilsFileError
-from setuptools.dist import Distribution
+from mock import patch
+from setuptools.dist import Distribution, _Distribution
from setuptools.config import ConfigHandler, read_configuration
@@ -598,3 +599,43 @@ class TestOptions:
with get_dist(tmpdir) as dist:
assert dist.entry_points == expected
+
+saved_dist_init = _Distribution.__init__
+class TestExternalSetters:
+ # During creation of the setuptools Distribution() object, we call
+ # the init of the parent distutils Distribution object via
+ # _Distribution.__init__ ().
+ #
+ # It's possible distutils calls out to various keyword
+ # implementations (i.e. distutils.setup_keywords entry points)
+ # that may set a range of variables.
+ #
+ # This wraps distutil's Distribution.__init__ and simulates
+ # pbr or something else setting these values.
+ def _fake_distribution_init(self, dist, attrs):
+ saved_dist_init(dist, attrs)
+ # see self._DISTUTUILS_UNSUPPORTED_METADATA
+ setattr(dist.metadata, 'long_description_content_type',
+ 'text/something')
+ # Test overwrite setup() args
+ setattr(dist.metadata, 'project_urls', {
+ 'Link One': 'https://example.com/one/',
+ 'Link Two': 'https://example.com/two/',
+ })
+ return None
+
+ @patch.object(_Distribution, '__init__', autospec=True)
+ def test_external_setters(self, mock_parent_init, tmpdir):
+ mock_parent_init.side_effect = self._fake_distribution_init
+
+ dist = Distribution(attrs={
+ 'project_urls': {
+ 'will_be': 'ignored'
+ }
+ })
+
+ assert dist.metadata.long_description_content_type == 'text/something'
+ assert dist.metadata.project_urls == {
+ 'Link One': 'https://example.com/one/',
+ 'Link Two': 'https://example.com/two/',
+ }