22import contextlib
33import io
44import tarfile
5+ from collections .abc import Iterator
56from contextlib import nullcontext as does_not_raise
67from pathlib import Path
7- from typing import cast
8+ from typing import Any , cast
89
910import pytest
1011
1718 "version" ,
1819 ["sigstore 4.0.0" , "sigstore 4.1.0" ],
1920)
20- def test_check_sigstore_version_success (version ) -> None :
21+ def test_check_sigstore_version_success (version : str ) -> None :
2122 # Verify runs with no exceptions
2223 run_release .check_sigstore_version (version )
2324
@@ -26,7 +27,7 @@ def test_check_sigstore_version_success(version) -> None:
2627 "version" ,
2728 ["sigstore 3.4.0" , "sigstore 3.6.2" , "sigstore 3.6.6" , "" ],
2829)
29- def test_check_sigstore_version_exception (version ) -> None :
30+ def test_check_sigstore_version_exception (version : str ) -> None :
3031 with pytest .raises (
3132 ReleaseException , match = "Sigstore version not detected or not valid"
3233 ):
@@ -89,13 +90,15 @@ def test_invalid_extract_github_owner() -> None:
8990 ],
9091)
9192def test_check_cpython_repo_branch (
92- monkeypatch , release_tag : str , git_current_branch : str , expectation
93+ monkeypatch : pytest .MonkeyPatch ,
94+ release_tag : str ,
95+ git_current_branch : str ,
96+ expectation : contextlib .AbstractContextManager [object ],
9397) -> None :
9498 # Arrange
9599 db = {"release" : Tag (release_tag ), "git_repo" : "/fake/repo" }
96100 monkeypatch .setattr (
97- run_release .subprocess ,
98- "check_output" ,
101+ "run_release.subprocess.check_output" ,
99102 lambda * args , ** kwargs : git_current_branch ,
100103 )
101104
@@ -116,23 +119,26 @@ def test_check_cpython_repo_branch(
116119 ],
117120)
118121def test_check_cpython_repo_age (
119- monkeypatch , age_seconds : int , user_continues : bool | None , expectation
122+ monkeypatch : pytest .MonkeyPatch ,
123+ age_seconds : int ,
124+ user_continues : bool | None ,
125+ expectation : contextlib .AbstractContextManager [object ],
120126) -> None :
121127 # Arrange
122128 db = {"release" : Tag ("3.15.0a6" ), "git_repo" : "/fake/repo" }
123129 current_time = 1700000000
124130 commit_timestamp = current_time - age_seconds
125131
126- def fake_check_output (cmd , ** kwargs ) :
132+ def fake_check_output (cmd : list [ str ] , ** kwargs : Any ) -> str :
127133 cmd_str = " " .join (cmd )
128134 if "%ct" in cmd_str :
129135 return f"{ commit_timestamp } \n "
130136 if "%cr" in cmd_str :
131137 return "some time ago\n "
132138 return ""
133139
134- monkeypatch .setattr (run_release .subprocess , " check_output" , fake_check_output )
135- monkeypatch .setattr (run_release .time , " time" , lambda : current_time )
140+ monkeypatch .setattr (" run_release.subprocess. check_output" , fake_check_output )
141+ monkeypatch .setattr (" run_release.time. time" , lambda : current_time )
136142 if user_continues is not None :
137143 monkeypatch .setattr (run_release , "ask_question" , lambda _ : user_continues )
138144
@@ -161,12 +167,12 @@ def prepare_fake_docs(tmp_path: Path, content: str) -> None:
161167
162168
163169@contextlib .contextmanager
164- def fake_answers (monkeypatch : pytest .MonkeyPatch , answers : list [str ]) -> None :
170+ def fake_answers (monkeypatch : pytest .MonkeyPatch , answers : list [str ]) -> Iterator [ None ] :
165171 """Monkey-patch input() to give the given answers. All must be consumed."""
166172
167173 answers_left = list (answers )
168174
169- def fake_input (question ) :
175+ def fake_input (question : str ) -> str :
170176 print (question , "--" , answers_left [0 ])
171177 return answers_left .pop (0 )
172178
@@ -207,7 +213,9 @@ def test_check_doc_unreleased_version_ok(tmp_path: Path) -> None:
207213 run_release .check_doc_unreleased_version (cast (ReleaseShelf , db ))
208214
209215
210- def test_check_doc_unreleased_version_not_ok (monkeypatch , tmp_path : Path ) -> None :
216+ def test_check_doc_unreleased_version_not_ok (
217+ monkeypatch : pytest .MonkeyPatch , tmp_path : Path
218+ ) -> None :
211219 prepare_fake_docs (
212220 tmp_path ,
213221 "<div>New in 3.13.0rc1 (unreleased)</div>" ,
@@ -220,7 +228,9 @@ def test_check_doc_unreleased_version_not_ok(monkeypatch, tmp_path: Path) -> Non
220228 run_release .check_doc_unreleased_version (cast (ReleaseShelf , db ))
221229
222230
223- def test_check_doc_unreleased_version_waived (monkeypatch , tmp_path : Path ) -> None :
231+ def test_check_doc_unreleased_version_waived (
232+ monkeypatch : pytest .MonkeyPatch , tmp_path : Path
233+ ) -> None :
224234 prepare_fake_docs (
225235 tmp_path ,
226236 "<div>New in 3.13.0rc1 (unreleased)</div>" ,
0 commit comments