diff options
| author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-02-23 02:57:49 +0000 |
|---|---|---|
| committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-03-05 14:30:52 +0000 |
| commit | a4b474ecb7ca027ba06b351b254ee57725184ee3 (patch) | |
| tree | edefed763c2f5cbd64823be0ec384a3452fd829f /setuptools/tests/config | |
| parent | cf32acbcc180938cf665ba1dfa65243bb8e2277f (diff) | |
| download | python-setuptools-git-a4b474ecb7ca027ba06b351b254ee57725184ee3.tar.gz | |
Back-fill Description-Content-Type according to readme suffix
According to PEP 621, the backend should fill-in the content-type if the
`readme` field is passed as a string. The value is derived from the
extension of the file (an error should be raised when that is not
possible).
Previously all READMEs were wrongly assumed rst.
This error was reported in:
https://discuss.python.org/t/help-testing-experimental-features-in-setuptools/13821/4
Diffstat (limited to 'setuptools/tests/config')
| -rw-r--r-- | setuptools/tests/config/test_apply_pyprojecttoml.py | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/setuptools/tests/config/test_apply_pyprojecttoml.py b/setuptools/tests/config/test_apply_pyprojecttoml.py index 4d9c8c5f..5b5a8dfa 100644 --- a/setuptools/tests/config/test_apply_pyprojecttoml.py +++ b/setuptools/tests/config/test_apply_pyprojecttoml.py @@ -129,18 +129,53 @@ def main_tomatoes(): pass """ -def test_pep621_example(tmp_path): - """Make sure the example in PEP 621 works""" +def _pep621_example_project(tmp_path, readme="README.rst"): pyproject = tmp_path / "pyproject.toml" - pyproject.write_text(PEP621_EXAMPLE) + text = PEP621_EXAMPLE + replacements = {'readme = "README.rst"': f'readme = "{readme}"'} + for orig, subst in replacements.items(): + text = text.replace(orig, subst) + pyproject.write_text(text) + (tmp_path / "README.rst").write_text("hello world") (tmp_path / "LICENSE.txt").write_text("--- LICENSE stub ---") (tmp_path / "spam.py").write_text(PEP621_EXAMPLE_SCRIPT) + return pyproject + +def test_pep621_example(tmp_path): + """Make sure the example in PEP 621 works""" + pyproject = _pep621_example_project(tmp_path) dist = pyprojecttoml.apply_configuration(Distribution(), pyproject) assert set(dist.metadata.license_files) == {"LICENSE.txt"} +@pytest.mark.parametrize( + "readme, ctype", + [ + ("Readme.txt", "text/plain"), + ("readme.md", "text/markdown"), + ("text.rst", "text/x-rst"), + ] +) +def test_readme_content_type(tmp_path, readme, ctype): + pyproject = _pep621_example_project(tmp_path, readme) + dist = pyprojecttoml.apply_configuration(Distribution(), pyproject) + assert dist.metadata.long_description_content_type == ctype + + +def test_undefined_content_type(tmp_path): + pyproject = _pep621_example_project(tmp_path, "README.tex") + with pytest.raises(ValueError, match="Undefined content type for README.tex"): + pyprojecttoml.apply_configuration(Distribution(), pyproject) + + +def test_no_explicit_content_type_for_missing_extension(tmp_path): + pyproject = _pep621_example_project(tmp_path, "README") + dist = pyprojecttoml.apply_configuration(Distribution(), pyproject) + assert dist.metadata.long_description_content_type is None + + # --- Auxiliary Functions --- |
