Skip to content

Commit a2465fc

Browse files
committed
Make Kivy clock tests deterministic
1 parent 7abdc0b commit a2465fc

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

tests/test_main.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,35 @@
77
from asyncssh import PermissionDenied
88
from enum_here import ScreenName, ServerState
99
from main import PythonHereApp
10+
from ui_here.server_screen_here import ServerScreenManager
1011
from version_here import __version__
1112

1213

1314
def test_dev_version_is_set():
1415
assert __version__ == "0.0.0"
1516

1617

17-
@pytest.mark.asyncio
18-
async def test_starting_server_screen_shown(app_instance):
19-
app_instance.root.ids.here_screen_manager.update()
20-
assert app_instance.root.ids.here_screen_manager.current == "starting_server"
18+
def test_server_screen_update_states(mocker):
19+
screen = SimpleNamespace(current=None)
20+
app = SimpleNamespace(
21+
ssh_server_config_ready=asyncio.Event(),
22+
ssh_server_started=asyncio.Event(),
23+
)
24+
mocker.patch("ui_here.server_screen_here.App.get_running_app", return_value=app)
25+
unschedule = mocker.patch("ui_here.server_screen_here.Clock.unschedule")
26+
27+
ServerScreenManager.update.__wrapped__(screen)
28+
assert screen.current == ServerState.not_configured
29+
30+
app.ssh_server_config_ready.set()
31+
ServerScreenManager.update.__wrapped__(screen)
32+
assert screen.current == ServerState.starting_server
33+
34+
app.ssh_server_started.set()
35+
screen.update_event = mocker.Mock()
36+
ServerScreenManager.update.__wrapped__(screen)
37+
assert screen.current == ServerState.ready
38+
unschedule.assert_called_once_with(screen.update_event)
2139

2240

2341
@pytest.mark.asyncio

0 commit comments

Comments
 (0)