Example #1
0
def test_kernel_runner_start_kernel():
    """
    Ensure the start_kernel method eventually emits the kernel_started signal
    with the associated kernel manager and kernel client objects for
    subsequent use.
    """
    mock_kernel_manager = mock.MagicMock()
    mock_client = mock.MagicMock()
    mock_kernel_manager.client.return_value = mock_client
    envars = [["name", "value"]]
    kr = KernelRunner(cwd="/a/path/to/mu_code", envars=envars)
    kr.kernel_started = mock.MagicMock()
    mock_os = mock.MagicMock()
    mock_os.environ = {}
    mock_os.pathsep = os.pathsep
    mock_os.path.dirname.return_value = ("/Applications/mu-editor.app"
                                         "/Contents/Resources/app/mu")
    mock_kernel_manager_class = mock.MagicMock()
    mock_kernel_manager_class.return_value = mock_kernel_manager
    with mock.patch("mu.modes.python3.os", mock_os), mock.patch(
            "mu.modes.python3.QtKernelManager",
            mock_kernel_manager_class), mock.patch("sys.platform", "darwin"):
        kr.start_kernel()
    mock_os.chdir.assert_called_once_with("/a/path/to/mu_code")
    assert mock_os.environ["name"] == "value"
    expected_paths = sys.path + [MODULE_DIR]
    assert mock_os.environ["PYTHONPATH"] == os.pathsep.join(expected_paths)
    assert kr.repl_kernel_manager == mock_kernel_manager
    mock_kernel_manager_class.assert_called_once_with()
    mock_kernel_manager.start_kernel.assert_called_once_with()
    assert kr.repl_kernel_client == mock_client
    kr.kernel_started.emit.assert_called_once_with(mock_kernel_manager,
                                                   mock_client)
Example #2
0
def test_kernel_runner_start_kernel_pythonpath_exists():
    """
    Ensure  that MODULE_DIR is added to the existing PYTHONPATH
    """
    mock_kernel_manager = mock.MagicMock()
    mock_client = mock.MagicMock()
    mock_kernel_manager.client.return_value = mock_client
    envars = [["name", "value"]]
    kr = KernelRunner(cwd="/a/path/to/mu_code", envars=envars)
    kr.kernel_started = mock.MagicMock()
    mock_os = mock.MagicMock()
    mock_os.environ = {"PYTHONPATH": "foo"}
    mock_os.pathsep = os.pathsep
    mock_os.path.dirname.return_value = ("/Applications/mu-editor.app"
                                         "/Contents/Resources/app/mu")
    mock_kernel_manager_class = mock.MagicMock()
    mock_kernel_manager_class.return_value = mock_kernel_manager
    with mock.patch("mu.modes.python3.os", mock_os), mock.patch(
            "mu.modes.python3.QtKernelManager",
            mock_kernel_manager_class), mock.patch("sys.platform", "darwin"):
        kr.start_kernel()
    mock_os.chdir.assert_called_once_with("/a/path/to/mu_code")
    assert mock_os.environ["name"] == "value"
    expected_paths = ["foo"] + [MODULE_DIR]
    assert mock_os.environ["PYTHONPATH"] == os.pathsep.join(expected_paths)
    assert kr.repl_kernel_manager == mock_kernel_manager
    mock_kernel_manager_class.assert_called_once_with()
    mock_kernel_manager.start_kernel.assert_called_once_with()
    assert kr.repl_kernel_client == mock_client
    kr.kernel_started.emit.assert_called_once_with(mock_kernel_manager,
                                                   mock_client)
