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
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"
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")
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"
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")
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 == ""
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")
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)
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)
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")
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 == ""
def test_clear(self): body = RecordBody([RecordSection("added", "- added")], prefix="prefix", postfix="postfix") body.clear() assert body.render() == ""
def test_sanitize(self): body = RecordBody([RecordSection("added", "- added")], prefix="prefix", postfix="postfix") body.sanitize() assert body.render() == "### Added\n- added"
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"
def test_is_valid_title(self): assert RecordSection.is_valid_title("added") is True assert RecordSection.is_valid_title("notes") is False