Check that filename is same as blueprint name

The template was updated to indicate that the filename of the
specification must match the name of the blueprint (changed the
name of the sample blueprint be 'template' to match template.rst),
and that the title of the specification could be the title of the
blueprint.

A unit test was added to check the filename against the blueprint name.

Fixed a typo in one of the unit tests.

Change-Id: Ia5180aa44d6b2967d4843b8ab176915181e5e77f
This commit is contained in:
Ruby Loo 2015-01-05 23:05:59 +00:00
parent dff5e96722
commit 9110d19447
2 changed files with 39 additions and 8 deletions

View File

@ -4,13 +4,13 @@
http://creativecommons.org/licenses/by/3.0/legalcode
==========================================
Example Spec - The title of your blueprint
==========================================
==================================================
Title of the Spec - eg the title of your blueprint
==================================================
Include the URL of your launchpad blueprint:
https://blueprints.launchpad.net/ironic/+spec/example
https://blueprints.launchpad.net/ironic/+spec/template
Introduction paragraph -- start here.
@ -23,9 +23,9 @@ Some notes about using this template:
* Please wrap text at 79 columns.
* The filename in the git repository should match the launchpad URL, for
* The filename in the git repository must match the launchpad URL, for
example a URL of: https://blueprints.launchpad.net/ironic/+spec/awesome-thing
should be named awesome-thing.rst
must be named awesome-thing.rst
* Please do not delete any of the sections in this template. If you have
nothing to say for a whole section, just write: None

View File

@ -11,6 +11,7 @@
# under the License.
import glob
import os.path
import re
import docutils.core
@ -19,12 +20,16 @@ import testtools
RELEASE = 'kilo'
FIRST_TITLE = 'Problem description'
DRAFT_DIR = 'backlog'
DRAFT_REQUIRED_TITLES = {
'Problem description': [],
FIRST_TITLE: [],
'Proposed change': [],
}
BLUEPRINT_URL = 'https://blueprints.launchpad.net/ironic/+spec/'
class TestTitles(testtools.TestCase):
def _get_title(self, section_tree):
@ -96,8 +101,32 @@ class TestTitles(testtools.TestCase):
self.assertTrue(filename.endswith(".rst"),
"spec's file must uses 'rst' extension.")
def _check_filename(self, filename, raw):
"""Check that the filename matches the blueprint name.
Checks that the URL for the blueprint is mentioned, and that the
filename matches the name of the blueprint. This assumes that the
blueprint URL occurs on a line without any other text and the URL
occurs before the first section (title) of the specification.
param filename: path/name of the file
param raw: the data in the file
"""
(root, _) = os.path.splitext(os.path.basename(filename))
for i, line in enumerate(raw.split("\n")):
if BLUEPRINT_URL in line:
self.assertTrue(line.endswith(root),
"Filename '%s' must match blueprint name '%s'" %
(filename, line))
return
if line.startswith(FIRST_TITLE):
break
self.fail("URL of launchpad blueprint is missing")
def _check_license(self, raw):
# Check for the presense of this license string somewhere within the
# Check for the presence of this license string somewhere within the
# header of the spec file, ignoring newlines and blank lines and any
# other lines before or after it.
license_check_str = (
@ -140,6 +169,7 @@ class TestTitles(testtools.TestCase):
self._check_no_cr(filename, data)
self._check_trailing_spaces(filename, data)
self._check_license(data)
self._check_filename(filename, data)
def test_backlog(self):
template_titles = self._get_template_titles()
@ -153,3 +183,4 @@ class TestTitles(testtools.TestCase):
self._check_lines_wrapping(filename, data)
self._check_no_cr(filename, data)
self._check_trailing_spaces(filename, data)
self._check_filename(filename, data)