-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new smoke tests to run converter and mdinclude directive with doc…
…utils (#48)
- Loading branch information
Showing
6 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
TestRestCode, | ||
TestTable, | ||
) | ||
from .test_smoke import SmokeTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
## SubTitle | ||
|
||
__content__ | ||
**content** | ||
|
||
## サブタイトル | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 ..render import convert | ||
from ..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): | ||
content = TEST_MD.read_text() | ||
expected = TEST_RST.read_text() | ||
|
||
result = convert(content) | ||
self.assertEqual(expected, result) | ||
|
||
def test_mdinclude_basic(self): | ||
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)]) |