本文整理汇总了Python中mu.modes.python3.PythonMode类的典型用法代码示例。如果您正苦于以下问题:Python PythonMode类的具体用法?Python PythonMode怎么用?Python PythonMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PythonMode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_python_run_toggle_on
def test_python_run_toggle_on():
"""
Check the handler for clicking run starts the new process and updates the
UI state.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
view.button_bar.slots = {
'debug': mock.MagicMock(),
'modes': mock.MagicMock(),
'run': mock.MagicMock(),
}
pm = PythonMode(editor, view)
pm.runner = None
def runner(pm=pm):
pm.runner = True
pm.run_script = mock.MagicMock(side_effect=runner)
pm.run_toggle(None)
pm.run_script.assert_called_once_with()
slot = pm.view.button_bar.slots['run']
assert slot.setIcon.call_count == 1
slot.setText.assert_called_once_with('Stop')
slot.setToolTip.assert_called_once_with('Stop your Python script.')
pm.view.button_bar.slots['debug'].setEnabled.assert_called_once_with(False)
pm.view.button_bar.slots['modes'].setEnabled.assert_called_once_with(False)
开发者ID:martinohanlon,项目名称:mu,代码行数:27,代码来源:test_python3.py
示例2: test_python_add_repl
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.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()
view.button_bar.slots['repl'].setEnabled.assert_called_once_with(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:willingc,项目名称:mu,代码行数:33,代码来源:test_python3.py
示例3: test_python_api
def test_python_api():
"""
Make sure the API definition is as expected.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
pm = PythonMode(editor, view)
result = pm.api()
assert result == SHARED_APIS + PYTHON3_APIS + PI_APIS
开发者ID:martinohanlon,项目名称:mu,代码行数:9,代码来源:test_python3.py
示例4: test_python_remove_plotter_reset_focus
def test_python_remove_plotter_reset_focus():
"""
Ensure the button states are returned to normal before calling super
method.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
pm = PythonMode(editor, view)
pm.remove_plotter()
view.current_tab.setFocus.assert_called_once_with()
开发者ID:martinohanlon,项目名称:mu,代码行数:10,代码来源:test_python3.py
示例5: test_python_stop_script_no_runner
def test_python_stop_script_no_runner():
"""
If the script is cancelled before the child process is created ensure
nothing breaks and the UI is reset.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
pm = PythonMode(editor, view)
pm.runner = None
pm.stop_script()
view.remove_python_runner.assert_called_once_with()
开发者ID:martinohanlon,项目名称:mu,代码行数:11,代码来源:test_python3.py
示例6: test_python_debug
def test_python_debug():
"""
Ensure Python3 mode hands over running of the script to the debug mode.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
pm = PythonMode(editor, view)
pm.debug(None)
editor.change_mode.assert_called_once_with('debugger')
assert editor.mode == 'debugger'
editor.modes['debugger'].start.assert_called_once_with()
开发者ID:martinohanlon,项目名称:mu,代码行数:11,代码来源:test_python3.py
示例7: test_python_remove_repl
def test_python_remove_repl():
"""
Make sure the REPL is removed properly.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
pm = PythonMode(editor, view)
pm.stop_kernel = mock.MagicMock()
pm.remove_repl()
pm.stop_kernel.emit.assert_called_once_with()
view.button_bar.slots['repl'].setEnabled.assert_called_once_with(False)
开发者ID:willingc,项目名称:mu,代码行数:11,代码来源:test_python3.py
示例8: test_python_run_script_needs_saving
def test_python_run_script_needs_saving():
"""
If the file hasn't been saved yet (it's unnamed), prompt the user to save
it.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
view.current_tab.path = None
pm = PythonMode(editor, view)
pm.stop_script = mock.MagicMock()
pm.run_script()
editor.save.assert_called_once_with()
开发者ID:martinohanlon,项目名称:mu,代码行数:12,代码来源:test_python3.py
示例9: test_python_run_script_no_editor
def test_python_run_script_no_editor():
"""
If there's no active tab, there can be no runner either.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
view.current_tab = None
pm = PythonMode(editor, view)
pm.stop_script = mock.MagicMock()
pm.run_script()
assert pm.runner is None
pm.stop_script.assert_called_once_with()
开发者ID:martinohanlon,项目名称:mu,代码行数:12,代码来源:test_python3.py
示例10: test_python_remove_repl
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,代码行数:12,代码来源:test_python3.py
示例11: test_python_stop_resets_focus
def test_python_stop_resets_focus():
"""
Check that, when a child process is killed, the current
tab regains focus.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
pm = PythonMode(editor, view)
mock_runner = mock.MagicMock()
pm.runner = mock_runner
pm.stop_script()
view.current_tab.setFocus.assert_called_once_with()
开发者ID:martinohanlon,项目名称:mu,代码行数:12,代码来源:test_python3.py
示例12: test_python_run_script_uses_editor_save
def test_python_run_script_uses_editor_save():
"""The run code uses the common editor save code, invoking
encoding checks and useful messages
"""
editor = mock.MagicMock()
view = mock.MagicMock()
view.current_tab.IsModified.return_value = True
view.current_tab.path = "foo"
view.current_tab.text = mock.MagicMock(return_value="foo")
pm = PythonMode(editor, view)
pm.stop_script = mock.MagicMock()
pm.run_script()
editor.save_tab_to_file.assert_called_once_with(view.current_tab)
开发者ID:martinohanlon,项目名称:mu,代码行数:13,代码来源:test_python3.py
示例13: test_python_run_toggle_on_cancelled
def test_python_run_toggle_on_cancelled():
"""
Ensure the button states are correct if running an unsaved script is
cancelled before the process is allowed to start. See issue #338.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
pm = PythonMode(editor, view)
pm.runner = None
pm.run_script = mock.MagicMock()
pm.run_toggle(None)
pm.run_script.assert_called_once_with()
slot = pm.view.button_bar.slots['run']
assert slot.setIcon.call_count == 0
开发者ID:martinohanlon,项目名称:mu,代码行数:14,代码来源:test_python3.py
示例14: test_python_stop_script
def test_python_stop_script():
"""
Check that the child process is killed, the runner cleaned up and UI
is reset.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
pm = PythonMode(editor, view)
mock_runner = mock.MagicMock()
pm.runner = mock_runner
pm.stop_script()
mock_runner.process.kill.assert_called_once_with()
mock_runner.process.waitForFinished.assert_called_once_with()
assert pm.runner is None
开发者ID:martinohanlon,项目名称:mu,代码行数:14,代码来源:test_python3.py
示例15: test_python_remove_plotter
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,代码行数:14,代码来源:test_python3.py
示例16: test_python_on_kernel_stop
def test_python_on_kernel_stop():
"""
Ensure everything REPL based is cleaned up when this handler is called.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
view.button_bar.slots = {
'repl': mock.MagicMock(),
}
pm = PythonMode(editor, view)
pm.on_kernel_stop()
assert pm.repl_kernel_manager is None
view.button_bar.slots['repl'].setEnabled.assert_called_once_with(True)
editor.show_status_message.assert_called_once_with('REPL stopped.')
assert pm.kernel_runner is None
开发者ID:martinohanlon,项目名称:mu,代码行数:15,代码来源:test_python3.py
示例17: test_python_on_kernel_start
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)
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)
view.button_bar.slots['repl'].setEnabled.assert_called_once_with(True)
editor.show_status_message.assert_called_once_with('REPL started.')
开发者ID:willingc,项目名称:mu,代码行数:16,代码来源:test_python3.py
示例18: test_python_run_toggle_off
def test_python_run_toggle_off():
"""
Check the handler for clicking run stops the process and reverts the UI
state.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
pm = PythonMode(editor, view)
pm.runner = True
pm.stop_script = mock.MagicMock()
pm.run_toggle(None)
pm.stop_script.assert_called_once_with()
slot = pm.view.button_bar.slots['run']
assert slot.setIcon.call_count == 1
slot.setText.assert_called_once_with('Run')
slot.setToolTip.assert_called_once_with('Run your Python script.')
pm.view.button_bar.slots['debug'].setEnabled.assert_called_once_with(True)
开发者ID:lordmauve,项目名称:mu,代码行数:17,代码来源:test_python3.py
示例19: test_python_run_script
def test_python_run_script():
"""
Ensure that running the script launches the process as expected.
"""
editor = mock.MagicMock()
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)
mock_runner.process.waitForStarted.assert_called_once_with()
开发者ID:lordmauve,项目名称:mu,代码行数:19,代码来源:test_python3.py
示例20: test_python_toggle_plotter
def test_python_toggle_plotter():
"""
Ensure toggling the plotter causes it to be added/removed.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
pm = PythonMode(editor, view)
pm.add_plotter = mock.MagicMock()
pm.remove_plotter = mock.MagicMock()
pm.toggle_plotter()
pm.add_plotter.assert_called_once_with()
pm.plotter = True
pm.toggle_plotter()
pm.remove_plotter.assert_called_once_with()
开发者ID:martinohanlon,项目名称:mu,代码行数:14,代码来源:test_python3.py
注:本文中的mu.modes.python3.PythonMode类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论