fix: keep readme.txt subheads off the lines around them

wporg_subheads() turned `= 0.5.0 =` into `**0.5.0**` with no blank line
after it. Python-Markdown won't let a list interrupt a paragraph, so each
version's `* ` items joined the heading's paragraph as literal text, and
nl2br put <br /> between them. Every changelog published through this
action rendered that way (mu-migration, manifest-updater,
em-event-submissions). A subhead with no blank line before it also joined
the previous version's last item.

The bold line now has a blank line on each side, so it stays its own
block, as wp.org's <h4> does. A subhead that already had blank lines
around it renders exactly as before.

Adds the repo's first tests (stdlib unittest, run with
`python3 -m unittest discover -s tests`) and ignores __pycache__/.
This commit is contained in:
Mike Mulligan committed 2026-10-01 07:52:01 -04:00
1 parent dca1a6a5a6
commit 57910d9c86
4 files changed
+87 -2

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
"""Tests for build-manifest.py. Run from the repo root:
python3 -m unittest discover -s tests
Needs the same `markdown` + `pyyaml` packages release.sh installs.
"""
import importlib.util
import os
import tempfile
import unittest
_BUILDER = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, "build-manifest.py")
_SPEC = importlib.util.spec_from_file_location("build_manifest", _BUILDER)
if _SPEC is None or _SPEC.loader is None:
raise ImportError(f"cannot load build-manifest.py from {_BUILDER}")
bm = importlib.util.module_from_spec(_SPEC)
_SPEC.loader.exec_module(bm)
def readme_sections(readme: str) -> dict:
with tempfile.TemporaryDirectory() as root:
with open(os.path.join(root, "readme.txt"), "w", encoding="utf-8") as fh:
fh.write(readme)
return bm.build_sections({}, root, True, None)
class ReadmeSubheadTest(unittest.TestCase):
def test_changelog_versions_render_as_headings_over_lists(self):
sections = readme_sections(
"=== Plugin ===\n\n"
"== Changelog ==\n\n"
"= 2.0.0 =\n"
"* Added a thing.\n"
"* Fixed a thing.\n"
"= 1.0.0 =\n"
"* Initial release.\n"
"* Second line.\n"
)
self.assertEqual(
sections["changelog"],
"<p><strong>2.0.0</strong></p>\n"
"<ul>\n<li>Added a thing.</li>\n<li>Fixed a thing.</li>\n</ul>\n"
"<p><strong>1.0.0</strong></p>\n"
"<ul>\n<li>Initial release.</li>\n<li>Second line.</li>\n</ul>",
)
def test_subhead_already_set_off_by_blank_lines_is_unchanged(self):
sections = readme_sections(
"=== Plugin ===\n\n"
"== Frequently Asked Questions ==\n\n"
"= Does it work? =\n\n"
"Yes, it does.\n\n"
"**Commands**\n\n"
"* one\n"
"* two\n"
)
self.assertEqual(
sections["faq"],
"<p><strong>Does it work?</strong></p>\n"
"<p>Yes, it does.</p>\n"
"<p><strong>Commands</strong></p>\n"
"<ul>\n<li>one</li>\n<li>two</li>\n</ul>",
)
if __name__ == "__main__":
unittest.main()