Artifact Repository (Glare) Specifications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_titles.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. import glob
  13. import re
  14. import docutils.core
  15. import testtools
  16. class TestTitles(testtools.TestCase):
  17. def _get_title(self, section_tree):
  18. section = {
  19. 'subtitles': [],
  20. }
  21. for node in section_tree:
  22. if node.tagname == 'title':
  23. section['name'] = node.rawsource
  24. elif node.tagname == 'section':
  25. subsection = self._get_title(node)
  26. section['subtitles'].append(subsection['name'])
  27. return section
  28. def _get_titles(self, spec):
  29. titles = {}
  30. for node in spec:
  31. if node.tagname == 'section':
  32. section = self._get_title(node)
  33. titles[section['name']] = section['subtitles']
  34. return titles
  35. def _check_titles(self, fname, titles):
  36. expected_titles = ('Problem description', 'Proposed change',
  37. 'Implementation', 'Dependencies',
  38. 'Testing', 'Documentation Impact',
  39. 'References')
  40. self.assertEqual(
  41. sorted(expected_titles),
  42. sorted(titles.keys()),
  43. "Expected titles not found in document %s" % fname)
  44. proposed = 'Proposed change'
  45. self.assertIn('Alternatives', titles[proposed])
  46. self.assertIn('Data model impact', titles[proposed])
  47. self.assertIn('REST API impact', titles[proposed])
  48. self.assertIn('Versioning impact', titles[proposed])
  49. self.assertIn('Other end user impact', titles[proposed])
  50. self.assertIn('Deployer impact', titles[proposed])
  51. self.assertIn('Developer impact', titles[proposed])
  52. impl = 'Implementation'
  53. self.assertIn('Assignee(s)', titles[impl])
  54. self.assertIn('Work Items', titles[impl])
  55. def _check_titles_lite(self, fname, titles):
  56. self.assertEqual(
  57. ['Glare Spec Lite'],
  58. sorted(titles.keys()),
  59. "Expected titles not found in document %s" % fname)
  60. def _check_lines_wrapping(self, tpl, raw):
  61. for i, line in enumerate(raw.split("\n")):
  62. if "http://" in line or "https://" in line:
  63. continue
  64. self.assertTrue(
  65. len(line) < 80,
  66. msg="%s:%d: Line limited to a maximum of 79 characters." %
  67. (tpl, i+1))
  68. def _check_no_cr(self, tpl, raw):
  69. matches = re.findall('\r', raw)
  70. self.assertEqual(
  71. len(matches), 0,
  72. "Found %s literal carriage returns in file %s" %
  73. (len(matches), tpl))
  74. def _check_trailing_spaces(self, tpl, raw):
  75. for i, line in enumerate(raw.split("\n")):
  76. trailing_spaces = re.findall(" +$", line)
  77. self.assertEqual(len(trailing_spaces),0,
  78. "Found trailing spaces on line %s of %s" % (i+1, tpl))
  79. def test_template(self):
  80. files = ['specs/template.rst'] + glob.glob('specs/*/*/*')
  81. for filename in files:
  82. self.assertTrue(filename.endswith(".rst"),
  83. "spec's file must uses 'rst' extension.")
  84. with open(filename) as f:
  85. data = f.read()
  86. spec = docutils.core.publish_doctree(data)
  87. titles = self._get_titles(spec)
  88. if 'Glare Spec Lite' in titles:
  89. self._check_titles_lite(filename, titles)
  90. else:
  91. self._check_titles(filename, titles)
  92. self._check_lines_wrapping(filename, data)
  93. self._check_no_cr(filename, data)
  94. self._check_trailing_spaces(filename, data)