forked from python/release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_release.py
More file actions
117 lines (97 loc) · 3.16 KB
/
test_release.py
File metadata and controls
117 lines (97 loc) · 3.16 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
from pathlib import Path
from typing import cast
import pytest
from pytest_mock import MockerFixture
import release
@pytest.mark.parametrize(
["test_editor", "expected"],
[
("vim", ["vim", "README.rst"]),
("bbedit --wait", ["bbedit", "--wait", "README.rst"]),
],
)
def test_manual_edit(
mocker: MockerFixture,
monkeypatch: pytest.MonkeyPatch,
test_editor: str,
expected: list[str],
) -> None:
# Arrange
monkeypatch.setenv("EDITOR", test_editor)
mock_run_cmd = mocker.patch("release.run_cmd")
# Act
release.manual_edit("README.rst")
# Assert
mock_run_cmd.assert_called_once_with(expected)
def test_task(mocker: MockerFixture) -> None:
# Arrange
db = {"mock": "mock"}
my_task = mocker.Mock()
task = release.Task(my_task, "My task")
# Act
task(cast(release.ReleaseShelf, db))
# Assert
assert task.description == "My task"
assert task.function == my_task
my_task.assert_called_once_with(cast(release.ReleaseShelf, db))
def test_tweak_patchlevel(tmp_path: Path) -> None:
# Arrange
tag = release.Tag("3.14.0b2")
original_patchlevel_file = Path(__file__).parent / "patchlevel.h"
patchlevel_file = tmp_path / "patchlevel.h"
patchlevel_file.write_text(original_patchlevel_file.read_text())
# Act
release.tweak_patchlevel(tag, filename=str(patchlevel_file))
# Assert
new_contents = patchlevel_file.read_text()
for expected in (
"#define PY_MAJOR_VERSION 3",
"#define PY_MINOR_VERSION 14",
"#define PY_MICRO_VERSION 0",
"#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_BETA",
"#define PY_RELEASE_SERIAL 2",
'#define PY_VERSION "3.14.0b2"',
):
assert expected in new_contents
@pytest.mark.parametrize(
["test_tag", "expected_version", "expected_underline"],
[
(
"3.14.0a6",
"This is Python version 3.14.0 alpha 6",
"=====================================",
),
(
"3.14.0b2",
"This is Python version 3.14.0 beta 2",
"====================================",
),
(
"3.14.0rc2",
"This is Python version 3.14.0 release candidate 2",
"=================================================",
),
(
"3.14.1",
"This is Python version 3.14.1",
"=============================",
),
],
)
def test_tweak_readme(
tmp_path: Path, test_tag: str, expected_version: str, expected_underline: str
) -> None:
# Arrange
tag = release.Tag(test_tag)
original_readme_file = Path(__file__).parent / "README.rst"
original_contents = original_readme_file.read_text()
readme_file = tmp_path / "README.rst"
readme_file.write_text(original_contents)
# Act
release.tweak_readme(tag, filename=str(readme_file))
# Assert
original_lines = original_contents.splitlines()
new_lines = readme_file.read_text().splitlines()
assert new_lines[0] == expected_version
assert new_lines[1] == expected_underline
assert new_lines[2:] == original_lines[2:]