async def test_add_no_class_doesnt_call_create(session_manager, mock_session_create): # Patch the type to class dict with patch("robot_server.service.session.manager.SessionTypeToClass", new={}): with pytest.raises(SessionCreationException): await session_manager.add(SessionType.null, SessionMetaData()) mock_session_create.assert_not_called()
async def test_get_by_type(session_manager): sessions = await asyncio.gather(*[ session_manager.add(SessionType.null, SessionMetaData()) for _ in range(5) ] # noqa: e501 ) assert session_manager.get(SessionType.null) == tuple(sessions) assert session_manager.get(SessionType.calibration_check) == tuple()
async def test_remove_inactive_session(session_manager, session): active_session = await session_manager.add(SessionType.null, SessionMetaData()) await session_manager.remove(session.meta.identifier) assert session_manager._active.active_id is active_session.meta.identifier
async def test_remove_calls_cleanup(session_manager): session = await session_manager.add(SessionType.null, SessionMetaData()) session.clean_up = MagicMock(side_effect=side_effect) await session_manager.remove(session.meta.identifier) session.clean_up.assert_called_once()
async def session(session_manager, loop) -> BaseSession: """An added session""" return await session_manager.add(session_type=SessionType.null, session_meta_data=SessionMetaData())
async def test_add_fails(self, session_manager): with pytest.raises(RobotServerError): await session_manager.add(session_type=SessionType.default, session_meta_data=SessionMetaData())
async def test_add_fails(self, session_manager): with pytest.raises(SessionCreationException): await session_manager.add(session_type=SessionType.default, session_meta_data=SessionMetaData())