Exemple #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
Exemple #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"
Exemple #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")
Exemple #4
0
 def test_set_section(self):
     body = RecordBody((
         RecordSection("removed", "- removed"),
         RecordSection("added", "- added"),
         RecordSection("fixed", ""),
     ))
     body.set_section("removed", "- new removed")
     assert body.get_section("removed").body == "- new removed"
     body.set_section("added", "")
     assert body.get_section("added").body == ""
     with pytest.raises(ValueError):
         body.set_section("unknown", "")
Exemple #5
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 == ""
Exemple #6
0
    def _command_rc_version(self) -> str:
        old_version: Version = self._config.version
        if self.input:
            record_body = RecordBody.parse(self.input)
        else:
            record_body = self.changelog.get_unreleased().body

        return record_body.bump_rc_version(old_version).dumps()
Exemple #7
0
    def body(self) -> RecordBody:
        """
        Release body.
        """
        if self._record_body is None:
            self._record_body = RecordBody.parse(self._text)

        return self._record_body
Exemple #8
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"
Exemple #9
0
    def set_body(self, text: str) -> None:
        """
        Change record body to `text`.

        Logs changes.
        """
        old_body = self.body.clone()
        self._record_body = RecordBody.parse(text)
        self._log_changes(old_body)
Exemple #10
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)
Exemple #11
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")
Exemple #12
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 == ""
Exemple #13
0
 def _log_changes(self, old_body: RecordBody) -> None:
     for section_title in SECTION_TITLES:
         old_section = old_body.get_section(section_title)
         new_section = self.body.get_section(section_title)
         if new_section.body == old_section.body:
             continue
         if old_section.is_empty():
             if not new_section.is_empty():
                 self._logger.info(
                     f"{self.name} `{new_section.title}` section added")
         else:
             if new_section.is_empty():
                 self._logger.info(
                     f"{self.name} `{new_section.title}` section deleted")
             else:
                 self._logger.info(
                     f"{self.name} `{new_section.title}` section updated")
Exemple #14
0
    def _command_add(self) -> str:
        release_name = self.release_name
        changelog = self.changelog
        record = self._get_record(changelog, release_name)

        if self._config.section == SECTION_ALL:
            record.merge(RecordBody.parse(self.input))
        else:
            section_name = self._config.section
            record.append_section(section_name, self._as_md_list(self.input))

        if self._config.created:
            record.created = self._config.created

        changelog.update_release(record)
        self.save_changelog(changelog)
        return ""
Exemple #15
0
 def test_parse(self):
     assert RecordBody.parse("test").render() == "test"
     assert RecordBody.parse("Added: test").render() == "### Added\ntest"
     assert (RecordBody.parse("other\nAdded: test\nAdded: test2").render()
             == "other\n\n### Added\ntest\ntest2")
     assert (RecordBody.parse("### Added\n\ntest\n\n### Added\n\ntest2").
             render() == "### Added\ntest\ntest2")
     assert (RecordBody.parse("### Added\n\ntest\n## Other\n\ntest2").
             render() == "### Added\ntest\n\n## Other\n\ntest2")
     body = RecordBody.parse(
         "### Added\n\ntest\n\n```\n### Removed\nnot a section\n```\n## Other\n\ntest2"
     )
     assert [i.title for i in body.sections] == ["added"]
Exemple #16
0
 def _command_format(self) -> str:
     record_body = RecordBody.parse(self.input)
     record_body.sanitize()
     return record_body.render()
Exemple #17
0
 def test_clear(self):
     body = RecordBody([RecordSection("added", "- added")],
                       prefix="prefix",
                       postfix="postfix")
     body.clear()
     assert body.render() == ""
Exemple #18
0
 def test_clone(self):
     body = RecordBody(prefix="prefix", postfix="postfix")
     assert body.clone().render() == "prefix\n\npostfix"
Exemple #19
0
 def test_sanitize(self):
     body = RecordBody([RecordSection("added", "- added")],
                       prefix="prefix",
                       postfix="postfix")
     body.sanitize()
     assert body.render() == "### Added\n- added"
Exemple #20
0
 def test_parse_prefix_section(self):
     assert RecordBody._parse_prefix_section("Added: new added") == "added"
     assert RecordBody._parse_prefix_section("added:new added") == "added"
     assert RecordBody._parse_prefix_section("removed new added") == ""
     assert RecordBody._parse_prefix_section("removed new: added") == ""
     assert RecordBody._parse_prefix_section("") == ""