Skip to content

Commit eb6ff0a

Browse files
authored
Increase test independence by using the basic theme (#12776)
1 parent 444cc04 commit eb6ff0a

File tree

6 files changed

+49
-29
lines changed

6 files changed

+49
-29
lines changed

sphinx/testing/util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ def __init__(
178178
self.cleanup()
179179
raise
180180

181+
def _init_builder(self) -> None:
182+
# override the default theme to 'basic' rather than 'alabaster'
183+
# for test independence
184+
185+
if 'html_theme' in self.config._overrides:
186+
pass # respect overrides
187+
elif 'html_theme' in self.config and self.config.html_theme == 'alabaster':
188+
self.config.html_theme = self.config._overrides.get('html_theme', 'basic')
189+
super()._init_builder()
190+
181191
@property
182192
def status(self) -> StringIO:
183193
"""The in-memory text I/O for the application status messages."""

tests/test_builders/test_build_html.py

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,12 @@ def test_html_style(app):
367367
@pytest.mark.sphinx(
368368
'html',
369369
testroot='basic',
370-
# alabaster changed default sidebars in 1.0.0
371370
confoverrides={
372371
'html_sidebars': {
373372
'**': [
374-
'about.html',
375-
'navigation.html',
376-
'relations.html',
377-
'searchbox.html',
378-
'donate.html',
373+
'localtoc.html',
374+
'searchfield.html',
375+
'sourcelink.html',
379376
]
380377
}
381378
},
@@ -386,45 +383,58 @@ def test_html_sidebar(app):
386383
# default for alabaster
387384
app.build(force_all=True)
388385
result = (app.outdir / 'index.html').read_text(encoding='utf8')
386+
# layout.html
389387
assert '<div class="sphinxsidebar" role="navigation" aria-label="Main">' in result
390-
assert '<h1 class="logo"><a href="#">Project name not set</a></h1>' in result
388+
assert '<h1>The basic Sphinx documentation for testing' in result
391389
assert '<h3>Navigation</h3>' in result
392-
assert '<h3>Related Topics</h3>' in result
393-
assert '<h3 id="searchlabel">Quick search</h3>' in result
390+
# localtoc.html
391+
assert '<h3><a href="#">Table of Contents</a></h3>' in result
392+
# searchfield.html
393+
assert '<div class="searchformwrapper">' in result
394+
# sourcelink.html
395+
assert '<h3>This Page</h3>' in result
394396

395397
app.builder.add_sidebars('index', ctx)
396398
assert ctx['sidebars'] == [
397-
'about.html',
398-
'navigation.html',
399-
'relations.html',
400-
'searchbox.html',
401-
'donate.html',
399+
'localtoc.html',
400+
'searchfield.html',
401+
'sourcelink.html',
402402
]
403403

404-
# only relations.html
405-
app.config.html_sidebars = {'**': ['relations.html']}
404+
# only sourcelink.html
405+
app.config.html_sidebars = {'**': ['sourcelink.html']}
406406
app.build(force_all=True)
407407
result = (app.outdir / 'index.html').read_text(encoding='utf8')
408+
# layout.html
408409
assert '<div class="sphinxsidebar" role="navigation" aria-label="Main">' in result
409-
assert '<h1 class="logo"><a href="#">Python</a></h1>' not in result
410-
assert '<h3>Navigation</h3>' not in result
411-
assert '<h3>Related Topics</h3>' in result
412-
assert '<h3 id="searchlabel">Quick search</h3>' not in result
410+
assert '<h1>The basic Sphinx documentation for testing' in result
411+
assert '<h3>Navigation</h3>' in result
412+
# localtoc.html
413+
assert '<h3><a href="#">Table of Contents</a></h3>' not in result
414+
# searchfield.html
415+
assert '<div class="searchformwrapper">' not in result
416+
# sourcelink.html
417+
assert '<h3>This Page</h3>' in result
413418

414419
app.builder.add_sidebars('index', ctx)
415-
assert ctx['sidebars'] == ['relations.html']
420+
assert ctx['sidebars'] == ['sourcelink.html']
416421

417422
# no sidebars
418423
app.config.html_sidebars = {'**': []}
419424
app.build(force_all=True)
420425
result = (app.outdir / 'index.html').read_text(encoding='utf8')
426+
# layout.html
421427
assert (
422428
'<div class="sphinxsidebar" role="navigation" aria-label="Main">'
423429
) not in result
424-
assert '<h1 class="logo"><a href="#">Python</a></h1>' not in result
425-
assert '<h3>Navigation</h3>' not in result
426-
assert '<h3>Related Topics</h3>' not in result
427-
assert '<h3 id="searchlabel">Quick search</h3>' not in result
430+
assert '<h1>The basic Sphinx documentation for testing' in result
431+
assert '<h3>Navigation</h3>' in result
432+
# localtoc.html
433+
assert '<h3><a href="#">Table of Contents</a></h3>' not in result
434+
# searchfield.html
435+
assert '<div class="searchformwrapper">' not in result
436+
# sourcelink.html
437+
assert '<h3>This Page</h3>' not in result
428438

429439
app.builder.add_sidebars('index', ctx)
430440
assert ctx['sidebars'] == []

tests/test_builders/test_build_html_assets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def test_assets_order(app, monkeypatch):
8181
expected = [
8282
'_static/early.css',
8383
'_static/pygments.css',
84-
'_static/alabaster.css',
8584
'https://example.com/custom.css',
8685
'_static/normal.css',
8786
'_static/late.css',

tests/test_builders/test_build_html_highlight.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55

6-
@pytest.mark.sphinx('html', testroot='basic')
6+
@pytest.mark.sphinx('html', testroot='basic', confoverrides={'html_theme': 'alabaster'})
77
def test_html_pygments_style_default(app):
88
style = app.builder.highlighter.formatter_args.get('style')
99
assert style.__name__ == 'Alabaster'

tests/test_domains/test_domain_std.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,9 @@ def test_productionlist(app):
497497

498498
etree = etree_parse(app.outdir / 'index.html')
499499
nodes = list(etree.iter('ul'))
500-
assert len(nodes) >= 2
500+
assert len(nodes) >= 3
501501

502-
ul = nodes[1]
502+
ul = nodes[2]
503503
cases = []
504504
for li in list(ul):
505505
assert len(list(li)) == 1

tests/test_intl/test_intl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'language': _CATALOG_LOCALE,
2828
'locale_dirs': ['.'],
2929
'gettext_compact': False,
30+
'html_sidebars': {'**': ['globaltoc.html']}, # for test_html_meta
3031
},
3132
)
3233

0 commit comments

Comments
 (0)