File: test_smoke.py

package info (click to toggle)
sphinx-mdinclude 0.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 380 kB
  • sloc: python: 1,242; makefile: 53; sh: 8
file content (78 lines) | stat: -rw-r--r-- 2,151 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
68
69
70
71
72
73
74
75
76
77
78
# Copyright Amethyst Reese
# Licensed under the MIT License

import platform
import unittest
from dataclasses import dataclass, field
from pathlib import Path
from textwrap import dedent

from docutils.frontend import get_default_settings
from docutils.parsers.rst import directives, Parser
from docutils.utils import new_document

from sphinx_mdinclude.render import convert
from sphinx_mdinclude.sphinx import MdInclude

TEST_MD = Path(__file__).parent / "test.md"
TEST_RST = Path(__file__).parent / "test.rst"


@dataclass
class FakeConfig:
    no_underscore_emphasis: bool = False
    md_parse_relative_links: bool = False
    md_anonymous_references: bool = False
    md_disable_inline_math: bool = False


@dataclass
class FakeEnv:
    config: FakeConfig = field(default_factory=FakeConfig)


class SmokeTest(unittest.TestCase):
    maxDiff = None

    @unittest.skipIf(
        platform.system() == "Windows",
        "inconsistent column widths on Windows",
    )
    def test_convert(self) -> None:
        content = TEST_MD.read_text()
        expected = TEST_RST.read_text()

        result = convert(content)
        self.assertEqual(expected, result)

    def test_mdinclude_basic(self) -> None:
        content = dedent(
            f"""
            .. mdinclude:: {TEST_MD}

            """
        )
        expected = dedent(
            """\
            <document source="smoke.rst">
                <section ids="title" names="title">
                    <title>
                        Title
                    <section ids="subtitle" names="subtitle">
                        <title>
                            SubTitle
                        <paragraph>
                            <strong>
                                content
            """
        )

        directives.register_directive("mdinclude", MdInclude)
        parser = Parser()
        settings = get_default_settings(Parser)
        settings.env = FakeEnv()
        document = new_document("smoke.rst", settings.copy())
        parser.parse(content, document)

        result = document.pformat()
        self.assertEqual(expected, result[: len(expected)])