summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2023-04-17 20:27:15 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2023-04-17 20:27:15 +0000
commitc47135d41d82d18bc0fab7cf2e0406778697d0ad (patch)
tree13f6fb4212be67fb9bacbf3d0d95fd29757b3b0a
parenta521d6ecb581e2d62d929828d588fa38e5f2e03c (diff)
downloaddocutils-c47135d41d82d18bc0fab7cf2e0406778697d0ad.tar.gz
Test syntax highlight: Make pygments version parsing more robust.
Do not fail for pre-release versions (c.f. https://pygments.org/docs/changelog/). git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9355 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_code.py12
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_code_long.py10
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_include.py9
3 files changed, 10 insertions, 21 deletions
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code.py b/docutils/test/test_parsers/test_rst/test_directives/test_code.py
index 7985d1b65..e948a67bd 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_code.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_code.py
@@ -9,6 +9,7 @@ Test the 'code' directive in parsers/rst/directives/body.py.
"""
from pathlib import Path
+import re
import sys
import unittest
@@ -22,13 +23,12 @@ from docutils.parsers.rst import Parser
from docutils.utils import new_document
from docutils.utils.code_analyzer import with_pygments
-try:
- from pygments import __version__ as _pygments_ver
-except ImportError:
- _pygments_ver = ''
- PYGMENTS_2_14_PLUS = False
+if with_pygments:
+ import pygments
+ _pv = re.match(r'^([0-9]+)\.([0-9]*)', pygments.__version__)
+ PYGMENTS_2_14_PLUS = (int(_pv[1]), int(_pv[2])) >= (2, 14)
else:
- PYGMENTS_2_14_PLUS = tuple(map(int, _pygments_ver.split('.'))) >= (2, 14)
+ PYGMENTS_2_14_PLUS = None
class ParserTestCase(unittest.TestCase):
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py b/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py
index 641a5f1d9..6b2f24a95 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py
@@ -21,14 +21,8 @@ from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
from docutils.utils import new_document
from docutils.utils.code_analyzer import with_pygments
-
-try:
- from pygments import __version__ as _pygments_ver
-except ImportError:
- _pygments_ver = ''
- PYGMENTS_2_14_PLUS = False
-else:
- PYGMENTS_2_14_PLUS = tuple(map(int, _pygments_ver.split('.'))) >= (2, 14)
+from test.test_parsers.test_rst.test_directives.test_code \
+ import PYGMENTS_2_14_PLUS
@unittest.skipUnless(with_pygments, 'needs Pygments')
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_include.py b/docutils/test/test_parsers/test_rst/test_directives/test_include.py
index 0667e0e55..45f272692 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_include.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_include.py
@@ -22,14 +22,9 @@ from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
from docutils.utils import new_document
from docutils.utils.code_analyzer import with_pygments
+from test.test_parsers.test_rst.test_directives.test_code \
+ import PYGMENTS_2_14_PLUS
-try:
- from pygments import __version__ as _pygments_ver
-except ImportError:
- _pygments_ver = ''
- PYGMENTS_2_14_PLUS = False
-else:
- PYGMENTS_2_14_PLUS = tuple(map(int, _pygments_ver.split('.'))) >= (2, 14)
TEST_ROOT = Path(__file__).resolve().parents[3]