]> granicus.if.org Git - python/commitdiff
Issue #28222: Don't fail if pygments is not available
authorBerker Peksag <berker.peksag@gmail.com>
Tue, 4 Oct 2016 17:54:44 +0000 (20:54 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Tue, 4 Oct 2016 17:54:44 +0000 (20:54 +0300)
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().

Lib/distutils/tests/test_check.py

index 959fa9085cf548048b226f827dea23c5b0fa5cef..3d22868e313be788468e898863e301896f57a990 100644 (file)
@@ -7,6 +7,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):
@@ -119,9 +125,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):