diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index 8d02f5bed..ffd32d6f5 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -1621,7 +1621,14 @@ def test_html_codeblock_linenos_style_table(app):
app.build()
content = (app.outdir / 'index.html').read_text()
- assert '
' in content
+ pygments_version = tuple(LooseVersion(pygments.__version__).version)
+ if pygments_version >= (2, 8):
+ assert ('1\n'
+ '2\n'
+ '3\n'
+ '4
') in content
+ else:
+ assert '' in content
@pytest.mark.sphinx('html', testroot='reST-code-block',
diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py
index 0ae11baf3..ee67b738a 100644
--- a/tests/test_directive_code.py
+++ b/tests/test_directive_code.py
@@ -9,7 +9,9 @@
"""
import os
+from distutils.version import LooseVersion
+import pygments
import pytest
from docutils import nodes
@@ -421,46 +423,87 @@ def test_literal_include_block_start_with_comment_or_brank(app, status, warning)
def test_literal_include_linenos(app, status, warning):
app.builder.build(['linenos'])
html = (app.outdir / 'linenos.html').read_text()
+ pygments_version = tuple(LooseVersion(pygments.__version__).version)
# :linenos:
- assert (''
- ' 1\n'
- ' 2\n'
- ' 3\n'
- ' 4\n'
- ' 5\n'
- ' 6\n'
- ' 7\n'
- ' 8\n'
- ' 9\n'
- '10\n'
- '11\n'
- '12\n'
- '13 | ' in html)
+ if pygments_version >= (2, 8):
+ assert (''
+ ' 1\n'
+ ' 2\n'
+ ' 3\n'
+ ' 4\n'
+ ' 5\n'
+ ' 6\n'
+ ' 7\n'
+ ' 8\n'
+ ' 9\n'
+ '10\n'
+ '11\n'
+ '12\n'
+ '13 | ' in html)
+ else:
+ assert (''
+ ' 1\n'
+ ' 2\n'
+ ' 3\n'
+ ' 4\n'
+ ' 5\n'
+ ' 6\n'
+ ' 7\n'
+ ' 8\n'
+ ' 9\n'
+ '10\n'
+ '11\n'
+ '12\n'
+ '13 | ' in html)
# :lineno-start:
- assert (''
- '200\n'
- '201\n'
- '202\n'
- '203\n'
- '204\n'
- '205\n'
- '206\n'
- '207\n'
- '208\n'
- '209\n'
- '210\n'
- '211\n'
- '212 | ' in html)
+ if pygments_version >= (2, 8):
+ assert (''
+ '200\n'
+ '201\n'
+ '202\n'
+ '203\n'
+ '204\n'
+ '205\n'
+ '206\n'
+ '207\n'
+ '208\n'
+ '209\n'
+ '210\n'
+ '211\n'
+ '212 | ' in html)
+ else:
+ assert (''
+ '200\n'
+ '201\n'
+ '202\n'
+ '203\n'
+ '204\n'
+ '205\n'
+ '206\n'
+ '207\n'
+ '208\n'
+ '209\n'
+ '210\n'
+ '211\n'
+ '212 | ' in html)
# :lineno-match:
- assert (''
- '5\n'
- '6\n'
- '7\n'
- '8\n'
- '9 | ' in html)
+ if pygments_version >= (2, 8):
+ assert (''
+ '5\n'
+ '6\n'
+ '7\n'
+ '8\n'
+ '9 | ' in html)
+ else:
+ assert (''
+ '5\n'
+ '6\n'
+ '7\n'
+ '8\n'
+ '9 | ' in html)
@pytest.mark.sphinx('latex', testroot='directive-code')
@@ -594,45 +637,82 @@ def test_linenothreshold(app, status, warning):
app.builder.build(['linenothreshold'])
html = (app.outdir / 'linenothreshold.html').read_text()
+ pygments_version = tuple(LooseVersion(pygments.__version__).version)
lineos_head = ' | '
# code-block using linenothreshold
- _, matched, html = html.partition(lineos_head +
- '1\n'
- '2\n'
- '3\n'
- '4\n'
- '5\n'
- '6' + lineos_tail)
+ if pygments_version >= (2, 8):
+ _, matched, html = html.partition(lineos_head +
+ '1\n'
+ '2\n'
+ '3\n'
+ '4\n'
+ '5\n'
+ '6' + lineos_tail)
+ else:
+ _, matched, html = html.partition(lineos_head +
+ '1\n'
+ '2\n'
+ '3\n'
+ '4\n'
+ '5\n'
+ '6' + lineos_tail)
assert matched
# code-block not using linenothreshold
- html, matched, _ = html.partition(lineos_head +
- '1\n'
- '2' + lineos_tail)
+ if pygments_version >= (2, 8):
+ html, matched, _ = html.partition(lineos_head +
+ '1\n'
+ '2' + lineos_tail)
+ else:
+ html, matched, _ = html.partition(lineos_head +
+ '1\n'
+ '2' + lineos_tail)
assert not matched
# literal include using linenothreshold
- _, matched, html = html.partition(lineos_head +
- ' 1\n'
- ' 2\n'
- ' 3\n'
- ' 4\n'
- ' 5\n'
- ' 6\n'
- ' 7\n'
- ' 8\n'
- ' 9\n'
- '10\n'
- '11\n'
- '12\n'
- '13' + lineos_tail)
+ if pygments_version >= (2, 8):
+ _, matched, html = html.partition(lineos_head +
+ ' 1\n'
+ ' 2\n'
+ ' 3\n'
+ ' 4\n'
+ ' 5\n'
+ ' 6\n'
+ ' 7\n'
+ ' 8\n'
+ ' 9\n'
+ '10\n'
+ '11\n'
+ '12\n'
+ '13' + lineos_tail)
+ else:
+ _, matched, html = html.partition(lineos_head +
+ ' 1\n'
+ ' 2\n'
+ ' 3\n'
+ ' 4\n'
+ ' 5\n'
+ ' 6\n'
+ ' 7\n'
+ ' 8\n'
+ ' 9\n'
+ '10\n'
+ '11\n'
+ '12\n'
+ '13' + lineos_tail)
assert matched
# literal include not using linenothreshold
- html, matched, _ = html.partition(lineos_head +
- '1\n'
- '2\n'
- '3' + lineos_tail)
+ if pygments_version >= (2, 8):
+ html, matched, _ = html.partition(lineos_head +
+ '1\n'
+ '2\n'
+ '3' + lineos_tail)
+ else:
+ html, matched, _ = html.partition(lineos_head +
+ '1\n'
+ '2\n'
+ '3' + lineos_tail)
assert not matched