Example #1
0
 def test_is_empty(self):
     assert RecordBody().is_empty() is True
     assert RecordBody([RecordSection("fixed", "")]).is_empty() is True
     assert RecordBody(prefix="prefix").is_empty() is False
     assert RecordBody(postfix="prefix").is_empty() is False
     assert RecordBody([RecordSection("fixed", "- fixed")
                        ]).is_empty() is False
Example #2
0
 def test_init(self):
     body = RecordBody((
         RecordSection("removed", "- removed"),
         RecordSection("added", "- added"),
         RecordSection("added", "- added2\n"),
     ))
     assert body.render(
     ) == "### Added\n- added\n- added2\n\n### Removed\n- removed"
Example #3
0
 def test_bump_rc_version(self):
     body = RecordBody((
         RecordSection("removed", "- removed"),
         RecordSection("added", "- added"),
         RecordSection("fixed", "- fixed"),
     ))
     assert body.bump_rc_version(Version("1.2.3")) == Version("2.0.0rc1")
     assert body.bump_rc_version(Version("1.2.3rc1")) == Version("2.0.0rc1")
     assert body.bump_rc_version(Version("1.0.0rc1")) == Version("1.0.0rc2")
Example #4
0
 def test_append_lines(self):
     body = RecordBody((
         RecordSection("removed", "- removed"),
         RecordSection("added", "- added"),
         RecordSection("fixed", ""),
     ))
     body.append_lines("removed", "\n- new removed")
     assert body.get_section("removed").body == "- removed\n- new removed"
     body.append_lines("added", "\n")
     assert body.get_section("added").body == "- added"
Example #5
0
 def test_get_section(self):
     body = RecordBody((
         RecordSection("removed", "- removed"),
         RecordSection("added", "- added"),
         RecordSection("fixed", ""),
     ))
     assert body.get_section("removed").body == "- removed"
     assert body.get_section("added").body == "- added"
     assert body.get_section("fixed").body == ""
     with pytest.raises(ValueError):
         body.get_section("unknown")
Example #6
0
 def test_append_to_all(self):
     body = RecordBody((
         RecordSection("removed", "- removed"),
         RecordSection("added", "- added"),
         RecordSection("fixed", ""),
     ))
     body.append_to_all(" postfix")
     assert body.get_section("removed").body == "- removed postfix"
     assert body.get_section("added").body == "- added postfix"
     assert body.get_section("fixed").body == ""
     assert body.get_section("security").body == ""
Example #7
0
    def test_render(self):
        assert RecordSection("added", "test").render() == "### Added\ntest"
        assert RecordSection("added", "\ntest").render() == "### Added\ntest"
        assert RecordSection("changed", "\n").render() == "### Changed"

        section = RecordSection("changed", "\n")
        section.body = "\n\ntest\ntest2\n"
        assert section.render() == "### Changed\ntest\ntest2"

        with pytest.raises(ValueError):
            RecordSection("none", "body")
Example #8
0
    def append_section(self, title: str, text: str) -> None:
        """
        Append new lines to release notes.

        Arguments:
            title -- Section title.
            text -- Section text to append.
        """
        new_record = RecordBody(sections=[RecordSection(title, text)])
        self.merge(new_record)
Example #9
0
 def __init__(
     self,
     sections: Iterable[RecordSection] = (),
     prefix: str = "",
     postfix: str = "",
 ) -> None:
     self._sections: Dict[str, RecordSection] = {
         i: RecordSection(i, "")
         for i in SECTION_TITLES
     }
     self.prefix: str = prefix
     self.postfix: str = postfix
     for section in sections:
         self.append_lines(section.title, section.body)
Example #10
0
    def test_bump_version(self):
        body = RecordBody((
            RecordSection("removed", "- removed"),
            RecordSection("added", "- added"),
            RecordSection("fixed", "- fixed"),
        ))
        assert body.bump_version(Version("1.2.3")) == Version("2.0.0")

        body = RecordBody((
            RecordSection("removed", ""),
            RecordSection("added", "- added"),
            RecordSection("fixed", "- fixed"),
        ))
        assert body.bump_version(Version("1.2.3")) == Version("1.3.0")

        body = RecordBody((
            RecordSection("removed", ""),
            RecordSection("added", ""),
            RecordSection("fixed", "- fixed"),
        ))
        assert body.bump_version(Version("1.2.3")) == Version("1.2.4")
        assert RecordBody().bump_version(Version("1.2.3")) == Version("1.2.4")
Example #11
0
 def test_get_merged(self):
     body = RecordBody((
         RecordSection("removed", "- removed"),
         RecordSection("added", ""),
         RecordSection("fixed", "- fixed"),
     ))
     body2 = RecordBody((
         RecordSection("removed", "- removed2"),
         RecordSection("added", "- added"),
         RecordSection("fixed", ""),
     ))
     merged = body.get_merged(body2)
     assert merged.get_section("removed").body == "- removed\n- removed2"
     assert merged.get_section("added").body == "- added"
     assert merged.get_section("fixed").body == "- fixed"
     assert merged.get_section("security").body == ""
Example #12
0
 def test_clear(self):
     body = RecordBody([RecordSection("added", "- added")],
                       prefix="prefix",
                       postfix="postfix")
     body.clear()
     assert body.render() == ""
Example #13
0
 def test_sanitize(self):
     body = RecordBody([RecordSection("added", "- added")],
                       prefix="prefix",
                       postfix="postfix")
     body.sanitize()
     assert body.render() == "### Added\n- added"
Example #14
0
 def test_append_lines(self):
     section = RecordSection("changed", "test\n")
     section.append_lines("\n\ntest2\n")
     assert section.render() == "### Changed\ntest\ntest2"
     section.append_lines("test3")
     assert section.render() == "### Changed\ntest\ntest2\ntest3"
     section.append_lines("\n")
     assert section.render() == "### Changed\ntest\ntest2\ntest3"
Example #15
0
 def test_is_valid_title(self):
     assert RecordSection.is_valid_title("added") is True
     assert RecordSection.is_valid_title("notes") is False