Skip to content

Commit

Permalink
fix: emit a warning when no content is rendered (pypa#231)
Browse files Browse the repository at this point in the history
* fix: emit a warning when no content is rendered

Fixes pypa#149

Signed-off-by: Mike Fiedler <[email protected]>

* feat: emit empty warning only if no warnings exist

This is a bit more gymnastics than I think is warranted,
but wanted to play out the example.

Needing to inspect the stream proved more complex than
originally expected, as each version confroms to a slightly
different interface.

- Updated the outpout string to be clearer
- Added test for empty RST file

Signed-off-by: Mike Fiedler <[email protected]>

* refactor: simplify now that distutils is gone

Signed-off-by: Mike Fiedler <[email protected]>
  • Loading branch information
miketheman authored Apr 18, 2022
1 parent 7512742 commit 88b786f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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():
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

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()

0 comments on commit 88b786f

Please sign in to comment.