@@ -108,24 +108,36 @@ async def test_buildbotapi_stable_builders() -> None:
108108 assert "stable" in all_builders [3 ].tags
109109
110110
111+ # The most recent builds in success.json and failure.json
112+ SUCCESS_COMPLETE_AT = 1728312495
113+ FAILURE_COMPLETE_AT = 1734198808
114+ DAY = buildbotapi .SECONDS_PER_DAY
115+
116+
111117@pytest .mark .asyncio
112118@pytest .mark .parametrize (
113- ["json_data" , "expected" ],
119+ ["json_data" , "now" , " expected" ],
114120 [
115- ("tests/buildbotapi/success.json" , False ),
116- ("tests/buildbotapi/failure.json" , True ),
117- ("tests/buildbotapi/no-builds.json" , False ),
121+ # Recent builds: judged on their result
122+ ("tests/buildbotapi/success.json" , SUCCESS_COMPLETE_AT + DAY , False ),
123+ ("tests/buildbotapi/failure.json" , FAILURE_COMPLETE_AT + DAY , True ),
124+ ("tests/buildbotapi/no-builds.json" , FAILURE_COMPLETE_AT + DAY , False ),
125+ # Just inside the staleness cutoff: failure still counts
126+ ("tests/buildbotapi/failure.json" , FAILURE_COMPLETE_AT + 13 * DAY , True ),
127+ # Stale build (last run > 14 days ago): builder ignored
128+ ("tests/buildbotapi/failure.json" , FAILURE_COMPLETE_AT + 15 * DAY , False ),
118129 ],
119130)
120- async def test_buildbotapi_is_builder_failing_currently_yes (
121- json_data : str , expected : bool
131+ async def test_buildbotapi_is_builder_failing_currently (
132+ monkeypatch : pytest . MonkeyPatch , json_data : str , now : int , expected : bool
122133) -> None :
123134 # Arrange
124135 mock_session = AsyncMock (aiohttp .ClientSession )
125136 mock_session .get .return_value .__aenter__ .return_value .status = 200
126137 mock_session .get .return_value .__aenter__ .return_value .text .return_value = load (
127138 json_data
128139 )
140+ monkeypatch .setattr ("buildbotapi.time.time" , lambda : now )
129141 api = buildbotapi .BuildBotAPI (mock_session )
130142 builder = buildbotapi .Builder (builderid = 3 )
131143
0 commit comments