"""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"], "
2.0.0
\n" "1.0.0
\n" "Does it work?
\n" "Yes, it does.
\n" "Commands
\n" "