Fix for sphinx 1.6.2

This changes things to work on sphinx 1.6.2, should still work on
sphinx 1.5.1.

Change-Id: I6547877ad46d008616458a5f3b52105ab4f55c28
This commit is contained in:
Sean Dague 2017-06-13 15:06:20 -04:00
parent 199b7b38ee
commit ce1252fcfc
3 changed files with 27 additions and 30 deletions

View File

@ -223,9 +223,9 @@ class RestParametersDirective(Table):
with open(fpath, 'r') as stream:
lookup = ordered_load(stream)
except IOError:
self.env.warn(
self.env.docname,
"Parameters file %s not found" % fpath)
self.app.warn(
"Parameters file %s not found" % fpath,
(self.env.docname, None))
return
except yaml.YAMLError as exc:
self.app.warn(exc)
@ -234,9 +234,9 @@ class RestParametersDirective(Table):
if lookup:
self._check_yaml_sorting(fpath, lookup)
else:
self.env.warn(
self.env.docname,
"Parameters file is empty %s" % fpath)
self.app.warn(
"Parameters file is empty %s" % fpath,
(self.env.docname, None))
return
YAML_CACHE[fpath] = lookup
@ -306,29 +306,27 @@ class RestParametersDirective(Table):
new_content = list()
for paramlist in parsed:
if not isinstance(paramlist, dict):
self.env.warn(
"%s:%s" % (
self.state_machine.node.source,
self.state_machine.node.line),
self.app.warn(
("Invalid parameter definition ``%s``. Expected "
"format: ``name: reference``. "
" Skipping." % paramlist))
" Skipping." % paramlist),
(self.state_machine.node.source,
self.state_machine.node.line))
continue
for name, ref in paramlist.items():
if ref in lookup:
new_content.append((name, lookup[ref]))
else:
# TODO(sdague): this provides a kind of confusing
# error message because env.warn isn't meant to be
# error message because app.warn isn't meant to be
# used this way, however it does provide a way to
# track down where the parameters list is that is
# wrong. So it's good enough for now.
self.env.warn(
"%s:%s " % (
self.state_machine.node.source,
self.state_machine.node.line),
self.app.warn(
("No field definition for ``%s`` found in ``%s``. "
" Skipping." % (ref, fpath)))
" Skipping." % (ref, fpath)),
(self.state_machine.node.source,
self.state_machine.node.line))
# Check for path params in stanza
for i, param in enumerate(self.env.path_params):
@ -342,13 +340,12 @@ class RestParametersDirective(Table):
# Warn that path parameters are not set in rest_parameter
# stanza and will not appear in the generated table.
for param in self.env.path_params:
self.env.warn(
"%s:%s " % (
self.state_machine.node.source,
self.state_machine.node.line),
self.app.warn(
("No path parameter ``%s`` found in rest_parameter"
" stanza.\n"
% param.rstrip('}').lstrip('{')))
% param.rstrip('}').lstrip('{')),
(self.state_machine.node.source,
self.state_machine.node.line))
# self.app.info("New content %s" % new_content)
self.yaml = new_content

View File

@ -49,9 +49,9 @@ class HTTPResponseCodeDirective(Table):
with open(fpath, 'r') as stream:
lookup = yaml.safe_load(stream)
except IOError:
self.env.warn(
self.env.docname,
"Parameters file %s not found" % fpath)
self.app.warn(
"Parameters file %s not found" % fpath,
(self.env.docname, None))
return
except yaml.YAMLError as exc:
self.app.warn(exc)

View File

@ -62,7 +62,7 @@ class TestWarnings(base.TestCase):
+ "OrderedDict([('description',"
+ " 'name_1 is missing type field.\\n'), ('in', 'body'),"
+ " ('required', True)]). "
+ "'NoneType' object has no attribute 'split'\n"),
+ "'NoneType' object has no attribute 'split'"),
self.warning)
def test_invalid_parameter_definition(self):
@ -81,15 +81,15 @@ class TestWarnings(base.TestCase):
def test_no_parameters_set(self):
"""Error when parameters are not set in rest_parameters stanza."""
self.assertIn(
("ERROR: No parameters defined\n\n.."
+ " rest_parameters:: parameters.yaml\n"),
("No parameters defined\n\n.."
+ " rest_parameters:: parameters.yaml"),
self.warning)
def test_parameter_file_not_exist(self):
"""Error when parameter file does not exist"""
self.assertIn(
("ERROR: No parameters defined\n\n.."
+ " rest_parameters:: no_parameters.yaml\n"),
("No parameters defined\n\n.."
+ " rest_parameters:: no_parameters.yaml"),
self.warning)
def test_missing_path_parameter_in_stanza(self):