Example #3
0
def test_kernel_runner_start_kernel():
    """
    Ensure the start_kernel method eventually emits the kernel_started signal
    with the associated kernel manager and kernel client objects for
    subsequent use.
    """
    mock_kernel_manager = mock.MagicMock()
    mock_client = mock.MagicMock()
    mock_kernel_manager.client.return_value = mock_client
    envars = [['name', 'value'], ]
    kr = KernelRunner(cwd='/a/path/to/mu_code', envars=envars)
    kr.kernel_started = mock.MagicMock()
    mock_os = mock.MagicMock()
    mock_os.environ = {}
    mock_os.pathsep = os.pathsep
    mock_os.path.dirname.return_value = ('/Applications/mu-editor.app'
                                         '/Contents/Resources/app/mu')
    mock_kernel_manager_class = mock.MagicMock()
    mock_kernel_manager_class.return_value = mock_kernel_manager
    with mock.patch('mu.modes.python3.os', mock_os), \
            mock.patch('mu.modes.python3.QtKernelManager',
                       mock_kernel_manager_class), \
            mock.patch('sys.platform', 'darwin'):
        kr.start_kernel()
    mock_os.chdir.assert_called_once_with('/a/path/to/mu_code')
    assert mock_os.environ['name'] == 'value'
    assert mock_os.environ['PYTHONPATH'] == os.pathsep.join(sys.path)
    assert kr.repl_kernel_manager == mock_kernel_manager
    mock_kernel_manager_class.assert_called_once_with()
    mock_kernel_manager.start_kernel.assert_called_once_with()
    assert kr.repl_kernel_client == mock_client
    kr.kernel_started.emit.assert_called_once_with(mock_kernel_manager,
                                                   mock_client)
Example #4
0
def test_kernel_runner_start_kernel():
    """
    Ensure the start_kernel method eventually emits the kernel_started signal
    with the associated kernel manager and kernel client objects for
    subsequent use.
    """
    mock_kernel_manager = mock.MagicMock()
    mock_client = mock.MagicMock()
    mock_kernel_manager.client.return_value = mock_client
    envars = [['name', 'value'], ]
    kr = KernelRunner(cwd='/a/path/to/mu_code', envars=envars)
    kr.kernel_started = mock.MagicMock()
    mock_os = mock.MagicMock()
    mock_os.environ = {}
    mock_os.pathsep = os.pathsep
    mock_os.path.dirname.return_value = ('/Applications/mu-editor.app'
                                         '/Contents/Resources/app/mu')
    mock_kernel_manager_class = mock.MagicMock()
    mock_kernel_manager_class.return_value = mock_kernel_manager
    with mock.patch('mu.modes.python3.os', mock_os), \
            mock.patch('mu.modes.python3.QtKernelManager',
                       mock_kernel_manager_class), \
            mock.patch('sys.platform', 'darwin'):
        kr.start_kernel()
    mock_os.chdir.assert_called_once_with('/a/path/to/mu_code')
    assert mock_os.environ['name'] == 'value'
    assert mock_os.environ['PYTHONPATH'] == os.pathsep.join(sys.path)
    assert kr.repl_kernel_manager == mock_kernel_manager
    mock_kernel_manager_class.assert_called_once_with()
    mock_kernel_manager.start_kernel.assert_called_once_with()
    assert kr.repl_kernel_client == mock_client
    kr.kernel_started.emit.assert_called_once_with(mock_kernel_manager,
                                                   mock_client)
Example #5
0
def test_kernel_runner_start_kernel():
    """
    Ensure the start_kernel method eventually emits the kernel_started signal
    with the associated kernel manager and kernel client objects for
    subsequent use.
    """
    mock_kernel_manager = mock.MagicMock()
    mock_client = mock.MagicMock()
    mock_kernel_manager.client.return_value = mock_client
    envars = [['name', 'value'], ]
    kr = KernelRunner(cwd='/a/path/to/mu_code', envars=envars)
    kr.kernel_started = mock.MagicMock()
    mock_os = mock.MagicMock()
    mock_os.environ = {}
    mock_kernel_manager_class = mock.MagicMock()
    mock_kernel_manager_class.return_value = mock_kernel_manager
    with mock.patch('mu.modes.python3.os', mock_os), \
            mock.patch('mu.modes.python3.QtKernelManager',
                       mock_kernel_manager_class):
        kr.start_kernel()
    mock_os.chdir.assert_called_once_with('/a/path/to/mu_code')
    assert mock_os.environ['name'] == 'value'
    assert kr.repl_kernel_manager == mock_kernel_manager
    mock_kernel_manager_class.assert_called_once_with()
    mock_kernel_manager.start_kernel.assert_called_once_with()
    assert kr.repl_kernel_client == mock_client
    kr.kernel_started.emit.assert_called_once_with(mock_kernel_manager,
                                                   mock_client)
