Skip to content

Commit

Permalink
Warn about missing long description (#69)
Browse files Browse the repository at this point in the history
Additionally, add comprehensive tests for the disutils integration.

Resolves #64
  • Loading branch information
Jon Wayne Parrott authored Mar 30, 2018
1 parent 8e44fa9 commit 506da6a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
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

0 comments on commit 506da6a

Please sign in to comment.