Skip to content

Commit ba80b51

Browse files
committed
improve tests
1 parent 9c70442 commit ba80b51

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

roots/test-templates/post.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.. post:: 2020-12-01
2+
:author: Durden
23

34
post
45
=======

src/ablog/tests/test_templates.py

+32-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_skip_ablog_templates_but_missing_templates(app: Sphinx):
99
"""Completely override the templates used by ablog, but not provide them."""
1010
with pytest.raises(
1111
ThemeError,
12-
match=r"An error happened in rendering the page blog/archive\.\nReason: TemplateNotFound\(\"'ablog/catalog.html' not found in *.",
12+
match=r"An error happened in rendering the page blog/author\.\nReason: TemplateNotFound\(\"'ablog/catalog.html' not found in *.",
1313
):
1414
app.build()
1515

@@ -20,37 +20,55 @@ def test_skip_ablog_templates_but_missing_templates(app: Sphinx):
2020
confoverrides={
2121
"templates_path": ["_templates"],
2222
"skip_injecting_base_ablog_templates": False, # default value
23-
"html_sidebars": {"**": ["ablog/postcard.html"]},
23+
"html_sidebars": {
24+
"**": [
25+
# overriden by user
26+
"ablog/postcard.html",
27+
# fallback to builtin
28+
"ablog/authors.html",
29+
]
30+
},
2431
},
2532
)
2633
def test_override_template_but_fallback_missing(app: Sphinx, rootdir: Path):
2734
"""Partically override the only some Ablog templates, but use the Ablog ones for missing as fallback."""
2835
app.build()
2936

30-
# read the content of custom postcard template
31-
expected = (rootdir / "test-templates" / "_templates" / "ablog" / "postcard.html").read_text()
32-
33-
# is it in the output?
37+
# is the customized template it in the output?
38+
customized = (rootdir / "test-templates" / "_templates" / "ablog" / "postcard.html").read_text()
3439
source = (app.outdir / "post.html").read_text()
35-
assert expected in source
40+
assert customized in source
41+
42+
# is builtin template in the output?
43+
builtin = '<div class="ablog-sidebar-item ablog__authors">'
44+
assert builtin in source
3645

3746

3847
@pytest.mark.sphinx(
3948
"html",
4049
testroot="templates",
4150
confoverrides={
42-
"html_sidebars": {"**": ["ablog/postcard.html"]},
51+
"html_sidebars": {
52+
"**": [
53+
# overriden by theme
54+
"ablog/postcard.html",
55+
# fallback to builtin
56+
"ablog/authors.html",
57+
]
58+
},
4359
"html_theme_path": "_themes",
4460
"html_theme": "test_theme",
4561
},
4662
)
4763
def test_themes_templates_come_first(app: Sphinx, rootdir: Path):
48-
"""Ensures that if theme supplies own Ablog template, it is used over the builtin one."""
64+
"""Ensures that if theme supplies own Ablog template, it is used over the builtin one, but fallback to builtin for missing ones."""
4965
app.build()
5066

51-
# read the content of custom postcard template
52-
expected = (rootdir / "test-templates" / "_themes" / "test_theme" / "ablog" / "postcard.html").read_text()
53-
54-
# is it in the output?
67+
# is the customized template it in the output?
68+
customized = (rootdir / "test-templates" / "_themes" / "test_theme" / "ablog" / "postcard.html").read_text()
5569
source = (app.outdir / "post.html").read_text()
56-
assert expected in source
70+
assert customized in source
71+
72+
# is builtin template in the output?
73+
builtin = '<div class="ablog-sidebar-item ablog__authors">'
74+
assert builtin in source

0 commit comments

Comments
 (0)