Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
liborjelinek committed Oct 29, 2024
1 parent 9c70442 commit ba80b51
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions roots/test-templates/post.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.. post:: 2020-12-01
:author: Durden

post
=======
46 changes: 32 additions & 14 deletions src/ablog/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_skip_ablog_templates_but_missing_templates(app: Sphinx):
"""Completely override the templates used by ablog, but not provide them."""
with pytest.raises(
ThemeError,
match=r"An error happened in rendering the page blog/archive\.\nReason: TemplateNotFound\(\"'ablog/catalog.html' not found in *.",
match=r"An error happened in rendering the page blog/author\.\nReason: TemplateNotFound\(\"'ablog/catalog.html' not found in *.",
):
app.build()

Expand All @@ -20,37 +20,55 @@ def test_skip_ablog_templates_but_missing_templates(app: Sphinx):
confoverrides={
"templates_path": ["_templates"],
"skip_injecting_base_ablog_templates": False, # default value
"html_sidebars": {"**": ["ablog/postcard.html"]},
"html_sidebars": {
"**": [
# overriden by user
"ablog/postcard.html",
# fallback to builtin
"ablog/authors.html",
]
},
},
)
def test_override_template_but_fallback_missing(app: Sphinx, rootdir: Path):
"""Partically override the only some Ablog templates, but use the Ablog ones for missing as fallback."""
app.build()

# read the content of custom postcard template
expected = (rootdir / "test-templates" / "_templates" / "ablog" / "postcard.html").read_text()

# is it in the output?
# is the customized template it in the output?
customized = (rootdir / "test-templates" / "_templates" / "ablog" / "postcard.html").read_text()
source = (app.outdir / "post.html").read_text()
assert expected in source
assert customized in source

# is builtin template in the output?
builtin = '<div class="ablog-sidebar-item ablog__authors">'
assert builtin in source


@pytest.mark.sphinx(
"html",
testroot="templates",
confoverrides={
"html_sidebars": {"**": ["ablog/postcard.html"]},
"html_sidebars": {
"**": [
# overriden by theme
"ablog/postcard.html",
# fallback to builtin
"ablog/authors.html",
]
},
"html_theme_path": "_themes",
"html_theme": "test_theme",
},
)
def test_themes_templates_come_first(app: Sphinx, rootdir: Path):
"""Ensures that if theme supplies own Ablog template, it is used over the builtin one."""
"""Ensures that if theme supplies own Ablog template, it is used over the builtin one, but fallback to builtin for missing ones."""
app.build()

# read the content of custom postcard template
expected = (rootdir / "test-templates" / "_themes" / "test_theme" / "ablog" / "postcard.html").read_text()

# is it in the output?
# is the customized template it in the output?
customized = (rootdir / "test-templates" / "_themes" / "test_theme" / "ablog" / "postcard.html").read_text()
source = (app.outdir / "post.html").read_text()
assert expected in source
assert customized in source

# is builtin template in the output?
builtin = '<div class="ablog-sidebar-item ablog__authors">'
assert builtin in source

0 comments on commit ba80b51

Please sign in to comment.