def test_get_server_with_server(mocker, nbdir, state, result, start):
    """Test that .get_server() returns a suitable server if it is accepting
    requests, and that it start up a new server unless a suitable server exists
    that is either starting up or running. Here, a suitable server is a server
    which renders the given notebook."""
    serverManager = ServerManager()
    mock_start = mocker.patch.object(serverManager, 'start_server')
    filename = osp.abspath('foo/ham.ipynb')
    server_info = mocker.Mock(spec=dict)
    server = ServerProcess(mocker.Mock(spec=QProcess),
                           osp.abspath(nbdir),
                           state=state,
                           server_info=server_info)
    serverManager.servers.append(server)

    res = serverManager.get_server(filename)

    if result:
        assert res == server_info
    else:
        assert res is None
    if start:
        mock_start.assert_called_once_with(filename)
    else:
        mock_start.assert_not_called()
def test_get_server_without_servers(mocker, start_arg):
    """Test that .get_server() calls .start_server() when there are no servers
    only if `start` is True."""
    serverManager = ServerManager()
    mock_start = mocker.patch.object(serverManager, 'start_server')
    filename = osp.abspath('ham.ipynb')

    res = serverManager.get_server(filename, start=start_arg)

    assert res is None
    if start_arg:
        mock_start.assert_called_once_with(filename)
    else:
        mock_start.assert_not_called()