Exemplo n.º 1
0
def test_check_server_started_if_errored(mocker, qtbot):
    """Test that .check_server_started() does not do anything if server state
    is ERROR."""
    fake_open = mocker.patch('spyder_notebook.utils.servermanager.open')
    mock_QTimer = mocker.patch('spyder_notebook.utils.servermanager.QTimer',
                               spec=QTimer)
    mock_process = mocker.Mock(spec=QProcess, processId=lambda: 7)
    server_process = ServerProcess(
        mock_process, 'notebookdir', 'interpreter', state=ServerState.ERROR)
    serverManager = ServerManager()

    serverManager._check_server_started(server_process)

    fake_open.assert_not_called()
    mock_QTimer.assert_not_called()
    assert server_process.state == ServerState.ERROR
Exemplo n.º 2
0
def test_check_server_started_if_started(mocker, qtbot):
    """Test that .check_server_started() emits sig_server_started if there
    is a json file with the correct name and completes the server info."""
    fake_open = mocker.patch('spyder_notebook.utils.servermanager.open',
                             mocker.mock_open(read_data='{"foo": 42}'))
    mocker.patch('spyder_notebook.utils.servermanager.jupyter_runtime_dir',
                 return_value='runtimedir')
    mock_process = mocker.Mock(spec=QProcess, processId=lambda: 7)
    server_process = ServerProcess(mock_process, 'notebookdir', 'interpreter')
    serverManager = ServerManager()

    with qtbot.waitSignal(serverManager.sig_server_started):
        serverManager._check_server_started(server_process)

    fake_open.assert_called_once_with(
        osp.join('runtimedir', 'nbserver-7.json'), encoding='utf-8')
    assert server_process.state == ServerState.RUNNING
    assert server_process.server_info == {'foo': 42}
Exemplo n.º 3
0
def test_check_server_started_if_timed_out(mocker, qtbot):
    """Test that .check_server_started() emits sig_server_timed_out if after
    an hour there is still no json file."""
    fake_open = mocker.patch('spyder_notebook.utils.servermanager.open',
                             side_effect=OSError)
    mocker.patch('spyder_notebook.utils.servermanager.jupyter_runtime_dir',
                 return_value='runtimedir')
    mock_process = mocker.Mock(spec=QProcess, processId=lambda: 7)
    one_hour_ago = datetime.datetime.now() - datetime.timedelta(hours=1)
    server_process = ServerProcess(
        mock_process, 'notebookdir', 'interpreter', starttime=one_hour_ago)
    serverManager = ServerManager()

    with qtbot.waitSignal(serverManager.sig_server_timed_out):
        serverManager._check_server_started(server_process)

    fake_open.assert_called_once_with(
        osp.join('runtimedir', 'nbserver-7.json'), encoding='utf-8')
    assert server_process.state == ServerState.TIMED_OUT
Exemplo n.º 4
0
def test_check_server_started_if_not_started(mocker, qtbot):
    """Test that .check_server_started() repeats itself on a timer if there
    is no json file with the correct name."""
    fake_open = mocker.patch('spyder_notebook.utils.servermanager.open',
                             side_effect=OSError)
    mocker.patch('spyder_notebook.utils.servermanager.jupyter_runtime_dir',
                 return_value='runtimedir')
    mock_QTimer = mocker.patch('spyder_notebook.utils.servermanager.QTimer',
                               spec=QTimer)
    mock_process = mocker.Mock(spec=QProcess, processId=lambda: 7)
    server_process = ServerProcess(mock_process, 'notebookdir', 'interpreter')
    serverManager = ServerManager()

    serverManager._check_server_started(server_process)

    fake_open.assert_called_once_with(
        osp.join('runtimedir', 'nbserver-7.json'), encoding='utf-8')
    assert server_process.state == ServerState.STARTING
    mock_QTimer.singleShot.assert_called_once()