diff --git a/tests/test_check.py b/tests/test_check.py index b31973f1..cceff71e 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -107,6 +107,31 @@ def test_check_no_description(monkeypatch, capsys): ) +def test_check_invalid_description(monkeypatch, capsys): + package = pretend.stub(metadata_dictionary=lambda: { + 'description': "Project", + 'long_description': "My amazing project::", + 'description_content_type': '"text/rst"', # close, but not quite + }) + + monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"]) + monkeypatch.setattr( + check, + "PackageFile", + pretend.stub(from_filename=lambda *a, **kw: package), + ) + + output_stream = check.StringIO() + check.check("dist/*", output_stream=output_stream) + assert output_stream.getvalue() == ( + 'Checking distribution dist/dist.tar.gz: ' + 'warning; `long_description_content_type` invalid.\n' + 'It must be one of the following types: ' + '[text/markdown, text/plain, text/x-rst].\n' + 'Passed\n' + ) + + def test_check_failing_distribution(monkeypatch): renderer = pretend.stub( render=pretend.call_recorder(lambda *a, **kw: None) diff --git a/twine/commands/check.py b/twine/commands/check.py index 67840bdd..5794905b 100644 --- a/twine/commands/check.py +++ b/twine/commands/check.py @@ -32,6 +32,7 @@ "text/markdown": None, # Rendering cannot fail } +_supported_readme_types = sorted([key for key in _RENDERERS.keys() if key]) # Regular expression used to capture and reformat doctuils warnings into # something that a human can understand. This is loosely borrowed from @@ -88,6 +89,13 @@ def check(dists, output_stream=sys.stdout): ) description_content_type = 'text/x-rst' + if description_content_type not in _supported_readme_types: + output_stream.write( + 'warning; `long_description_content_type` invalid.\n' + 'It must be one of the following types: [{}].\n' + .format(", ".join(_supported_readme_types)) + ) + content_type, params = cgi.parse_header(description_content_type) renderer = _RENDERERS.get(content_type, _RENDERERS[None])