Skip to content

Commit 78b0309

Browse files
committed
Add test for check_cpython_repo_age
1 parent 503b628 commit 78b0309

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/test_run_release.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,43 @@ def test_check_cpython_repo_branch(
102102
run_release.check_cpython_repo_branch(cast(ReleaseShelf, db))
103103

104104

105+
@pytest.mark.parametrize(
106+
["age_seconds", "user_continues", "expectation"],
107+
[
108+
# Recent repo (< 1 day) - no question asked
109+
(3600, None, does_not_raise()),
110+
# Old repo (> 1 day) + user says yes
111+
(90000, True, does_not_raise()),
112+
# Old repo (> 1 day) + user says no
113+
(90000, False, pytest.raises(ReleaseException, match="repository is old")),
114+
],
115+
)
116+
def test_check_cpython_repo_age(
117+
monkeypatch, age_seconds: int, user_continues: bool | None, expectation
118+
) -> None:
119+
# Arrange
120+
db = {"release": Tag("3.15.0a6"), "git_repo": "/fake/repo"}
121+
current_time = 1700000000
122+
commit_timestamp = current_time - age_seconds
123+
124+
def fake_check_output(cmd, **kwargs):
125+
cmd_str = " ".join(cmd)
126+
if "%ct" in cmd_str:
127+
return f"{commit_timestamp}\n"
128+
if "%cr" in cmd_str:
129+
return "some time ago\n"
130+
return ""
131+
132+
monkeypatch.setattr(run_release.subprocess, "check_output", fake_check_output)
133+
monkeypatch.setattr(run_release.time, "time", lambda: current_time)
134+
if user_continues is not None:
135+
monkeypatch.setattr(run_release, "ask_question", lambda _: user_continues)
136+
137+
# Act / Assert
138+
with expectation:
139+
run_release.check_cpython_repo_age(cast(ReleaseShelf, db))
140+
141+
105142
def test_check_magic_number() -> None:
106143
db = {
107144
"release": Tag("3.14.0rc1"),

0 commit comments

Comments
 (0)