de694f7164
This patch fixes existing specs to totally conform to tox py27 environment tests as specified by tests/test_titles.py. Semantic information of all existing specs has not been changed. Specifically, this patch makes the following changes: * Fixes all titles and subtitles' capitalization inconsistencies: defaulting to only having the first word being capitalized (this seems to be the general rule in group-based-policy-specs); * Adds missing titles and subtitles to some specs; * Changes tests/test_titles.py for consistency: only 1st word capitalized; * Changes tests/tests_titles.py: subtitle count inside Testing or Documentation impact no longer restricted to 0. Change-Id: I88e30b0825f5279a8c6808fd9a2fc2987b6611f9 Closes-Bug: #1437282
103 lines
3.5 KiB
Python
103 lines
3.5 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import glob
|
|
|
|
import docutils.core
|
|
from docutils.parsers import rst
|
|
from docutils.parsers.rst import directives
|
|
import testtools
|
|
|
|
|
|
class FakeDirective(rst.Directive):
|
|
has_content = True
|
|
def run(self):
|
|
return []
|
|
|
|
|
|
directives.register_directive('seqdiag', FakeDirective)
|
|
directives.register_directive('blockdiag', FakeDirective)
|
|
directives.register_directive('nwdiag', FakeDirective)
|
|
directives.register_directive('actdiag', FakeDirective)
|
|
|
|
|
|
class TestTitles(testtools.TestCase):
|
|
def _get_title(self, section_tree):
|
|
section = {
|
|
'subtitles': [],
|
|
}
|
|
for node in section_tree:
|
|
if node.tagname == 'title':
|
|
section['name'] = node.rawsource
|
|
elif node.tagname == 'section':
|
|
subsection = self._get_title(node)
|
|
section['subtitles'].append(subsection['name'])
|
|
return section
|
|
|
|
def _get_titles(self, spec):
|
|
titles = {}
|
|
for node in spec:
|
|
if node.tagname == 'section':
|
|
section = self._get_title(node)
|
|
titles[section['name']] = section['subtitles']
|
|
return titles
|
|
|
|
def _check_titles(self, titles):
|
|
problem = 'Problem description'
|
|
self.assertIn(problem, titles)
|
|
self.assertEqual(0, len(titles[problem]))
|
|
|
|
proposed = 'Proposed change'
|
|
self.assertIn(proposed, titles)
|
|
self.assertIn('Alternatives', titles[proposed])
|
|
self.assertIn('Data model impact', titles[proposed])
|
|
self.assertIn('REST API impact', titles[proposed])
|
|
self.assertIn('Security impact', titles[proposed])
|
|
self.assertIn('Notifications impact', titles[proposed])
|
|
self.assertIn('Other end user impact', titles[proposed])
|
|
self.assertIn('Performance impact', titles[proposed])
|
|
self.assertIn('Other deployer impact', titles[proposed])
|
|
self.assertIn('Developer impact', titles[proposed])
|
|
|
|
impl = 'Implementation'
|
|
self.assertIn(impl, titles)
|
|
self.assertEqual(2, len(titles[impl]))
|
|
self.assertIn('Assignee(s)', titles[impl])
|
|
self.assertIn('Work items', titles[impl])
|
|
|
|
deps = 'Dependencies'
|
|
self.assertIn(deps, titles)
|
|
self.assertEqual(0, len(titles[deps]))
|
|
|
|
testing = 'Testing'
|
|
self.assertIn(testing, titles)
|
|
|
|
docs = 'Documentation impact'
|
|
self.assertIn(docs, titles)
|
|
|
|
refs = 'References'
|
|
self.assertIn(refs, titles)
|
|
self.assertEqual(0, len(titles[refs]))
|
|
|
|
self.assertEqual(7, len(titles))
|
|
|
|
def test_template(self):
|
|
files = glob.glob('specs/*.rst') + glob.glob('specs/*/*')
|
|
for filename in files:
|
|
self.assertTrue(filename.endswith(".rst"),
|
|
"spec's file must uses 'rst' extension.")
|
|
with open(filename) as f:
|
|
data = f.read()
|
|
spec = docutils.core.publish_doctree(data)
|
|
titles = self._get_titles(spec)
|
|
self._check_titles(titles)
|