当前位置: 首页>>代码示例>>Python>>正文


Python PythonMode.set_buttons方法代码示例

本文整理汇总了Python中mu.modes.python3.PythonMode.set_buttons方法的典型用法代码示例。如果您正苦于以下问题:Python PythonMode.set_buttons方法的具体用法?Python PythonMode.set_buttons怎么用?Python PythonMode.set_buttons使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mu.modes.python3.PythonMode的用法示例。


在下文中一共展示了PythonMode.set_buttons方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_python_on_kernel_start

# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import set_buttons [as 别名]
def test_python_on_kernel_start():
    """
    Ensure the handler for when the kernel has started updates the UI such that
    the kernel manager and kernel client are used to add the Jupyter widget to
    the UI, the REPL button is re-enabled and a status update is shown.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PythonMode(editor, view)
    pm.set_buttons = mock.MagicMock()
    mock_kernel_manager = mock.MagicMock()
    mock_client = mock.MagicMock()
    pm.on_kernel_start(mock_kernel_manager, mock_client)
    view.add_jupyter_repl.assert_called_once_with(mock_kernel_manager,
                                                  mock_client)
    pm.set_buttons.assert_called_once_with(repl=True)
    editor.show_status_message.assert_called_once_with('REPL started.')
    # Check button states are set according to what other aspects of the mode
    # are currently enabled.
    # With Runner enabled.
    pm.set_buttons.reset_mock()
    pm.runner = True
    pm.on_kernel_start(mock_kernel_manager, mock_client)
    assert pm.set_buttons.call_count == 2
    assert pm.set_buttons.call_args_list[0][1]['repl'] is True
    assert pm.set_buttons.call_args_list[1][1]['plotter'] is False
    # With Plotter enabled.
    pm.set_buttons.reset_mock()
    pm.runner = False
    pm.plotter = True
    pm.on_kernel_start(mock_kernel_manager, mock_client)
    assert pm.set_buttons.call_count == 2
    assert pm.set_buttons.call_args_list[0][1]['repl'] is True
    assert pm.set_buttons.call_args_list[1][1]['run'] is False
    assert pm.set_buttons.call_args_list[1][1]['debug'] is False
开发者ID:martinohanlon,项目名称:mu,代码行数:37,代码来源:test_python3.py

示例2: test_python_add_plotter

# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import set_buttons [as 别名]
def test_python_add_plotter():
    """
    Ensure the plotter is added as expected.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PythonMode(editor, view)
    pm.set_buttons = mock.MagicMock()
    pm.add_plotter()
    view.add_python3_plotter.assert_called_once_with(pm)
    assert pm.plotter
    pm.set_buttons.assert_called_once_with(debug=False)
    # Check button states are updated depending on other aspects of the mode
    # being enabled.
    # REPL active.
    pm.set_buttons.reset_mock()
    pm.repl = True
    pm.add_plotter()
    assert pm.set_buttons.call_count == 2
    assert pm.set_buttons.call_args_list[0][1]['debug'] is False
    assert pm.set_buttons.call_args_list[1][1]['run'] is False
    # Runner active.
    pm.set_buttons.reset_mock()
    pm.repl = False
    pm.runner = True
    pm.add_plotter()
    assert pm.set_buttons.call_count == 2
    assert pm.set_buttons.call_args_list[0][1]['debug'] is False
    assert pm.set_buttons.call_args_list[1][1]['repl'] is False
开发者ID:martinohanlon,项目名称:mu,代码行数:31,代码来源:test_python3.py

示例3: test_python_on_data_flood

# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import set_buttons [as 别名]
def test_python_on_data_flood():
    """
    Ensure that Python 3 mode cleans up correctly after a data flood of the
    plotter is detected: reset the buttons, stop either the REPL or runner and
    then call the base method.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PythonMode(editor, view)
    pm.set_buttons = mock.MagicMock()
    pm.run_toggle = mock.MagicMock()
    pm.remove_repl = mock.MagicMock()
    pm.runner = True
    with mock.patch('builtins.super') as mock_super:
        pm.on_data_flood()
        pm.set_buttons.assert_called_once_with(run=True, repl=True, debug=True)
        pm.run_toggle.assert_called_once_with(None)
        mock_super().on_data_flood.assert_called_once_with()
    pm.set_buttons.reset_mock()
    pm.runner = False
    pm.kernel_runner = True
    with mock.patch('builtins.super') as mock_super:
        pm.on_data_flood()
        pm.set_buttons.assert_called_once_with(run=True, repl=True, debug=True)
        pm.remove_repl.assert_called_once_with()
        mock_super().on_data_flood.assert_called_once_with()
开发者ID:martinohanlon,项目名称:mu,代码行数:28,代码来源:test_python3.py

示例4: test_python_add_repl

# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import set_buttons [as 别名]
def test_python_add_repl():
    """
    Check the REPL's kernal manager is configured correctly before being handed
    to the Jupyter widget in the view.
    """
    mock_qthread = mock.MagicMock()
    mock_kernel_runner = mock.MagicMock()
    editor = mock.MagicMock()
    editor.envars = [['name', 'value'], ]
    view = mock.MagicMock()
    pm = PythonMode(editor, view)
    pm.set_buttons = mock.MagicMock()
    pm.stop_kernel = mock.MagicMock()
    with mock.patch('mu.modes.python3.QThread', mock_qthread), \
            mock.patch('mu.modes.python3.KernelRunner', mock_kernel_runner):
        pm.add_repl()
    mock_qthread.assert_called_once_with()
    mock_kernel_runner.assert_called_once_with(cwd=pm.workspace_dir(),
                                               envars=editor.envars)
    assert pm.kernel_thread == mock_qthread()
    assert pm.kernel_runner == mock_kernel_runner()
    pm.set_buttons.assert_called_once_with(repl=False)
    pm.kernel_runner.moveToThread.assert_called_once_with(pm.kernel_thread)
    pm.kernel_runner.kernel_started.connect.\
        assert_called_once_with(pm.on_kernel_start)
    pm.kernel_runner.kernel_finished.connect.\
        assert_called_once_with(pm.kernel_thread.quit)
    pm.stop_kernel.connect.\
        assert_called_once_with(pm.kernel_runner.stop_kernel)
    pm.kernel_thread.started.connect.\
        assert_called_once_with(pm.kernel_runner.start_kernel)
    pm.kernel_thread.finished.connect.\
        assert_called_once_with(pm.on_kernel_stop)
    pm.kernel_thread.start.assert_called_once_with()
开发者ID:martinohanlon,项目名称:mu,代码行数:36,代码来源:test_python3.py

示例5: test_python_run_script

# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import set_buttons [as 别名]
def test_python_run_script():
    """
    Ensure that running the script launches the process as expected.
    """
    editor = mock.MagicMock()
    editor.envars = [['name', 'value']]
    view = mock.MagicMock()
    view.current_tab.path = '/foo/bar'
    view.current_tab.isModified.return_value = True
    view.current_tab.text = mock.MagicMock(return_value="abc")
    mock_runner = mock.MagicMock()
    view.add_python3_runner.return_value = mock_runner
    pm = PythonMode(editor, view)
    pm.run_script()
    editor.save_tab_to_file.assert_called_once_with(view.current_tab)
    view.add_python3_runner.assert_called_once_with('/foo/bar', '/foo',
                                                    interactive=True,
                                                    envars=editor.envars)
    mock_runner.process.waitForStarted.assert_called_once_with()
    # Check the buttons are set to the correct state when other aspects of the
    # mode are also in play.
    pm.set_buttons = mock.MagicMock()
    pm.kernel_runner = True
    pm.run_script()
    pm.set_buttons.assert_called_once_with(plotter=False)
    pm.set_buttons.reset_mock()
    pm.kernel_runner = False
    pm.plotter = True
    pm.run_script()
    pm.set_buttons.assert_called_once_with(repl=False)
开发者ID:martinohanlon,项目名称:mu,代码行数:32,代码来源:test_python3.py

示例6: test_python_remove_repl

# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import set_buttons [as 别名]
def test_python_remove_repl():
    """
    Make sure the REPL is removed properly.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    pm = PythonMode(editor, view)
    pm.set_buttons = mock.MagicMock()
    pm.stop_kernel = mock.MagicMock()
    pm.remove_repl()
    pm.stop_kernel.emit.assert_called_once_with()
    pm.set_buttons.assert_called_once_with(repl=False)
开发者ID:martinohanlon,项目名称:mu,代码行数:14,代码来源:test_python3.py

示例7: test_python_remove_plotter

# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import set_buttons [as 别名]
def test_python_remove_plotter():
    """
    Ensure the button states are returned to normal before calling super
    method.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    with mock.patch('builtins.super') as mock_super:
        pm = PythonMode(editor, view)
        pm.set_buttons = mock.MagicMock()
        mock_super.reset_mock()
        pm.remove_plotter()
        pm.set_buttons.assert_called_once_with(run=True, repl=True, debug=True)
        mock_super().remove_plotter.assert_called_once_with()
开发者ID:martinohanlon,项目名称:mu,代码行数:16,代码来源:test_python3.py

示例8: test_python_run_script

# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import set_buttons [as 别名]
def test_python_run_script():
    """
    Ensure that running the script launches the process as expected.
    """
    editor = mock.MagicMock()
    editor.envars = [['name', 'value']]
    view = mock.MagicMock()
    view.current_tab.path = '/foo'
    view.current_tab.isModified.return_value = True
    mock_runner = mock.MagicMock()
    view.add_python3_runner.return_value = mock_runner
    pm = PythonMode(editor, view)
    pm.workspace_dir = mock.MagicMock(return_value='/bar')
    with mock.patch('builtins.open') as oa, \
            mock.patch('mu.modes.python3.write_and_flush'):
        pm.run_script()
        oa.assert_called_once_with('/foo', 'w', newline='')
    view.add_python3_runner.assert_called_once_with('/foo', '/bar',
                                                    interactive=True,
                                                    envars=editor.envars)
    mock_runner.process.waitForStarted.assert_called_once_with()
    # Check the buttons are set to the correct state when other aspects of the
    # mode are also in play.
    pm.set_buttons = mock.MagicMock()
    pm.kernel_runner = True
    with mock.patch('builtins.open') as oa, \
            mock.patch('mu.modes.python3.write_and_flush'):
        pm.run_script()
    pm.set_buttons.assert_called_once_with(plotter=False)
    pm.set_buttons.reset_mock()
    pm.kernel_runner = False
    pm.plotter = True
    with mock.patch('builtins.open') as oa, \
            mock.patch('mu.modes.python3.write_and_flush'):
        pm.run_script()
    pm.set_buttons.assert_called_once_with(repl=False)
开发者ID:ZanderBrown,项目名称:mu,代码行数:38,代码来源:test_python3.py


注:本文中的mu.modes.python3.PythonMode.set_buttons方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。