-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathconftest.py
More file actions
40 lines (32 loc) · 1.15 KB
/
conftest.py
File metadata and controls
40 lines (32 loc) · 1.15 KB
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
import textwrap
import pytest
from pathlib import Path
THEME_DIR = Path(__file__).parent.parent / "mkdocs_dracula_theme"
CSS_SOURCE = Path(__file__).parent.parent / "template" / "assets" / "css" / "mkdocs.css"
CSS_MIN = THEME_DIR / "assets" / "css" / "mkdocs.min.css"
@pytest.fixture()
def docs_dir(tmp_path):
d = tmp_path / "docs"
d.mkdir()
(d / "index.md").write_text("# Home\nHello world.\n")
return d
@pytest.fixture()
def build_site(tmp_path, docs_dir):
"""Factory: build a minimal MkDocs site and return the index.html content."""
from mkdocs.config import load_config
from mkdocs.commands.build import build
def _build(extra_theme_config: str = "") -> str:
config_text = textwrap.dedent(f"""
site_name: Test Site
docs_dir: {docs_dir}
site_dir: {tmp_path / "site"}
theme:
name: dracula
{extra_theme_config}
""")
cfg_path = tmp_path / "mkdocs.yml"
cfg_path.write_text(config_text)
cfg = load_config(str(cfg_path))
build(cfg)
return (tmp_path / "site" / "index.html").read_text()
return _build