11import pytest
22from pytest_mock import MockerFixture
3+ from socketio import AsyncServer # pyright: ignore[reportMissingTypeStubs]
34from vbl_aquarium .models .ephys_link import EphysLinkOptions , GetManipulatorsResponse
45
56import ephys_link .back_end .server
67from ephys_link .back_end .platform_handler import PlatformHandler
78from ephys_link .back_end .server import Server
89from ephys_link .front_end .console import Console
10+ from ephys_link .utils .constants import SERVER_NOT_INITIALIZED_ERROR
911from tests .conftest import DUMMY_STRING , DUMMY_STRING_LIST
1012
1113
@@ -30,6 +32,21 @@ def proxy_client(self, platform_handler: PlatformHandler, console: Console) -> S
3032 """Fixture for server as proxy client."""
3133 return Server (EphysLinkOptions (use_proxy = True ), platform_handler , console )
3234
35+ def test_failed_server_init (
36+ self , platform_handler : PlatformHandler , console : Console , mocker : MockerFixture
37+ ) -> None :
38+ """Server should raise error if sio is not an AsyncServer."""
39+ # Mock out the AsyncServer init.
40+ patched_async_server = mocker .patch .object (AsyncServer , "__new__" )
41+
42+ # Act
43+ with pytest .raises (TypeError ) as init_error :
44+ _ = Server (EphysLinkOptions (use_proxy = False ), platform_handler , console )
45+
46+ # Assert
47+ patched_async_server .assert_called_once ()
48+ assert init_error .value .args [0 ] == SERVER_NOT_INITIALIZED_ERROR
49+
3350 def test_launch_server (
3451 self , server : Server , platform_handler : PlatformHandler , console : Console , mocker : MockerFixture
3552 ) -> None :
0 commit comments