本文整理汇总了Python中mu.modes.python3.PythonMode.run_script方法的典型用法代码示例。如果您正苦于以下问题:Python PythonMode.run_script方法的具体用法?Python PythonMode.run_script怎么用?Python PythonMode.run_script使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mu.modes.python3.PythonMode
的用法示例。
在下文中一共展示了PythonMode.run_script方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_python_run_script_no_editor
# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import run_script [as 别名]
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()
示例2: test_python_run_script_needs_saving
# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import run_script [as 别名]
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()
示例3: test_python_run_script_uses_editor_save
# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import run_script [as 别名]
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)
示例4: test_python_run_toggle_on
# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import run_script [as 别名]
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)
示例5: test_python_run_script
# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import run_script [as 别名]
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()
示例6: test_python_run_script
# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import run_script [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)
示例7: test_python_run_toggle_on_cancelled
# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import run_script [as 别名]
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
示例8: test_python_run_script
# 需要导入模块: from mu.modes.python3 import PythonMode [as 别名]
# 或者: from mu.modes.python3.PythonMode import run_script [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)