summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-29 14:25:32 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-29 18:17:19 +0200
commit90612181b24025841ac8eb60c007adb6d041de29 (patch)
tree6da158a3c7c2d740bb9c02ad98ca5a152d4770c4 /script
parent8efabe9e7f23515a1d4eeaf9c1e01ff5b48cdf68 (diff)
downloadastroid-git-90612181b24025841ac8eb60c007adb6d041de29.tar.gz
Add a function to get the next versions from the version
Diffstat (limited to 'script')
-rw-r--r--script/bump_changelog.py19
-rw-r--r--script/test_bump_changelog.py59
2 files changed, 62 insertions, 16 deletions
diff --git a/script/bump_changelog.py b/script/bump_changelog.py
index 69801536..30f46bc8 100644
--- a/script/bump_changelog.py
+++ b/script/bump_changelog.py
@@ -7,6 +7,7 @@ import enum
import logging
from datetime import datetime
from pathlib import Path
+from typing import List
DEFAULT_CHANGELOG_PATH = Path("ChangeLog")
@@ -53,6 +54,24 @@ def get_next_version(version: str, version_type: VersionType) -> str:
return ".".join(new_version)
+def get_next_versions(version: str, version_type: VersionType) -> List[str]:
+ if version_type == VersionType.PATCH:
+ # "2.6.1" => ["2.6.2"]
+ return [get_next_version(version, VersionType.PATCH)]
+ if version_type == VersionType.MINOR:
+ assert version.endswith(".0"), f"{version} does not look like a minor version"
+ # "2.6.0" => ["2.7.0", "2.6.1"]
+ next_minor_version = get_next_version(version, VersionType.MINOR)
+ next_patch_version = get_next_version(version, VersionType.PATCH)
+ return [next_minor_version, next_patch_version]
+ assert version.endswith(".0.0"), f"{version} does not look like a major version"
+ next_major_version = get_next_version(version, VersionType.MAJOR)
+ next_minor_version = get_next_version(next_major_version, VersionType.MINOR)
+ next_patch_version = get_next_version(next_major_version, VersionType.PATCH)
+ # "3.0.0" => ["3.1.0", "3.0.1"]
+ return [next_minor_version, next_patch_version]
+
+
def get_version_type(version: str) -> VersionType:
if version.endswith("0.0"):
version_type = VersionType.MAJOR
diff --git a/script/test_bump_changelog.py b/script/test_bump_changelog.py
index a52c1c72..5dfe7f60 100644
--- a/script/test_bump_changelog.py
+++ b/script/test_bump_changelog.py
@@ -1,28 +1,55 @@
import logging
import pytest
-from bump_changelog import VersionType, get_next_version, transform_content
+from bump_changelog import (
+ VersionType,
+ get_next_version,
+ get_next_versions,
+ transform_content,
+)
@pytest.mark.parametrize(
- "version,version_type,expected",
+ "version,version_type,expected_version,expected_versions",
[
- ["2.6.1", VersionType.PATCH, "2.6.2"],
- ["2.6.1", VersionType.MINOR, "2.7.0"],
- ["2.6.1", VersionType.MAJOR, "3.0.0"],
- ["2.6.1-dev0", VersionType.PATCH, "2.6.2"],
- ["2.6.1-dev0", VersionType.MINOR, "2.7.0"],
- ["2.6.1-dev0", VersionType.MAJOR, "3.0.0"],
- ["2.7.0", VersionType.PATCH, "2.7.1"],
- ["2.7.0", VersionType.MINOR, "2.8.0"],
- ["2.7.0", VersionType.MAJOR, "3.0.0"],
- ["2.0.0", VersionType.PATCH, "2.0.1"],
- ["2.0.0", VersionType.MINOR, "2.1.0"],
- ["2.0.0", VersionType.MAJOR, "3.0.0"],
+ ["2.6.1", VersionType.PATCH, "2.6.2", ["2.6.2"]],
+ [
+ "2.6.0",
+ VersionType.MINOR,
+ "2.7.0",
+ [
+ "2.7.0",
+ "2.6.1",
+ ],
+ ],
+ ["2.6.1", VersionType.MAJOR, "3.0.0", ["3.1.0", "3.0.1"]],
+ ["2.6.1-dev0", VersionType.PATCH, "2.6.2", ["2.6.2"]],
+ [
+ "2.6.1-dev0",
+ VersionType.MINOR,
+ "2.7.0",
+ [
+ "2.7.1",
+ "2.7.0",
+ ],
+ ],
+ ["2.6.1-dev0", VersionType.MAJOR, "3.0.0", ["3.1.0", "3.0.1"]],
+ ["2.7.0", VersionType.PATCH, "2.7.1", ["2.7.1"]],
+ ["2.7.0", VersionType.MINOR, "2.8.0", ["2.8.0", "2.7.1"]],
+ ["2.7.0", VersionType.MAJOR, "3.0.0", ["3.1.0", "3.0.1"]],
+ ["2.0.0", VersionType.PATCH, "2.0.1", ["2.0.1"]],
+ ["2.0.0", VersionType.MINOR, "2.1.0", ["2.1.0", "2.0.1"]],
+ ["2.0.0", VersionType.MAJOR, "3.0.0", ["3.1.0", "3.0.1"]],
],
)
-def test_get_next_version(version, version_type, expected):
- assert get_next_version(version, version_type) == expected
+def test_get_next_version(version, version_type, expected_version, expected_versions):
+ assert get_next_version(version, version_type) == expected_version
+ if (
+ version_type == VersionType.PATCH
+ or version_type == VersionType.MINOR
+ and version.endswith(".0")
+ ):
+ assert get_next_versions(version, version_type) == expected_versions
@pytest.mark.parametrize(