Skip to content

Commit

Permalink
fixturize
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Sep 13, 2024
1 parent d5fc9df commit 23cbb8a
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions tests/test_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
Tree: TypeAlias = Mapping[str | Path, "Tree | str"]


def mkfiles(root: Path, tree: Tree = MappingProxyType({})) -> None:
root.mkdir(parents=True, exist_ok=True)
for path, sub in tree.items():
if isinstance(sub, str):
(root / path).write_text(sub)
else:
mkfiles(root / path, sub)


@pytest.fixture(params=["rst", "myst"])
def app(
request: pytest.FixtureRequest, make_app_setup: Callable[..., Sphinx]
Expand All @@ -32,13 +41,26 @@ def app(
)


def mkfiles(root: Path, tree: Tree = MappingProxyType({})) -> None:
root.mkdir(parents=True, exist_ok=True)
for path, sub in tree.items():
if isinstance(sub, str):
(root / path).write_text(sub)
else:
mkfiles(root / path, sub)
@pytest.fixture
def files(app: Sphinx) -> Tree:
files: Tree
if "myst_parser" in app.extensions:
files = {
"index.md": "```{release-notes} .\n```",
"1.2.0.md": "### 1.2.0",
"1.2.1.md": "### 1.2.1",
"1.3.0.md": "### 1.3.0",
"1.3.2.md": "### 1.3.2",
}
else:
files = {
"index.rst": ".. release-notes:: .",
"1.2.0.rst": "1.2.0\n=====",
"1.2.1.rst": "1.2.1\n=====",
"1.3.0.rst": "1.3.0\n=====",
"1.3.2.rst": "1.3.2\n=====",
}
return files


expected = """\
Expand All @@ -65,25 +87,7 @@ def mkfiles(root: Path, tree: Tree = MappingProxyType({})) -> None:
"""


def test_release_notes(tmp_path: Path, app: Sphinx) -> None:
files: Tree
if "myst_parser" in app.extensions:
files = {
"index.md": "```{release-notes} .\n```",
"1.2.0.md": "### 1.2.0",
"1.2.1.md": "### 1.2.1",
"1.3.0.md": "### 1.3.0",
"1.3.2.md": "### 1.3.2",
}
else:
files = {
"index.rst": ".. release-notes:: .",
"1.2.0.rst": "1.2.0\n=====",
"1.2.1.rst": "1.2.1\n=====",
"1.3.0.rst": "1.3.0\n=====",
"1.3.2.rst": "1.3.2\n=====",
}

def test_release_notes(tmp_path: Path, app: Sphinx, files: Tree) -> None:
mkfiles(tmp_path, files)
app.build()
index_out = (tmp_path / "_build/pseudoxml/index.pseudoxml").read_text()
Expand Down

0 comments on commit 23cbb8a

Please sign in to comment.