Coverage for tests/test_shell.py: 100.00%
17 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 shell formatters."""
3from __future__ import annotations
5from textwrap import dedent
6from typing import TYPE_CHECKING
8if TYPE_CHECKING:
9 import pytest
10 from markdown import Markdown
13def test_output_markdown(md: Markdown) -> None:
14 """Assert Markdown is converted to HTML.
16 Parameters:
17 md: A Markdown instance (fixture).
18 """
19 html = md.convert(
20 dedent(
21 """
22 ```sh exec="yes"
23 echo "**Bold!**"
24 ```
25 """,
26 ),
27 )
28 assert html == "<p><strong>Bold!</strong></p>"
31def test_output_html(md: Markdown) -> None:
32 """Assert HTML is injected as is.
34 Parameters:
35 md: A Markdown instance (fixture).
36 """
37 html = md.convert(
38 dedent(
39 """
40 ```sh exec="yes" html="yes"
41 echo "**Bold!**"
42 ```
43 """,
44 ),
45 )
46 assert html == "<p>**Bold!**\n</p>"
49def test_error_raised(md: Markdown, caplog: pytest.LogCaptureFixture) -> None:
50 """Assert errors properly log a warning and return a formatted traceback.
52 Parameters:
53 md: A Markdown instance (fixture).
54 caplog: Pytest fixture to capture logs.
55 """
56 html = md.convert(
57 dedent(
58 """
59 ```sh exec="yes"
60 echo("wrong syntax")
61 ```
62 """,
63 ),
64 )
65 assert "error" in html
66 assert "Execution of sh code block exited with unexpected code 2" in caplog.text
69def test_return_code(md: Markdown, caplog: pytest.LogCaptureFixture) -> None:
70 """Assert return code is used correctly.
72 Parameters:
73 md: A Markdown instance (fixture).
74 caplog: Pytest fixture to capture logs.
75 """
76 html = md.convert(
77 dedent(
78 """
79 ```sh exec="yes" returncode="1"
80 echo Not in the mood
81 exit 1
82 ```
83 """,
84 ),
85 )
86 assert "Not in the mood" in html
87 assert "exited with" not in caplog.text