]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-28222: Don't fail if pygments is not available (GH-7564)
authorZachary Ware <zachary.ware@gmail.com>
Sat, 9 Jun 2018 18:50:23 +0000 (13:50 -0500)
committerGitHub <noreply@github.com>
Sat, 9 Jun 2018 18:50:23 +0000 (13:50 -0500)
We can't just skip the test if docutils is available,
but pygments is not because the purpose of the test
was testing a bug in _check_rst_data().

(cherry-picked from b5bb404ccaa9a3dd81e220fb4ca40253be778831)

Lib/distutils/tests/test_check.py

index 81058b1911ee2109042edc8878e02c6a44cd8ec8..e94647ffa4a7728f6719770980dcbaa1052f8f6b 100644 (file)
@@ -8,6 +8,12 @@ from distutils.command.check import check, HAS_DOCUTILS
 from distutils.tests import support
 from distutils.errors import DistutilsSetupError
 
+try:
+    import pygments
+except ImportError:
+    pygments = None
+
+
 class CheckTestCase(support.LoggingSilencer,
                     support.TempdirManager,
                     unittest.TestCase):
@@ -120,9 +126,15 @@ class CheckTestCase(support.LoggingSilencer,
             pkg_info, dist = self.create_dist(long_description=rest_with_code)
             cmd = check(dist)
             cmd.check_restructuredtext()
-            self.assertEqual(cmd._warnings, 0)
             msgs = cmd._check_rst_data(rest_with_code)
-            self.assertEqual(len(msgs), 0)
+            if pygments is not None:
+                self.assertEqual(len(msgs), 0)
+            else:
+                self.assertEqual(len(msgs), 1)
+                self.assertEqual(
+                    str(msgs[0][1]),
+                    'Cannot analyze code. Pygments package not found.'
+                )
 
     def test_check_all(self):