Example #6
0
def test_kernel_runner_start_kernel():
    """
    Ensure the start_kernel method eventually emits the kernel_started signal
    with the associated kernel manager and kernel client objects for
    subsequent use.
    """
    mock_kernel_manager = mock.MagicMock()
    mock_client = mock.MagicMock()
    mock_kernel_manager.client.return_value = mock_client
    envars = [
        ['name', 'value'],
    ]
    kr = KernelRunner(cwd='/a/path/to/mu_code', envars=envars)
    kr.kernel_started = mock.MagicMock()
    mock_os = mock.MagicMock()
    mock_os.environ = {}
    mock_kernel_manager_class = mock.MagicMock()
    mock_kernel_manager_class.return_value = mock_kernel_manager
    with mock.patch('mu.modes.python3.os', mock_os), \
            mock.patch('mu.modes.python3.QtKernelManager',
                       mock_kernel_manager_class):
        kr.start_kernel()
    mock_os.chdir.assert_called_once_with('/a/path/to/mu_code')
    assert mock_os.environ['name'] == 'value'
    assert kr.repl_kernel_manager == mock_kernel_manager
    mock_kernel_manager_class.assert_called_once_with()
    mock_kernel_manager.start_kernel.assert_called_once_with()
    assert kr.repl_kernel_client == mock_client
    kr.kernel_started.emit.assert_called_once_with(mock_kernel_manager,
                                                   mock_client)
Example #7
0
def test_kernel_runner_start_kernel():
    """
    Ensure the start_kernel method eventually emits the kernel_started signal
    with the associated kernel manager and kernel client objects for
    subsequent use.
    """
    mock_kernel_manager = mock.MagicMock()
    mock_client = mock.MagicMock()
    mock_kernel_manager.client.return_value = mock_client
    kr = KernelRunner()
    kr.kernel_started = mock.MagicMock()
    with mock.patch('mu.modes.python3.QtKernelManager',
                    return_value=mock_kernel_manager):
        kr.start_kernel()
    assert kr.repl_kernel_manager == mock_kernel_manager
    mock_kernel_manager.start_kernel.assert_called_once_with()
    assert kr.repl_kernel_client == mock_client
    kr.kernel_started.emit.assert_called_once_with(mock_kernel_manager,
                                                   mock_client)
Example #8
0
def test_kernel_runner_start_kernel_pythonpath_exists():
    """
    Ensure  that MODULE_DIR is added to the existing PYTHONPATH
    """
    mock_kernel_manager = mock.MagicMock()
    mock_client = mock.MagicMock()
    mock_kernel_manager.client.return_value = mock_client
    envars = [
        ['name', 'value'],
    ]
    kr = KernelRunner(cwd='/a/path/to/mu_code', envars=envars)
    kr.kernel_started = mock.MagicMock()
    mock_os = mock.MagicMock()
    mock_os.environ = {'PYTHONPATH': 'foo'}
    mock_os.pathsep = os.pathsep
    mock_os.path.dirname.return_value = ('/Applications/mu-editor.app'
                                         '/Contents/Resources/app/mu')
    mock_kernel_manager_class = mock.MagicMock()
    mock_kernel_manager_class.return_value = mock_kernel_manager
    with mock.patch('mu.modes.python3.os', mock_os), \
            mock.patch('mu.modes.python3.QtKernelManager',
                       mock_kernel_manager_class), \
            mock.patch('sys.platform', 'darwin'):
        kr.start_kernel()
    mock_os.chdir.assert_called_once_with('/a/path/to/mu_code')
    assert mock_os.environ['name'] == 'value'
    expected_paths = [
        'foo',
    ] + [
        MODULE_DIR,
    ]
    assert mock_os.environ['PYTHONPATH'] == os.pathsep.join(expected_paths)
    assert kr.repl_kernel_manager == mock_kernel_manager
    mock_kernel_manager_class.assert_called_once_with()
    mock_kernel_manager.start_kernel.assert_called_once_with()
    assert kr.repl_kernel_client == mock_client
    kr.kernel_started.emit.assert_called_once_with(mock_kernel_manager,
                                                   mock_client)
