diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-26 14:00:10 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-29 18:17:19 +0200 |
commit | 144d71d9333e19e04571c8b898bf095e903072ae (patch) | |
tree | ac04af99a1907518818fa2addf358dffa450d05e /script | |
parent | e0c565a192387b65ec703c88fff72946303bab14 (diff) | |
download | astroid-git-144d71d9333e19e04571c8b898bf095e903072ae.tar.gz |
Refactor of script/bump_changelog.py for easier tests
Diffstat (limited to 'script')
-rw-r--r-- | script/bump_changelog.py | 29 | ||||
-rw-r--r-- | script/test_bump_changelog.py | 4 |
2 files changed, 14 insertions, 19 deletions
diff --git a/script/bump_changelog.py b/script/bump_changelog.py index dae41e3e..991fa222 100644 --- a/script/bump_changelog.py +++ b/script/bump_changelog.py @@ -24,10 +24,13 @@ def main() -> None: parser = argparse.ArgumentParser(add_help=__doc__) parser.add_argument("version", help="The version we want to release") args = parser.parse_args() - if "dev" not in args.version: - version = args.version - next_version = get_next_version(version) - run(version, next_version) + if "dev" in args.version: + return + with open(DEFAULT_CHANGELOG_PATH) as f: + content = f.read() + content = transform_content(content, args.version) + with open(DEFAULT_CHANGELOG_PATH, "w") as f: + f.write(content) def get_next_version(version: str) -> str: @@ -41,23 +44,15 @@ def get_next_version(version: str) -> str: return ".".join(new_version) -def run(version: str, next_version: str) -> None: - with open(DEFAULT_CHANGELOG_PATH) as f: - content = f.read() - content = transform_content(content, version, next_version) - with open(DEFAULT_CHANGELOG_PATH, "w") as f: - f.write(content) - - -def transform_content(content: str, version: str, next_version: str) -> str: - wn_new_version = FULL_WHATS_NEW_TEXT.format(version=version) +def transform_content(content: str, version: str) -> str: + next_version = get_next_version(version) wn_next_version = FULL_WHATS_NEW_TEXT.format(version=next_version) # There is only one field where the release date is TBA assert content.count(RELEASE_DATE_TEXT) == 1, TBA_ERROR_MSG # There is already a release note for the version we want to release - assert content.count(wn_new_version) == 1, NEW_VERSION_ERROR_MSG.format( - version=version - ) + assert ( + content.count(FULL_WHATS_NEW_TEXT.format(version=version)) == 1 + ), NEW_VERSION_ERROR_MSG.format(version=version) # There is no release notes for the next version assert content.count(wn_next_version) == 0, NEXT_VERSION_ERROR_MSG.format( version=next_version diff --git a/script/test_bump_changelog.py b/script/test_bump_changelog.py index 4b9a23cf..adfd82a7 100644 --- a/script/test_bump_changelog.py +++ b/script/test_bump_changelog.py @@ -51,7 +51,7 @@ Release Date: 2012-02-05 ) def test_update_content_error(old_content, expected_error): with pytest.raises(AssertionError, match=expected_error): - transform_content(old_content, "2.6.1", "2.6.2") + transform_content(old_content, "2.6.1") def test_update_content(): @@ -79,5 +79,5 @@ What's New in astroid 2.6.1? ============================ Release Date: 20""" - new_content = transform_content(old_content, "2.6.1", "2.6.2") + new_content = transform_content(old_content, "2.6.1") assert new_content.startswith(expected_beginning) |