[rtems-central commit] content: Add Content.ensure_blank_line()

Sebastian Huber sebh at rtems.org
Fri Sep 18 11:31:55 UTC 2020


Module:    rtems-central
Branch:    master
Commit:    f59bfb6b8cebf98c7b25e95b7b498949f5462222
Changeset: http://git.rtems.org/rtems-central/commit/?id=f59bfb6b8cebf98c7b25e95b7b498949f5462222

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Jul 24 16:05:49 2020 +0200

content: Add Content.ensure_blank_line()

---

 rtemsspec/content.py            | 5 +++++
 rtemsspec/tests/test_content.py | 8 ++++++++
 2 files changed, 13 insertions(+)

diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index 5e8da8b..cfef89c 100644
--- a/rtemsspec/content.py
+++ b/rtemsspec/content.py
@@ -386,6 +386,11 @@ class Content:
         """ Adds a blank line. """
         self._lines.append("")
 
+    def ensure_blank_line(self):
+        """ Ensures that the last line is blank. """
+        if not self._lines or self._lines[-1]:
+            self._lines.append("")
+
     def register_license(self, the_license: str) -> None:
         """ Registers a licence for the content. """
         licenses = re.split(r"\s+OR\s+", the_license)
diff --git a/rtemsspec/tests/test_content.py b/rtemsspec/tests/test_content.py
index de30276..8383ca8 100644
--- a/rtemsspec/tests/test_content.py
+++ b/rtemsspec/tests/test_content.py
@@ -178,6 +178,14 @@ def test_add_blank_line():
 """
 
 
+def test_ensure_blank_line():
+    content = Content("BSD-2-Clause", True)
+    content.ensure_blank_line()
+    content.ensure_blank_line()
+    assert str(content) == """
+"""
+
+
 def test_indent():
     content = Content("BSD-2-Clause", True)
     content.add_blank_line()



More information about the vc mailing list