forked from commitizen-tools/commitizen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_changelog_meta.py
More file actions
165 lines (117 loc) · 3.88 KB
/
test_changelog_meta.py
File metadata and controls
165 lines (117 loc) · 3.88 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import os
import pytest
from commitizen import changelog
CHANGELOG_A = """
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
- Start using "changelog" over "change log" since it's the common usage.
## [1.0.0] - 2017-06-20
### Added
- New visual identity by [@tylerfortune8](https://github.com/tylerfortune8).
- Version navigation.
""".strip()
CHANGELOG_B = """
## [Unreleased]
- Start using "changelog" over "change log" since it's the common usage.
## 1.2.0
""".strip()
CHANGELOG_C = """
# Unreleased
## v1.0.0
"""
CHANGELOG_D = """
## Unreleased
- Start using "changelog" over "change log" since it's the common usage.
"""
@pytest.fixture
def changelog_a_file():
changelog_path = "tests/CHANGELOG.md"
with open(changelog_path, "w") as f:
f.write(CHANGELOG_A)
yield changelog_path
os.remove(changelog_path)
@pytest.fixture
def changelog_b_file():
changelog_path = "tests/CHANGELOG.md"
with open(changelog_path, "w") as f:
f.write(CHANGELOG_B)
yield changelog_path
os.remove(changelog_path)
@pytest.fixture
def changelog_c_file():
changelog_path = "tests/CHANGELOG.md"
with open(changelog_path, "w") as f:
f.write(CHANGELOG_C)
yield changelog_path
os.remove(changelog_path)
@pytest.fixture
def changelog_d_file():
changelog_path = "tests/CHANGELOG.md"
with open(changelog_path, "w") as f:
f.write(CHANGELOG_D)
yield changelog_path
os.remove(changelog_path)
VERSIONS_EXAMPLES = [
("## [1.0.0] - 2017-06-20", "1.0.0"),
(
"# [10.0.0-next.3](https://github.com/angular/angular/compare/10.0.0-next.2...10.0.0-next.3) (2020-04-22)",
"10.0.0-next.3",
),
("### 0.19.1 (Jan 7, 2020)", "0.19.1"),
("## 1.0.0", "1.0.0"),
("## v1.0.0", "1.0.0"),
("## v1.0.0 - (2012-24-32)", "1.0.0"),
("# version 2020.03.24", "2020.03.24"),
("## [Unreleased]", None),
("All notable changes to this project will be documented in this file.", None),
("# Changelog", None),
("### Bug Fixes", None),
]
@pytest.mark.parametrize("line_from_changelog,output_version", VERSIONS_EXAMPLES)
def test_changelog_detect_version(line_from_changelog, output_version):
version = changelog.parse_version_from_markdown(line_from_changelog)
assert version == output_version
TITLES_EXAMPLES = [
("## [1.0.0] - 2017-06-20", "##"),
("## [Unreleased]", "##"),
("# Unreleased", "#"),
]
@pytest.mark.parametrize("line_from_changelog,output_title", TITLES_EXAMPLES)
def test_parse_title_type_of_line(line_from_changelog, output_title):
title = changelog.parse_title_type_of_line(line_from_changelog)
assert title == output_title
def test_get_metadata_from_a(changelog_a_file):
meta = changelog.get_metadata(changelog_a_file)
assert meta == {
"latest_version": "1.0.0",
"latest_version_position": 10,
"unreleased_end": 10,
"unreleased_start": 7,
}
def test_get_metadata_from_b(changelog_b_file):
meta = changelog.get_metadata(changelog_b_file)
assert meta == {
"latest_version": "1.2.0",
"latest_version_position": 3,
"unreleased_end": 3,
"unreleased_start": 0,
}
def test_get_metadata_from_c(changelog_c_file):
meta = changelog.get_metadata(changelog_c_file)
assert meta == {
"latest_version": "1.0.0",
"latest_version_position": 3,
"unreleased_end": 3,
"unreleased_start": 1,
}
def test_get_metadata_from_d(changelog_d_file):
meta = changelog.get_metadata(changelog_d_file)
assert meta == {
"latest_version": None,
"latest_version_position": None,
"unreleased_end": 2,
"unreleased_start": 1,
}