Skip to content

Commit 503b628

Browse files
committed
Add test for check_cpython_repo_branch
1 parent 4e2c0c6 commit 503b628

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

tests/test_run_release.py

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import contextlib
33
import io
44
import tarfile
5+
from contextlib import nullcontext as does_not_raise
56
from pathlib import Path
67
from typing import cast
78

89
import pytest
910

1011
import run_release
1112
from release import ReleaseShelf, Tag
13+
from run_release import ReleaseException
1214

1315

1416
@pytest.mark.parametrize(
@@ -26,8 +28,7 @@ def test_check_sigstore_version_success(version) -> None:
2628
)
2729
def test_check_sigstore_version_exception(version) -> None:
2830
with pytest.raises(
29-
run_release.ReleaseException,
30-
match="Sigstore version not detected or not valid",
31+
ReleaseException, match="Sigstore version not detected or not valid"
3132
):
3233
run_release.check_sigstore_version(version)
3334

@@ -46,21 +47,67 @@ def test_extract_github_owner(url: str, expected: str) -> None:
4647

4748
def test_invalid_extract_github_owner() -> None:
4849
with pytest.raises(
49-
run_release.ReleaseException,
50+
ReleaseException,
5051
match="Could not parse GitHub owner from 'origin' remote URL: "
5152
"https://example.com",
5253
):
5354
run_release.extract_github_owner("https://example.com")
5455

5556

57+
@pytest.mark.parametrize(
58+
["release_tag", "git_current_branch", "expectation"],
59+
[
60+
# Success cases
61+
("3.15.0rc1", "3.15\n", does_not_raise()),
62+
("3.15.0b1", "3.15\n", does_not_raise()),
63+
("3.15.0a6", "main\n", does_not_raise()),
64+
("3.14.3", "3.14\n", does_not_raise()),
65+
("3.13.12", "3.13\n", does_not_raise()),
66+
# Failure cases
67+
(
68+
"3.15.0rc1",
69+
"main\n",
70+
pytest.raises(ReleaseException, match="on main branch, expected 3.15"),
71+
),
72+
(
73+
"3.15.0b1",
74+
"main\n",
75+
pytest.raises(ReleaseException, match="on main branch, expected 3.15"),
76+
),
77+
(
78+
"3.15.0a6",
79+
"3.14\n",
80+
pytest.raises(ReleaseException, match="on 3.14 branch, expected main"),
81+
),
82+
(
83+
"3.14.3",
84+
"main\n",
85+
pytest.raises(ReleaseException, match="on main branch, expected 3.14"),
86+
),
87+
],
88+
)
89+
def test_check_cpython_repo_branch(
90+
monkeypatch, release_tag: str, git_current_branch: str, expectation
91+
) -> None:
92+
# Arrange
93+
db = {"release": Tag(release_tag), "git_repo": "/fake/repo"}
94+
monkeypatch.setattr(
95+
run_release.subprocess,
96+
"check_output",
97+
lambda *args, **kwargs: git_current_branch,
98+
)
99+
100+
# Act / Assert
101+
with expectation:
102+
run_release.check_cpython_repo_branch(cast(ReleaseShelf, db))
103+
104+
56105
def test_check_magic_number() -> None:
57106
db = {
58107
"release": Tag("3.14.0rc1"),
59108
"git_repo": str(Path(__file__).parent / "magicdata"),
60109
}
61-
with pytest.raises(
62-
run_release.ReleaseException, match="Magic numbers in .* don't match"
63-
):
110+
with pytest.raises(ReleaseException, match="Magic numbers in .* don't match"):
64111
run_release.check_magic_number(cast(ReleaseShelf, db))
65112

66113

0 commit comments

Comments
 (0)