[rtems-central commit] content: Improve empty list support

Sebastian Huber sebh at rtems.org
Tue Nov 21 13:35:40 UTC 2023


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Nov 21 11:13:15 2023 +0100

content: Improve empty list support

---

 rtemsspec/content.py            | 6 +++++-
 rtemsspec/tests/test_content.py | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index 7e596a2e..cd122f0b 100644
--- a/rtemsspec/content.py
+++ b/rtemsspec/content.py
@@ -467,7 +467,9 @@ class Content:
                  items: GenericContentIterable,
                  prologue: Optional[GenericContent] = None,
                  epilogue: Optional[GenericContent] = None,
-                 add_blank_line: bool = False) -> None:
+                 add_blank_line: bool = False,
+                 empty: Optional[GenericContent] = None) -> None:
+        # pylint: disable=too-many-arguments
         """ Adds a list with introduction. """
         if items:
             self.wrap(prologue)
@@ -476,6 +478,8 @@ class Content:
             if add_blank_line:
                 self.add_blank_line()
             self.wrap(epilogue)
+        else:
+            self.wrap(empty)
 
     def open_list_item(self, content: GenericContent) -> None:
         """ Opens a list item. """
diff --git a/rtemsspec/tests/test_content.py b/rtemsspec/tests/test_content.py
index ad26972e..dbbd1564 100644
--- a/rtemsspec/tests/test_content.py
+++ b/rtemsspec/tests/test_content.py
@@ -218,6 +218,13 @@ def test_add_blank_line():
 """
 
 
+def test_add_list_empty():
+    content = Content("BSD-2-Clause", True)
+    content.add_list([], empty="empty")
+    assert str(content) == """empty
+"""
+
+
 def test_ensure_blank_line():
     content = Content("BSD-2-Clause", True)
     content.ensure_blank_line()



More information about the vc mailing list