2017-08-19 02:21:11 +02:00
|
|
|
"""Sanity test using rstcheck."""
|
2019-07-12 08:46:20 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2017-08-19 02:21:11 +02:00
|
|
|
|
|
|
|
import os
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .. import types as t
|
2019-07-30 20:10:55 +02:00
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from ..sanity import (
|
2017-08-19 02:21:11 +02:00
|
|
|
SanitySingleVersion,
|
|
|
|
SanityMessage,
|
|
|
|
SanityFailure,
|
|
|
|
SanitySuccess,
|
2019-08-06 02:40:00 +02:00
|
|
|
SANITY_ROOT,
|
2019-07-30 20:10:55 +02:00
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from ..target import (
|
2019-07-30 20:10:55 +02:00
|
|
|
TestTarget,
|
2017-08-19 02:21:11 +02:00
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from ..util import (
|
2017-08-19 02:21:11 +02:00
|
|
|
SubprocessError,
|
2018-09-21 07:20:08 +02:00
|
|
|
parse_to_list_of_dict,
|
2018-09-20 08:20:27 +02:00
|
|
|
read_lines_without_comments,
|
2019-07-27 01:46:52 +02:00
|
|
|
find_python,
|
2017-08-19 02:21:11 +02:00
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from ..util_common import (
|
2019-07-11 07:00:34 +02:00
|
|
|
run_command,
|
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from ..config import (
|
2017-08-19 02:21:11 +02:00
|
|
|
SanityConfig,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class RstcheckTest(SanitySingleVersion):
|
|
|
|
"""Sanity test using rstcheck."""
|
2019-07-30 20:10:55 +02:00
|
|
|
def filter_targets(self, targets): # type: (t.List[TestTarget]) -> t.List[TestTarget]
|
|
|
|
"""Return the given list of test targets, filtered to include only those relevant for the test."""
|
|
|
|
return [target for target in targets if os.path.splitext(target.path)[1] in ('.rst',)]
|
|
|
|
|
2019-07-27 01:46:52 +02:00
|
|
|
def test(self, args, targets, python_version):
|
2017-08-19 02:21:11 +02:00
|
|
|
"""
|
|
|
|
:type args: SanityConfig
|
|
|
|
:type targets: SanityTargets
|
2019-07-27 01:46:52 +02:00
|
|
|
:type python_version: str
|
2018-04-04 03:53:53 +02:00
|
|
|
:rtype: TestResult
|
2017-08-19 02:21:11 +02:00
|
|
|
"""
|
2019-08-06 02:40:00 +02:00
|
|
|
ignore_file = os.path.join(SANITY_ROOT, 'rstcheck', 'ignore-substitutions.txt')
|
2018-09-20 08:20:27 +02:00
|
|
|
ignore_substitutions = sorted(set(read_lines_without_comments(ignore_file, remove_blank_lines=True)))
|
2017-08-19 02:21:11 +02:00
|
|
|
|
2019-07-26 08:29:23 +02:00
|
|
|
settings = self.load_processor(args)
|
2019-07-23 22:31:54 +02:00
|
|
|
|
2019-07-30 20:10:55 +02:00
|
|
|
paths = [target.path for target in targets.include]
|
2017-08-19 02:21:11 +02:00
|
|
|
|
|
|
|
cmd = [
|
2019-07-27 01:46:52 +02:00
|
|
|
find_python(python_version),
|
2018-03-14 19:35:59 +01:00
|
|
|
'-m', 'rstcheck',
|
2017-08-19 02:21:11 +02:00
|
|
|
'--report', 'warning',
|
|
|
|
'--ignore-substitutions', ','.join(ignore_substitutions),
|
|
|
|
] + paths
|
|
|
|
|
|
|
|
try:
|
|
|
|
stdout, stderr = run_command(args, cmd, capture=True)
|
|
|
|
status = 0
|
|
|
|
except SubprocessError as ex:
|
|
|
|
stdout = ex.stdout
|
|
|
|
stderr = ex.stderr
|
|
|
|
status = ex.status
|
|
|
|
|
|
|
|
if stdout:
|
|
|
|
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
|
|
|
|
|
|
|
|
if args.explain:
|
|
|
|
return SanitySuccess(self.name)
|
|
|
|
|
|
|
|
pattern = r'^(?P<path>[^:]*):(?P<line>[0-9]+): \((?P<level>INFO|WARNING|ERROR|SEVERE)/[0-4]\) (?P<message>.*)$'
|
|
|
|
|
2018-09-21 07:20:08 +02:00
|
|
|
results = parse_to_list_of_dict(pattern, stderr)
|
2017-08-19 02:21:11 +02:00
|
|
|
|
|
|
|
results = [SanityMessage(
|
|
|
|
message=r['message'],
|
|
|
|
path=r['path'],
|
|
|
|
line=int(r['line']),
|
|
|
|
column=0,
|
|
|
|
level=r['level'],
|
|
|
|
) for r in results]
|
|
|
|
|
2019-07-23 22:31:54 +02:00
|
|
|
settings.process_errors(results, paths)
|
|
|
|
|
2017-08-19 02:21:11 +02:00
|
|
|
if results:
|
|
|
|
return SanityFailure(self.name, messages=results)
|
|
|
|
|
|
|
|
return SanitySuccess(self.name)
|