[Python-checkins] cpython (merge 3.4 -> default): merge 3.4 (#23063)

benjamin.peterson python-checkins at python.org
Thu Jan 15 06:00:54 CET 2015


https://hg.python.org/cpython/rev/731a36c13629
changeset:   94148:731a36c13629
parent:      94145:61a045ac0006
parent:      94146:db09d760b965
user:        Benjamin Peterson <benjamin at python.org>
date:        Thu Jan 15 00:00:16 2015 -0500
summary:
  merge 3.4 (#23063)

files:
  Lib/distutils/command/check.py    |   8 ++--
  Lib/distutils/tests/test_check.py |  31 +++++++++++++++++++
  Misc/NEWS                         |   3 +
  3 files changed, 38 insertions(+), 4 deletions(-)


diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py
--- a/Lib/distutils/command/check.py
+++ b/Lib/distutils/command/check.py
@@ -122,7 +122,7 @@
         """Returns warnings when the provided data doesn't compile."""
         source_path = StringIO()
         parser = Parser()
-        settings = frontend.OptionParser().get_default_values()
+        settings = frontend.OptionParser(components=(Parser,)).get_default_values()
         settings.tab_width = 4
         settings.pep_references = None
         settings.rfc_references = None
@@ -138,8 +138,8 @@
         document.note_source(source_path, -1)
         try:
             parser.parse(data, document)
-        except AttributeError:
-            reporter.messages.append((-1, 'Could not finish the parsing.',
-                                      '', {}))
+        except AttributeError as e:
+            reporter.messages.append(
+                (-1, 'Could not finish the parsing: %s.' % e, '', {}))
 
         return reporter.messages
diff --git a/Lib/distutils/tests/test_check.py b/Lib/distutils/tests/test_check.py
--- a/Lib/distutils/tests/test_check.py
+++ b/Lib/distutils/tests/test_check.py
@@ -1,4 +1,5 @@
 """Tests for distutils.command.check."""
+import textwrap
 import unittest
 from test.support import run_unittest
 
@@ -92,6 +93,36 @@
         cmd = self._run(metadata, strict=1, restructuredtext=1)
         self.assertEqual(cmd._warnings, 0)
 
+    @unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
+    def test_check_restructuredtext_with_syntax_highlight(self):
+        # Don't fail if there is a `code` or `code-block` directive
+
+        example_rst_docs = []
+        example_rst_docs.append(textwrap.dedent("""\
+            Here's some code:
+
+            .. code:: python
+
+                def foo():
+                    pass
+            """))
+        example_rst_docs.append(textwrap.dedent("""\
+            Here's some code:
+
+            .. code-block:: python
+
+                def foo():
+                    pass
+            """))
+
+        for rest_with_code in example_rst_docs:
+            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)
+
     def test_check_all(self):
 
         metadata = {'url': 'xxx', 'author': 'xxx'}
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -203,6 +203,9 @@
 Library
 -------
 
+- Issue #23063: In the disutils' check command, fix parsing of reST with code or
+  code-block directives.
+
 - Issue #23209, #23225: selectors.BaseSelector.get_key() now raises a
   RuntimeError if the selector is closed. And selectors.BaseSelector.close()
   now clears its internal reference to the selector mapping to break a

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list