Merge pull request #5775 from tk0miya/5770_doctest_refers_highlight_language

Fix #5770: doctest: Follow highlight_language on highlighting doctest block
This commit is contained in:
Takeshi KOMIYA 2018-12-16 00:56:55 +09:00 committed by GitHub
commit 6113261948
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -34,6 +34,8 @@ Incompatible changes
* LaTeX: setting the :confval:`language` to ``'en'`` triggered ``Sonny`` option
of ``fncychap``, now it is ``Bjarne`` to match case of no language specified.
(refs: #5772)
* #5770: doctest: Follow :confval:`highlight_language` on highlighting doctest
block. As a result, they are highlighted as python3 by default.
Deprecated
----------

View File

@ -121,9 +121,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'

View File

@ -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