-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for "scope" option (#284)
* Add support for "scope" option * Add test for "extra.scope" option * Clarify description for "scope" * Add fixes for nox * Add parametrization for test_extra_scope, fix bug for "scope": None * Update docs/customization.rst Co-authored-by: Brendan <[email protected]> * Add fixes for nox checks * Add app._warning in extra_scope_test * Add SSL packages * Move SSL packages to main requirements.txt * Remove unnecessary packages --------- Co-authored-by: Bizordec <[email protected]> Co-authored-by: Brendan <[email protected]>
- Loading branch information
1 parent
b35a566
commit 0d83cf3
Showing
6 changed files
with
95 additions
and
8 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mypy==1.5.1 | ||
types-PyYAML | ||
docutils-stubs | ||
types-beautifulsoup4 | ||
types-jsonschema | ||
types-appdirs | ||
types-requests | ||
|
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
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,68 @@ | ||
from __future__ import annotations | ||
|
||
import re | ||
import textwrap | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
from bs4 import BeautifulSoup | ||
|
||
if TYPE_CHECKING: | ||
from sphinx.testing.util import SphinxTestApp | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"scope_url,expected_scope_url", | ||
[ | ||
(None, "."), | ||
("", ""), | ||
("/", "/"), | ||
("/subsite", "/subsite"), | ||
], | ||
ids=[ | ||
"base_url", | ||
"empty", | ||
"root", | ||
"subsite", | ||
], | ||
) | ||
def test_extra_scope( | ||
immaterial_make_app, | ||
scope_url: str | None, | ||
expected_scope_url: str, | ||
): | ||
if scope_url is not None: | ||
scope_url = f'"{scope_url}"' | ||
|
||
app: SphinxTestApp = immaterial_make_app( | ||
extra_conf=textwrap.dedent( | ||
f""" | ||
html_theme_options = {{ | ||
"scope": {scope_url} | ||
}} | ||
""" | ||
), | ||
files={ | ||
"index.rst": "Sample text", | ||
}, | ||
) | ||
app.build() | ||
|
||
assert not app._warning.getvalue() | ||
|
||
with open(Path(app.outdir) / "index.html", mode="r") as file: | ||
soup = BeautifulSoup(file.read(), "html.parser") | ||
|
||
head = soup.head | ||
assert head is not None | ||
|
||
scope_pattern = re.compile(r"__md_scope=new URL\(\"(?P<url>[^\"]+)\"") | ||
matched_scope_url = "" | ||
for script in head.find_all("script"): | ||
scope_match = scope_pattern.search(script.text) | ||
if scope_match: | ||
matched_scope_url = scope_match.group("url") | ||
break | ||
|
||
assert matched_scope_url == expected_scope_url |
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