|
| 1 | +"""The plugins that need markdown-it-py >= 4.1.0 refuse older versions. |
| 2 | +
|
| 3 | +``test_gfm``, ``test_gfm_autolink`` and ``test_section_ref`` skip below 4.1.0, |
| 4 | +so their version guards are tested here, where they run on every supported version |
| 5 | +(CI runs the suite on the declared floor, markdown-it-py 3.0.0, as well as the latest). |
| 6 | +""" |
| 7 | + |
| 8 | +from types import SimpleNamespace |
| 9 | + |
| 10 | +from markdown_it import MarkdownIt |
| 11 | +from markdown_it import __version__ as mdit_version |
| 12 | +from packaging.version import Version |
| 13 | +import pytest |
| 14 | + |
| 15 | +from mdit_py_plugins.gfm import gfm_plugin |
| 16 | +from mdit_py_plugins.gfm_autolink import gfm_autolink_plugin |
| 17 | +from mdit_py_plugins.section_ref import section_ref_plugin |
| 18 | + |
| 19 | + |
| 20 | +@pytest.mark.skipif( |
| 21 | + Version(mdit_version) >= Version("4.1.0"), |
| 22 | + reason="needs markdown-it-py < 4.1.0 installed", |
| 23 | +) |
| 24 | +@pytest.mark.parametrize( |
| 25 | + "plugin", [gfm_plugin, gfm_autolink_plugin, section_ref_plugin] |
| 26 | +) |
| 27 | +def test_raises_below_4_1(plugin): |
| 28 | + """On markdown-it-py < 4.1.0 the plugin raises a clear error, not a late failure.""" |
| 29 | + with pytest.raises(RuntimeError, match=r"requires markdown-it-py >= 4\.1\.0"): |
| 30 | + MarkdownIt().use(plugin) |
| 31 | + |
| 32 | + |
| 33 | +def test_section_ref_runtime_error(): |
| 34 | + """The plugin requires the ``add_terminator_char`` API (markdown-it-py >= 4.1.0).""" |
| 35 | + md = MarkdownIt() |
| 36 | + md.inline = SimpleNamespace() # type: ignore[assignment] # lacks add_terminator_char |
| 37 | + with pytest.raises(RuntimeError, match="requires markdown-it-py"): |
| 38 | + section_ref_plugin(md) |
0 commit comments