| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import TYPE_CHECKING |
| 4 |
from unittest.mock import ANY, call, patch |
| 5 |
|
| 6 |
import pytest |
| 7 |
|
| 8 |
from sphinx.builders.html import StandaloneHTMLBuilder |
| 9 |
|
| 10 |
if TYPE_CHECKING: |
| 11 |
from sphinx.testing.util import SphinxTestApp |
| 12 |
|
| 13 |
|
| 14 |
@pytest.mark.sphinx('html', testroot='basic', confoverrides={'html_theme': 'alabaster'}) |
| 15 |
def test_html_pygments_style_default(app: SphinxTestApp) -> None: |
| 16 |
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking |
| 17 |
style = app.builder.highlighter.formatter_args.get('style') |
| 18 |
assert style is not None |
| 19 |
assert style.__name__ == 'Alabaster' |
| 20 |
|
| 21 |
|
| 22 |
@pytest.mark.sphinx( |
| 23 |
'html', |
| 24 |
testroot='basic', |
| 25 |
confoverrides={'pygments_style': 'sphinx'}, |
| 26 |
) |
| 27 |
def test_html_pygments_style_manually(app: SphinxTestApp) -> None: |
| 28 |
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking |
| 29 |
style = app.builder.highlighter.formatter_args.get('style') |
| 30 |
assert style is not None |
| 31 |
assert style.__name__ == 'SphinxStyle' |
| 32 |
|
| 33 |
|
| 34 |
@pytest.mark.sphinx( |
| 35 |
'html', |
| 36 |
testroot='basic', |
| 37 |
confoverrides={'html_theme': 'classic'}, |
| 38 |
) |
| 39 |
def test_html_pygments_for_classic_theme(app: SphinxTestApp) -> None: |
| 40 |
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking |
| 41 |
style = app.builder.highlighter.formatter_args.get('style') |
| 42 |
assert style is not None |
| 43 |
assert style.__name__ == 'SphinxStyle' |
| 44 |
|
| 45 |
|
| 46 |
@pytest.mark.sphinx('html', testroot='basic') |
| 47 |
def test_html_dark_pygments_style_default(app: SphinxTestApp) -> None: |
| 48 |
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking |
| 49 |
assert app.builder.dark_highlighter is None |
| 50 |
|
| 51 |
|
| 52 |
@pytest.mark.sphinx('html', testroot='highlight_options') |
| 53 |
def test_highlight_options(app: SphinxTestApp) -> None: |
| 54 |
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking |
| 55 |
subject = app.builder.highlighter |
| 56 |
with patch.object( |
| 57 |
subject, |
| 58 |
'highlight_block', |
| 59 |
wraps=subject.highlight_block, |
| 60 |
) as highlight: |
| 61 |
app.build() |
| 62 |
|
| 63 |
call_args = highlight.call_args_list |
| 64 |
assert len(call_args) == 3 |
| 65 |
assert call_args[0] == call( |
| 66 |
ANY, |
| 67 |
'default', |
| 68 |
force=False, |
| 69 |
linenos=False, |
| 70 |
location=ANY, |
| 71 |
opts={'default_option': True}, |
| 72 |
) |
| 73 |
assert call_args[1] == call( |
| 74 |
ANY, |
| 75 |
'python', |
| 76 |
force=False, |
| 77 |
linenos=False, |
| 78 |
location=ANY, |
| 79 |
opts={'python_option': True}, |
| 80 |
) |
| 81 |
assert call_args[2] == call( |
| 82 |
ANY, |
| 83 |
'java', |
| 84 |
force=False, |
| 85 |
linenos=False, |
| 86 |
location=ANY, |
| 87 |
opts={}, |
| 88 |
) |
| 89 |
|
| 90 |
|
| 91 |
@pytest.mark.sphinx( |
| 92 |
'html', |
| 93 |
testroot='highlight_options', |
| 94 |
confoverrides={'highlight_options': {'default_option': True}}, |
| 95 |
) |
| 96 |
def test_highlight_options_old(app: SphinxTestApp) -> None: |
| 97 |
assert isinstance(app.builder, StandaloneHTMLBuilder) # type-checking |
| 98 |
subject = app.builder.highlighter |
| 99 |
with patch.object( |
| 100 |
subject, |
| 101 |
'highlight_block', |
| 102 |
wraps=subject.highlight_block, |
| 103 |
) as highlight: |
| 104 |
app.build() |
| 105 |
|
| 106 |
call_args = highlight.call_args_list |
| 107 |
assert len(call_args) == 3 |
| 108 |
assert call_args[0] == call( |
| 109 |
ANY, |
| 110 |
'default', |
| 111 |
force=False, |
| 112 |
linenos=False, |
| 113 |
location=ANY, |
| 114 |
opts={'default_option': True}, |
| 115 |
) |
| 116 |
assert call_args[1] == call( |
| 117 |
ANY, |
| 118 |
'python', |
| 119 |
force=False, |
| 120 |
linenos=False, |
| 121 |
location=ANY, |
| 122 |
opts={}, |
| 123 |
) |
| 124 |
assert call_args[2] == call( |
| 125 |
ANY, |
| 126 |
'java', |
| 127 |
force=False, |
| 128 |
linenos=False, |
| 129 |
location=ANY, |
| 130 |
opts={}, |
| 131 |
) |