mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #5770: doctest: Follow highlight_language on highlighting doctest block
This commit is contained in:
parent
aaf0046f44
commit
d6d4406ce9
2
CHANGES
2
CHANGES
@ -31,6 +31,8 @@ Incompatible changes
|
||||
will use the text font not the math font. The ``LGR`` font encoding must be
|
||||
added to the ``'fontenc'`` key of :confval:`latex_elements` for this to work
|
||||
(only if it is needed by the document, of course).
|
||||
* #5770: doctest: Follow :confval:`highlight_language` on highlighting doctest
|
||||
block. As a result, they are highlighted as python3 by default.
|
||||
|
||||
Deprecated
|
||||
----------
|
||||
|
@ -122,9 +122,15 @@ class TestDirective(SphinxDirective):
|
||||
# only save if it differs from code
|
||||
node['test'] = test
|
||||
if self.name == 'doctest':
|
||||
node['language'] = 'pycon'
|
||||
if self.config.highlight_language in ('py', 'python'):
|
||||
node['language'] = 'pycon'
|
||||
else:
|
||||
node['language'] = 'pycon3' # default
|
||||
elif self.name == 'testcode':
|
||||
node['language'] = 'python'
|
||||
if self.config.highlight_language in ('py', 'python'):
|
||||
node['language'] = 'python'
|
||||
else:
|
||||
node['language'] = 'python3' # default
|
||||
elif self.name == 'testoutput':
|
||||
# don't try to highlight output
|
||||
node['language'] = 'none'
|
||||
|
@ -11,6 +11,7 @@
|
||||
import os
|
||||
from collections import Counter
|
||||
|
||||
from docutils import nodes
|
||||
import pytest
|
||||
from packaging.specifiers import InvalidSpecifier
|
||||
from packaging.version import InvalidVersion
|
||||
@ -32,6 +33,23 @@ def test_build(app, status, warning):
|
||||
assert cleanup_called == 3, 'testcleanup did not get executed enough times'
|
||||
|
||||
|
||||
@pytest.mark.sphinx('dummy', testroot='ext-doctest')
|
||||
def test_highlight_language_default(app, status, warning):
|
||||
app.build()
|
||||
doctree = app.env.get_doctree('doctest')
|
||||
for node in doctree.traverse(nodes.literal_block):
|
||||
assert node['language'] in ('python3', 'pycon3', 'none')
|
||||
|
||||
|
||||
@pytest.mark.sphinx('dummy', testroot='ext-doctest',
|
||||
confoverrides={'highlight_language': 'python'})
|
||||
def test_highlight_language_python2(app, status, warning):
|
||||
app.build()
|
||||
doctree = app.env.get_doctree('doctest')
|
||||
for node in doctree.traverse(nodes.literal_block):
|
||||
assert node['language'] in ('python', 'pycon', 'none')
|
||||
|
||||
|
||||
def test_is_allowed_version():
|
||||
assert is_allowed_version('<3.4', '3.3') is True
|
||||
assert is_allowed_version('<3.4', '3.3') is True
|
||||
|
Loading…
Reference in New Issue
Block a user