|
1 | 1 | from typing import Any, Callable, List, Optional
|
2 | 2 |
|
3 | 3 | import pytest
|
| 4 | +from freezegun import freeze_time # type: ignore [import-untyped] |
4 | 5 | from pytest_mock import MockerFixture
|
5 | 6 | from urwid import Widget
|
6 | 7 |
|
@@ -109,14 +110,21 @@ def test_set_footer_text_with_duration(
|
109 | 110 | duration: Optional[float] = 5.3,
|
110 | 111 | ) -> None:
|
111 | 112 | mocker.patch(VIEW + ".get_random_help", return_value=["some help text"])
|
112 |
| - mock_sleep = mocker.patch("time.sleep") |
| 113 | + mocked_alarm = mocker.patch(CONTROLLER + ".loop.set_alarm_in") |
113 | 114 |
|
114 |
| - view.set_footer_text([custom_text], duration=duration) |
| 115 | + with freeze_time() as frozen_datetime: |
| 116 | + view.set_footer_text([custom_text], duration=duration) |
115 | 117 |
|
116 |
| - view.frame.footer.set_text.assert_has_calls( |
117 |
| - [mocker.call([custom_text]), mocker.call(["some help text"])] |
118 |
| - ) |
119 |
| - mock_sleep.assert_called_once_with(duration) |
| 118 | + view.frame.footer.set_text.assert_called_once_with([custom_text]) |
| 119 | + assert view.controller.update_screen.call_count == 1 |
| 120 | + |
| 121 | + frozen_datetime.tick(duration) |
| 122 | + |
| 123 | + # Trigger the alarm |
| 124 | + alarm_callback = mocked_alarm.call_args[0][1] |
| 125 | + alarm_callback(None, None) |
| 126 | + |
| 127 | + view.frame.footer.set_text.assert_called_with(["some help text"]) |
120 | 128 | assert view.controller.update_screen.call_count == 2
|
121 | 129 |
|
122 | 130 | @pytest.mark.parametrize(
|
|
0 commit comments