Commit 868d8498 authored by Philipp A's avatar Philipp A Committed by Cheryl Sabella

bpo-31292: Fixed distutils check --restructuredtext for include directives (GH-10605)

parent 4c600046
...@@ -120,7 +120,8 @@ class check(Command): ...@@ -120,7 +120,8 @@ class check(Command):
def _check_rst_data(self, data): def _check_rst_data(self, data):
"""Returns warnings when the provided data doesn't compile.""" """Returns warnings when the provided data doesn't compile."""
source_path = StringIO() # the include and csv_table directives need this to be a path
source_path = self.distribution.script_name or 'setup.py'
parser = Parser() parser = Parser()
settings = frontend.OptionParser(components=(Parser,)).get_default_values() settings = frontend.OptionParser(components=(Parser,)).get_default_values()
settings.tab_width = 4 settings.tab_width = 4
......
This should be included.
"""Tests for distutils.command.check.""" """Tests for distutils.command.check."""
import os
import textwrap import textwrap
import unittest import unittest
from test.support import run_unittest from test.support import run_unittest
...@@ -13,13 +14,19 @@ except ImportError: ...@@ -13,13 +14,19 @@ except ImportError:
pygments = None pygments = None
HERE = os.path.dirname(__file__)
class CheckTestCase(support.LoggingSilencer, class CheckTestCase(support.LoggingSilencer,
support.TempdirManager, support.TempdirManager,
unittest.TestCase): unittest.TestCase):
def _run(self, metadata=None, **options): def _run(self, metadata=None, cwd=None, **options):
if metadata is None: if metadata is None:
metadata = {} metadata = {}
if cwd is not None:
old_dir = os.getcwd()
os.chdir(cwd)
pkg_info, dist = self.create_dist(**metadata) pkg_info, dist = self.create_dist(**metadata)
cmd = check(dist) cmd = check(dist)
cmd.initialize_options() cmd.initialize_options()
...@@ -27,6 +34,8 @@ class CheckTestCase(support.LoggingSilencer, ...@@ -27,6 +34,8 @@ class CheckTestCase(support.LoggingSilencer,
setattr(cmd, name, value) setattr(cmd, name, value)
cmd.ensure_finalized() cmd.ensure_finalized()
cmd.run() cmd.run()
if cwd is not None:
os.chdir(old_dir)
return cmd return cmd
def test_check_metadata(self): def test_check_metadata(self):
...@@ -99,6 +108,11 @@ class CheckTestCase(support.LoggingSilencer, ...@@ -99,6 +108,11 @@ class CheckTestCase(support.LoggingSilencer,
cmd = self._run(metadata, strict=1, restructuredtext=1) cmd = self._run(metadata, strict=1, restructuredtext=1)
self.assertEqual(cmd._warnings, 0) self.assertEqual(cmd._warnings, 0)
# check that includes work to test #31292
metadata['long_description'] = 'title\n=====\n\n.. include:: includetest.rst'
cmd = self._run(metadata, cwd=HERE, strict=1, restructuredtext=1)
self.assertEqual(cmd._warnings, 0)
@unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils") @unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
def test_check_restructuredtext_with_syntax_highlight(self): def test_check_restructuredtext_with_syntax_highlight(self):
# Don't fail if there is a `code` or `code-block` directive # Don't fail if there is a `code` or `code-block` directive
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment