Coverage for tests/test_base_formatter.py: 100.00%
14 statements
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-16 20:19 +0200
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-16 20:19 +0200
1"""Tests for the base formatter."""
3import pytest
4from markdown import Markdown
6from markdown_exec.formatters.base import base_format
9def test_no_p_around_html(md: Markdown) -> None:
10 """Assert HTML isn't wrapped in a `p` tag.
12 Parameters:
13 md: A Markdown instance (fixture).
14 """
15 code = "<pre><code>hello</code></pre>"
16 html = base_format(
17 language="whatever",
18 run=lambda code, **_: code,
19 code=code,
20 md=md,
21 html=True,
22 )
23 assert html == code
26@pytest.mark.parametrize("html", [True, False])
27def test_render_source(md: Markdown, html: bool) -> None:
28 """Assert source is rendered.
30 Parameters:
31 md: A Markdown instance (fixture).
32 html: Whether output is HTML or not.
33 """
34 markup = base_format(
35 language="python",
36 run=lambda code, **_: code,
37 code="hello",
38 md=md,
39 html=html,
40 source="tabbed-left",
41 )
42 assert "Source" in markup
45def test_render_console_plus_ansi_result(md: Markdown) -> None:
46 """Assert we can render source as console style with `ansi` highlight.
48 Parameters:
49 md: A Markdown instance (fixture).
50 """
51 markup = base_format(
52 language="bash",
53 run=lambda code, **_: code,
54 code="echo -e '\033[31mhello'",
55 md=md,
56 html=False,
57 source="console",
58 result="ansi",
59 )
60 assert "<code>ansi" in markup