summaryrefslogtreecommitdiff
path: root/script/test_bump_changelog.py
blob: fcdbd22527fd345e240850a51293169c8991ab82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import pytest
from bump_changelog import VersionType, get_next_version, transform_content


@pytest.mark.parametrize(
    "version,version_type,expected",
    [
        ["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"],
    ],
)
def test_get_next_version(version, version_type, expected):
    assert get_next_version(version, version_type) == expected


@pytest.mark.parametrize(
    "old_content,version,expected_error",
    [
        [
            """
What's New in astroid 2.7.0?
============================
Release Date: TBA

What's New in astroid 2.6.1?
============================
Release Date: TBA

What's New in astroid 2.6.0?
============================
Release Date: TBA
""",
            "2.6.1",
            r"There should be only two release dates 'TBA' \(2.6.1 and 2.7.0\)",
        ],
        [
            """===================
astroid's ChangeLog
===================

What's New in astroid 2.6.0?
============================
Release Date: TBA
""",
            "2.6.1",
            "text for this version '2.6.1' did not exists",
        ],
        [
            """
What's New in astroid 2.6.2?
============================
Release Date: TBA

What's New in astroid 2.6.1?
============================
Release Date: 2012-02-05
""",
            "2.6.1",
            "the next version '2.6.2' already exists",
        ],
        [
            """
What's New in astroid 3.0.0?
============================
Release Date: TBA

What's New in astroid 2.6.10?
============================
Release Date: TBA
""",
            "3.0.0",
            r"There should be only one release date 'TBA' \(3.0.0\)",
        ],
        [
            """
What's New in astroid 2.7.0?
============================
Release Date: TBA

What's New in astroid 2.6.10?
============================
Release Date: TBA
""",
            "2.7.0",
            r"There should be only one release date 'TBA' \(2.7.0\)",
        ],
    ],
)
def test_update_content_error(old_content, version, expected_error):
    with pytest.raises(AssertionError, match=expected_error):
        transform_content(old_content, version)


def test_update_content():
    old_content = """
===================
astroid's ChangeLog
===================

What's New in astroid 2.6.1?
============================
Release Date: TBA
"""
    expected_beginning = """
===================
astroid's ChangeLog
===================

What's New in astroid 2.6.2?
============================
Release Date: TBA



What's New in astroid 2.6.1?
============================
Release Date: 20"""

    new_content = transform_content(old_content, "2.6.1")
    assert new_content.startswith(expected_beginning)