Skip to content

Warn about missing long description #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion readme_renderer/integration/distutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def check_restructuredtext(self):
Checks if the long string fields are reST-compliant.
"""
data = self.distribution.get_long_description()

# None or empty string should both trigger this branch.
if not data or data == 'UNKNOWN':
self.warn(
"The project's long_description is either missing or empty.")
return

stream = io.StringIO()
markup = render(data, stream=stream)

Expand All @@ -35,4 +42,6 @@ def check_restructuredtext(self):
self.warn(line)

if markup is None:
self.warn("Invalid markup which will not be rendered on PyPI.")
self.warn(
"The project's long_description has invalid markup which will "
"not be rendered on PyPI.")
56 changes: 56 additions & 0 deletions tests/test_integration_distutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import distutils.dist

import mock

import readme_renderer.integration.distutils


def test_valid_rst():
dist = distutils.dist.Distribution(attrs=dict(
long_description="Hello, I am some text."))
checker = readme_renderer.integration.distutils.Check(dist)
checker.warn = mock.Mock()

checker.check_restructuredtext()

checker.warn.assert_not_called()


def test_invalid_rst():
dist = distutils.dist.Distribution(attrs=dict(
long_description="Hello, I am some `totally borked< text."))
checker = readme_renderer.integration.distutils.Check(dist)
checker.warn = mock.Mock()

checker.check_restructuredtext()

# Should warn once for the syntax error, and finally to warn that the
# overall syntax is invalid
checker.warn.call_count = 2
message_one = checker.warn.call_args_list[0][0][0]
assert 'start-string without end-string' in message_one
message_two = checker.warn.call_args_list[1][0][0]
assert 'invalid markup' in message_two


def test_invalid_missing():
dist = distutils.dist.Distribution(attrs=dict())
checker = readme_renderer.integration.distutils.Check(dist)
checker.warn = mock.Mock()

checker.check_restructuredtext()

checker.warn.assert_called_once_with(mock.ANY)
assert 'missing' in checker.warn.call_args[0][0]


def test_invalid_empty():
dist = distutils.dist.Distribution(attrs=dict(
long_description=""))
checker = readme_renderer.integration.distutils.Check(dist)
checker.warn = mock.Mock()

checker.check_restructuredtext()

checker.warn.assert_called_once_with(mock.ANY)
assert 'missing' in checker.warn.call_args[0][0]
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ envlist = py27,pypy,py34,py35,py36,pep8,py2pep8,packaging
extras = gfm
deps =
pytest
mock
commands =
py.test --strict {posargs}

Expand Down