Example #9
0
def test_kernel_runner_stop_kernel():
    """
    Ensure the stop_kernel method eventually emits the kernel_finished
    signal once it has stopped the client communication channels and shutdown
    the kernel in the quickest way possible.
    """
    kr = KernelRunner(cwd='/a/path/to/mu_code')
    kr.repl_kernel_client = mock.MagicMock()
    kr.repl_kernel_manager = mock.MagicMock()
    kr.kernel_finished = mock.MagicMock()
    kr.stop_kernel()
    kr.repl_kernel_client.stop_channels.assert_called_once_with()
    kr.repl_kernel_manager.shutdown_kernel.assert_called_once_with(now=True)
    kr.kernel_finished.emit.assert_called_once_with()
Example #10
0
def test_kernel_runner_stop_kernel():
    """
    Ensure the stop_kernel method eventually emits the kernel_finished
    signal once it has stopped the client communication channels and shutdown
    the kernel in the quickest way possible.
    """
    kr = KernelRunner(cwd='/a/path/to/mu_code')
    kr.repl_kernel_client = mock.MagicMock()
    kr.repl_kernel_manager = mock.MagicMock()
    kr.kernel_finished = mock.MagicMock()
    kr.stop_kernel()
    kr.repl_kernel_client.stop_channels.assert_called_once_with()
    kr.repl_kernel_manager.shutdown_kernel.assert_called_once_with(now=True)
    kr.kernel_finished.emit.assert_called_once_with()
Example #11
0
def test_kernel_runner_stop_kernel():
    """
    Ensure the stop_kernel method eventually emits the kernel_finished
    signal once it has stopped the client communication channels and shutdown
    the kernel in the quickest way possible.
    """
    kr = KernelRunner(cwd="/a/path/to/mu_code", envars=[["name", "value"]])
    kr.repl_kernel_client = mock.MagicMock()
    kr.repl_kernel_manager = mock.MagicMock()
    kr.kernel_finished = mock.MagicMock()
    mock_os = mock.MagicMock()
    mock_os.environ = {"old_mu_context": "to_be_deleted"}
    with mock.patch("mu.modes.python3.os", mock_os):
        kr.stop_kernel()
    assert "old_mu_context" not in mock_os.environ
    assert len(mock_os.environ) == len(kr.default_envars)
    kr.repl_kernel_client.stop_channels.assert_called_once_with()
    kr.repl_kernel_manager.shutdown_kernel.assert_called_once_with(now=True)
    kr.kernel_finished.emit.assert_called_once_with()
Example #12
0
def test_kernel_runner_stop_kernel():
    """
    Ensure the stop_kernel method eventually emits the kernel_finished
    signal once it has stopped the client communication channels and shutdown
    the kernel in the quickest way possible.
    """
    kr = KernelRunner(cwd='/a/path/to/mu_code', envars=[['name', 'value'], ])
    kr.repl_kernel_client = mock.MagicMock()
    kr.repl_kernel_manager = mock.MagicMock()
    kr.kernel_finished = mock.MagicMock()
    mock_os = mock.MagicMock()
    mock_os.environ = {
        'old_mu_context': 'to_be_deleted',
    }
    with mock.patch('mu.modes.python3.os', mock_os):
        kr.stop_kernel()
    assert 'old_mu_context' not in mock_os.environ
    assert len(mock_os.environ) == len(kr.default_envars)
    kr.repl_kernel_client.stop_channels.assert_called_once_with()
    kr.repl_kernel_manager.shutdown_kernel.assert_called_once_with(now=True)
    kr.kernel_finished.emit.assert_called_once_with()