Skip to content
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

fix: emit a warning when no content is rendered #231

Merged
merged 3 commits into from
Apr 18, 2022
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
3 changes: 3 additions & 0 deletions readme_renderer/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@ def render(
if rendered:
return clean(rendered)
else:
# If the warnings stream is empty, docutils had none, so add ours.
if not stream.tell():
Comment on lines +132 to +133
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever!

stream.write("No content rendered from RST source.")
return None
30 changes: 30 additions & 0 deletions tests/test_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,33 @@ def test_rst_raw():
""", stream=warnings) is None

assert '"raw" directive disabled' in warnings.getvalue()


def test_rst_empty_file():
warnings = io.StringIO()
assert render("", stream=warnings) is None
miketheman marked this conversation as resolved.
Show resolved Hide resolved

assert "No content rendered from RST source." in warnings.getvalue()


def test_rst_header_only():
warnings = io.StringIO()
assert render("""
Header
======
""", stream=warnings) is None

assert "No content rendered from RST source." in warnings.getvalue()


def test_header_and_malformed_emits_docutils_warning_only():
warnings = io.StringIO()
assert render("""
Header
======

======
""", stream=warnings) is None

assert len(warnings.getvalue().splitlines()) == 1
assert "No content rendered from RST source." not in warnings.getvalue()