File: test_main.py

package info (click to toggle)
python-rich-rst 1.3.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,508 kB
  • sloc: python: 712; makefile: 17
file content (67 lines) | stat: -rw-r--r-- 1,896 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import docutils
import pytest
from rich_rst import RestructuredText
from pathlib import Path
from rich.console import Console
from rich.terminal_theme import TerminalTheme

test_vectors_path = Path("tests/test_vectors")
rst_paths = sorted(str(x) for x in test_vectors_path.glob("*.rst"))
docutils_0_22_mark = pytest.mark.skipif(
    docutils.__version_info__ < (0, 22),
    reason="requires docutils 0.22 or higher",
)


def render_to_html(rst):
    DRACULA_TERMINAL_THEME = TerminalTheme(
        (40, 42, 54),
        (248, 248, 242),
        [
            (40, 42, 54),
            (255, 85, 85),
            (80, 250, 123),
            (241, 250, 140),
            (189, 147, 249),
            (255, 121, 198),
            (139, 233, 253),
            (255, 255, 255),
        ],
        [
            (40, 42, 54),
            (255, 85, 85),
            (80, 250, 123),
            (241, 250, 140),
            (189, 147, 249),
            (255, 121, 198),
            (139, 233, 253),
            (255, 255, 255),
        ],
    )
    console = Console(force_terminal=True, width=120, record=True)
    console.print(rst)
    return console.export_html(theme=DRACULA_TERMINAL_THEME)


@pytest.mark.parametrize(
    "rst_path",
    [
        (
            pytest.param(path, marks=docutils_0_22_mark)
            if path.endswith(("directives.rst", "specification.rst"))
            else path
        )
        for path in rst_paths
    ],
)
def test_main(rst_path):
    rst_path = Path(rst_path)
    actual_html_path = rst_path.parent / (rst_path.stem + "_actual.html")
    expected_html_path = rst_path.parent / (rst_path.stem + "_expected.html")

    rst = RestructuredText(rst_path.read_text(), show_errors=True)
    actual_html = render_to_html(rst)
    actual_html_path.write_text(actual_html)

    expected_html = expected_html_path.read_text()
    assert expected_html == actual_html