Skip to content

Commit 1577cd1

Browse files
author
Jon Wayne Parrott
committed
Warn about missing long description
Additionally, add comprehensive tests for the disutils integration. Resolves pypa#64
1 parent 8e44fa9 commit 1577cd1

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

readme_renderer/integration/distutils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def check_restructuredtext(self):
2626
Checks if the long string fields are reST-compliant.
2727
"""
2828
data = self.distribution.get_long_description()
29+
30+
# None or empty string should both trigger this branch.
31+
if not data or data == 'UNKNOWN':
32+
self.warn(
33+
"The project's long_description is either missing or empty.")
34+
return
35+
2936
stream = io.StringIO()
3037
markup = render(data, stream=stream)
3138

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

3744
if markup is None:
38-
self.warn("Invalid markup which will not be rendered on PyPI.")
45+
self.warn(
46+
"The project's long_description has invalid markup which will "
47+
"not be rendered on PyPI.")

tests/test_integration_distutils.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import distutils.dist
2+
3+
import mock
4+
5+
import readme_renderer.integration.distutils
6+
7+
8+
def test_valid_rst():
9+
dist = distutils.dist.Distribution(attrs=dict(
10+
long_description="Hello, I am some text."))
11+
checker = readme_renderer.integration.distutils.Check(dist)
12+
checker.warn = mock.Mock()
13+
14+
checker.check_restructuredtext()
15+
16+
checker.warn.assert_not_called()
17+
18+
19+
def test_invalid_rst():
20+
dist = distutils.dist.Distribution(attrs=dict(
21+
long_description="Hello, I am some `totally borked< text."))
22+
checker = readme_renderer.integration.distutils.Check(dist)
23+
checker.warn = mock.Mock()
24+
25+
checker.check_restructuredtext()
26+
27+
# Should warn once for the syntax error, and finally to warn that the
28+
# overall syntax is invalid
29+
checker.warn.call_count = 2
30+
message_one = checker.warn.call_args_list[0][0][0]
31+
assert 'start-string without end-string' in message_one
32+
message_two = checker.warn.call_args_list[1][0][0]
33+
assert 'invalid markup' in message_two
34+
35+
36+
def test_invalid_missing():
37+
dist = distutils.dist.Distribution(attrs=dict())
38+
checker = readme_renderer.integration.distutils.Check(dist)
39+
checker.warn = mock.Mock()
40+
41+
checker.check_restructuredtext()
42+
43+
checker.warn.assert_called_once_with(mock.ANY)
44+
assert 'missing' in checker.warn.call_args[0][0]
45+
46+
47+
def test_invalid_empty():
48+
dist = distutils.dist.Distribution(attrs=dict(
49+
long_description=""))
50+
checker = readme_renderer.integration.distutils.Check(dist)
51+
checker.warn = mock.Mock()
52+
53+
checker.check_restructuredtext()
54+
55+
checker.warn.assert_called_once_with(mock.ANY)
56+
assert 'missing' in checker.warn.call_args[0][0]

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ envlist = py27,pypy,py34,py35,py36,pep8,py2pep8,packaging
55
extras = gfm
66
deps =
77
pytest
8+
mock
89
commands =
910
py.test --strict {posargs}
1011

0 commit comments

Comments
 (0)