Use jsoncheck in doctest
This patch makes doctest use jsoncheck. It offers: - more helpful syntax error messages (courtesy of demjson) - additional niceness checks for standardized formatting Change-Id: Id92c43daeb6ee17ed03052b3c9b92cbf60f3f4a5 blueprint modularize-doctest
This commit is contained in:
parent
3fd52a5a0b
commit
1192da60ee
@ -31,7 +31,6 @@ Requires:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import gzip
|
import gzip
|
||||||
import json
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import operator
|
import operator
|
||||||
import os
|
import os
|
||||||
@ -47,6 +46,7 @@ from oslo.config import cfg
|
|||||||
|
|
||||||
import os_doc_tools
|
import os_doc_tools
|
||||||
from os_doc_tools.common import check_output # noqa
|
from os_doc_tools.common import check_output # noqa
|
||||||
|
from os_doc_tools import jsoncheck
|
||||||
from os_doc_tools.openstack.common import log
|
from os_doc_tools.openstack.common import log
|
||||||
|
|
||||||
|
|
||||||
@ -486,6 +486,15 @@ def check_deleted_files(rootdir, file_exceptions, verbose):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def indent(text, spaces):
|
||||||
|
"""Indent each line of a string by given number of spaces.
|
||||||
|
|
||||||
|
The text argument is passed through str() first to turn objects such
|
||||||
|
as exceptions into strings.
|
||||||
|
"""
|
||||||
|
return ''.join((spaces * ' ') + i for i in str(text).splitlines(True))
|
||||||
|
|
||||||
|
|
||||||
def validate_one_json_file(rootdir, path, verbose, check_syntax,
|
def validate_one_json_file(rootdir, path, verbose, check_syntax,
|
||||||
check_niceness):
|
check_niceness):
|
||||||
"""Validate a single JSON file."""
|
"""Validate a single JSON file."""
|
||||||
@ -496,12 +505,20 @@ def validate_one_json_file(rootdir, path, verbose, check_syntax,
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if check_syntax:
|
if check_syntax:
|
||||||
json_file = open(path, 'rb')
|
jsoncheck.check_syntax(path)
|
||||||
json.load(json_file)
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
any_failures = True
|
any_failures = True
|
||||||
print(" Invalid JSON file %s: %s" %
|
print(" Invalid JSON file %s:\n%s" %
|
||||||
(os.path.relpath(path, rootdir), e))
|
(os.path.relpath(path, rootdir), indent(e, 4)))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
if check_niceness:
|
||||||
|
jsoncheck.check_formatting(path)
|
||||||
|
except ValueError as e:
|
||||||
|
any_failures = True
|
||||||
|
print(" %s:\n%s" % (os.path.relpath(path, rootdir),
|
||||||
|
indent(e, 4)))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if check_niceness:
|
if check_niceness:
|
||||||
verify_whitespace_niceness(path)
|
verify_whitespace_niceness(path)
|
||||||
|
@ -68,7 +68,7 @@ def _indent_note(note):
|
|||||||
indented_note = []
|
indented_note = []
|
||||||
# Split into single lines in case the argument is pre-formatted.
|
# Split into single lines in case the argument is pre-formatted.
|
||||||
for line in note.splitlines():
|
for line in note.splitlines():
|
||||||
indented_note.append(textwrap.fill(line, initial_indent=8 * ' ',
|
indented_note.append(textwrap.fill(line, initial_indent=4 * ' ',
|
||||||
subsequent_indent=12 * ' ',
|
subsequent_indent=12 * ' ',
|
||||||
width=80))
|
width=80))
|
||||||
return "\n".join(indented_note)
|
return "\n".join(indented_note)
|
||||||
|
@ -9,3 +9,4 @@ iso8601>=0.1.9
|
|||||||
lxml>=2.3
|
lxml>=2.3
|
||||||
oslo.config>=1.4.0 # Apache-2.0
|
oslo.config>=1.4.0 # Apache-2.0
|
||||||
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
|
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
|
||||||
|
demjson
|
||||||
|
Loading…
x
Reference in New Issue
Block a user