Skip to content

Commit 71e350d

Browse files
committed
Test release.Tag
1 parent 3ce88e5 commit 71e350d

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
exclude_also =
66
# Don't complain if non-runnable code isn't run:
77
if __name__ == .__main__.:
8+
def main

tests/test_release_tag.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
from subprocess import CompletedProcess
2+
3+
import pytest
4+
from pytest_mock import MockerFixture
5+
6+
import release
7+
8+
9+
def test_tag() -> None:
10+
# Arrange
11+
tag_name = "3.12.2"
12+
13+
# Act
14+
tag = release.Tag(tag_name)
15+
16+
# Assert
17+
assert str(tag) == "3.12.2"
18+
assert str(tag.next_minor_release()) == "3.13.0a0"
19+
assert tag.as_tuple() == (3, 12, 2, "f", 0)
20+
assert tag.branch == "3.12"
21+
assert tag.gitname == "v3.12.2"
22+
assert tag.is_alpha_release is False
23+
assert tag.is_feature_freeze_release is False
24+
assert tag.is_release_candidate is False
25+
assert tag.nickname == "3122"
26+
assert tag.normalized() == "3.12.2"
27+
28+
29+
def test_tag_phase() -> None:
30+
# Arrange
31+
alpha = release.Tag("3.13.0a7")
32+
beta1 = release.Tag("3.13.0b1")
33+
beta4 = release.Tag("3.13.0b4")
34+
rc = release.Tag("3.13.0rc3")
35+
36+
# Act / Assert
37+
assert alpha.is_alpha_release is True
38+
assert alpha.is_feature_freeze_release is False
39+
assert alpha.is_release_candidate is False
40+
41+
assert beta1.is_alpha_release is False
42+
assert beta1.is_feature_freeze_release is True
43+
assert beta1.is_release_candidate is False
44+
45+
assert beta4.is_alpha_release is False
46+
assert beta4.is_feature_freeze_release is False
47+
assert beta4.is_release_candidate is False
48+
49+
assert rc.is_alpha_release is False
50+
assert rc.is_feature_freeze_release is False
51+
assert rc.is_release_candidate is True
52+
53+
54+
def test_tag_committed_at_not_found() -> None:
55+
# Arrange
56+
tag = release.Tag("3.12.2")
57+
58+
# Act / Assert
59+
with pytest.raises(SystemExit):
60+
tag.committed_at()
61+
62+
63+
def test_tag_committed(mocker: MockerFixture) -> None:
64+
# Arrange
65+
tag = release.Tag("3.12.2")
66+
67+
proc = CompletedProcess([], 0)
68+
proc.stdout = b"1707250784"
69+
mocker.patch("subprocess.run", return_value=proc)
70+
71+
# Act / Assert
72+
assert str(tag.committed_at) == "2024-02-06 20:19:44+00:00"
73+
74+
75+
def test_tag_dot(mocker: MockerFixture) -> None:
76+
# Arrange
77+
tag_name = "."
78+
mocker.patch("os.getcwd", return_value="/path/to/3.12.2")
79+
80+
# Act
81+
tag = release.Tag(tag_name)
82+
83+
# Assert
84+
assert str(tag) == "3.12.2"
85+
86+
87+
def test_tag_invalid() -> None:
88+
# Arrange
89+
tag_name = "bleep"
90+
91+
# Act / Assert
92+
with pytest.raises(SystemExit):
93+
release.Tag(tag_name)

0 commit comments

Comments
 (0)