本文整理汇总了Python中mu.modes.microbit.MicrobitMode.flash方法的典型用法代码示例。如果您正苦于以下问题:Python MicrobitMode.flash方法的具体用法?Python MicrobitMode.flash怎么用?Python MicrobitMode.flash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mu.modes.microbit.MicrobitMode
的用法示例。
在下文中一共展示了MicrobitMode.flash方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_flash_path_specified_does_not_exist
# 需要导入模块: from mu.modes.microbit import MicrobitMode [as 别名]
# 或者: from mu.modes.microbit.MicrobitMode import flash [as 别名]
def test_flash_path_specified_does_not_exist():
"""
Ensure that if a micro:bit is not automatically found by uflash and the
user has previously specified a path to the device, then the hex is saved
in the specified location.
"""
with mock.patch('mu.logic.uflash.hexlify', return_value=''), \
mock.patch('mu.logic.uflash.embed_hex', return_value='foo'), \
mock.patch('mu.logic.uflash.find_microbit', return_value=None),\
mock.patch('mu.logic.os.path.exists', return_value=False),\
mock.patch('mu.logic.os.makedirs', return_value=None), \
mock.patch('mu.logic.uflash.save_hex', return_value=None) as s:
view = mock.MagicMock()
view.current_tab.text = mock.MagicMock(return_value='')
view.show_message = mock.MagicMock()
editor = mock.MagicMock()
mm = MicrobitMode(editor, view)
mm.user_defined_microbit_path = 'baz'
mm.flash()
message = 'Could not find an attached BBC micro:bit.'
information = ("Please ensure you leave enough time for the BBC"
" micro:bit to be attached and configured correctly"
" by your computer. This may take several seconds."
" Alternatively, try removing and re-attaching the"
" device or saving your work and restarting Mu if"
" the device remains unfound.")
view.show_message.assert_called_once_with(message, information)
assert s.call_count == 0
assert mm.user_defined_microbit_path is None
示例2: test_flash_without_device
# 需要导入模块: from mu.modes.microbit import MicrobitMode [as 别名]
# 或者: from mu.modes.microbit.MicrobitMode import flash [as 别名]
def test_flash_without_device():
"""
If no device is found and the user doesn't provide a path then ensure a
helpful status message is enacted.
"""
with mock.patch('mu.logic.uflash.hexlify', return_value=''), \
mock.patch('mu.logic.uflash.embed_hex', return_value='foo'), \
mock.patch('mu.logic.uflash.find_microbit', return_value=None), \
mock.patch('mu.logic.uflash.save_hex', return_value=None) as s:
view = mock.MagicMock()
view.get_microbit_path = mock.MagicMock(return_value=None)
view.current_tab.text = mock.MagicMock(return_value='')
view.show_message = mock.MagicMock()
editor = mock.MagicMock()
mm = MicrobitMode(editor, view)
mm.flash()
message = 'Could not find an attached BBC micro:bit.'
information = ("Please ensure you leave enough time for the BBC"
" micro:bit to be attached and configured correctly"
" by your computer. This may take several seconds."
" Alternatively, try removing and re-attaching the"
" device or saving your work and restarting Mu if"
" the device remains unfound.")
view.show_message.assert_called_once_with(message, information)
home = HOME_DIRECTORY
view.get_microbit_path.assert_called_once_with(home)
assert s.call_count == 0
示例3: test_flash_user_specified_device_path
# 需要导入模块: from mu.modes.microbit import MicrobitMode [as 别名]
# 或者: from mu.modes.microbit.MicrobitMode import flash [as 别名]
def test_flash_user_specified_device_path():
"""
Ensure that if a micro:bit is not automatically found by uflash then it
prompts the user to locate the device and, assuming a path was given,
saves the hex in the expected location.
"""
mock_flasher = mock.MagicMock()
mock_flasher_class = mock.MagicMock(return_value=mock_flasher)
with mock.patch('mu.logic.uflash.find_microbit', return_value=None),\
mock.patch('mu.logic.os.path.exists', return_value=True),\
mock.patch('mu.modes.microbit.DeviceFlasher',
mock_flasher_class), \
mock.patch('mu.modes.microbit.sys.platform', 'win32'):
view = mock.MagicMock()
view.get_microbit_path = mock.MagicMock(return_value='bar')
view.current_tab.text = mock.MagicMock(return_value='foo')
view.show_message = mock.MagicMock()
editor = mock.MagicMock()
mm = MicrobitMode(editor, view)
mm.flash()
home = HOME_DIRECTORY
view.get_microbit_path.assert_called_once_with(home)
assert editor.show_status_message.call_count == 1
assert mm.user_defined_microbit_path == 'bar'
mock_flasher_class.assert_called_once_with(['bar', ], b'foo', None)
示例4: test_flash_with_attached_device_as_not_windows
# 需要导入模块: from mu.modes.microbit import MicrobitMode [as 别名]
# 或者: from mu.modes.microbit.MicrobitMode import flash [as 别名]
def test_flash_with_attached_device_as_not_windows():
"""
Ensure the expected calls are made to DeviceFlasher and a helpful status
message is enacted as if not on Windows.
"""
mock_timer = mock.MagicMock()
mock_timer_class = mock.MagicMock(return_value=mock_timer)
mock_flasher = mock.MagicMock()
mock_flasher_class = mock.MagicMock(return_value=mock_flasher)
with mock.patch('mu.modes.microbit.uflash.find_microbit',
return_value='bar'),\
mock.patch('mu.modes.microbit.os.path.exists', return_value=True),\
mock.patch('mu.modes.microbit.DeviceFlasher',
mock_flasher_class), \
mock.patch('mu.modes.microbit.sys.platform', 'linux'), \
mock.patch('mu.modes.microbit.QTimer', mock_timer_class):
view = mock.MagicMock()
view.current_tab.text = mock.MagicMock(return_value='foo')
view.show_message = mock.MagicMock()
editor = mock.MagicMock()
mm = MicrobitMode(editor, view)
mm.flash()
assert mm.flash_timer == mock_timer
assert editor.show_status_message.call_count == 1
view.button_bar.slots['flash'].setEnabled.\
assert_called_once_with(False)
mock_flasher_class.assert_called_once_with(['bar', ], b'foo', None)
assert mock_flasher.finished.connect.call_count == 0
mock_timer.timeout.connect.assert_called_once_with(mm.flash_finished)
mock_timer.setSingleShot.assert_called_once_with(True)
mock_timer.start.assert_called_once_with(10000)
mock_flasher.on_flash_fail.connect.\
assert_called_once_with(mm.flash_failed)
mock_flasher.start.assert_called_once_with()
示例5: test_flash_script_too_big
# 需要导入模块: from mu.modes.microbit import MicrobitMode [as 别名]
# 或者: from mu.modes.microbit.MicrobitMode import flash [as 别名]
def test_flash_script_too_big():
"""
If the script in the current tab is too big, abort in the expected way.
"""
view = mock.MagicMock()
view.current_tab.text = mock.MagicMock(return_value='x' * 8193)
view.current_tab.label = 'foo'
view.show_message = mock.MagicMock()
editor = mock.MagicMock()
mm = MicrobitMode(editor, view)
mm.flash()
view.show_message.assert_called_once_with('Unable to flash "foo"',
'Your script is too long!',
'Warning')
示例6: test_flash_no_tab
# 需要导入模块: from mu.modes.microbit import MicrobitMode [as 别名]
# 或者: from mu.modes.microbit.MicrobitMode import flash [as 别名]
def test_flash_no_tab():
"""
If there are no active tabs simply return.
"""
editor = mock.MagicMock()
view = mock.MagicMock()
view.current_tab = None
mm = MicrobitMode(editor, view)
assert mm.flash() is None
示例7: test_flash_with_attached_device_and_custom_runtime
# 需要导入模块: from mu.modes.microbit import MicrobitMode [as 别名]
# 或者: from mu.modes.microbit.MicrobitMode import flash [as 别名]
def test_flash_with_attached_device_and_custom_runtime():
"""
Ensure the custom runtime is passed into the DeviceFlasher thread.
"""
mock_flasher = mock.MagicMock()
mock_flasher_class = mock.MagicMock(return_value=mock_flasher)
with mock.patch('mu.modes.microbit.get_settings_path',
return_value='tests/settingswithcustomhex.json'), \
mock.patch('mu.modes.base.BaseMode.workspace_dir',
return_value=TEST_ROOT), \
mock.patch('mu.modes.microbit.DeviceFlasher',
mock_flasher_class), \
mock.patch('mu.modes.microbit.sys.platform', 'win32'):
view = mock.MagicMock()
view.current_tab.text = mock.MagicMock(return_value='foo')
view.show_message = mock.MagicMock()
editor = mock.MagicMock()
mm = MicrobitMode(editor, view)
mm.flash()
assert editor.show_status_message.call_count == 1
assert os.path.join('tests', 'customhextest.hex') in \
editor.show_status_message.call_args[0][0]
assert mock_flasher_class.call_count == 1
示例8: test_flash_existing_user_specified_device_path
# 需要导入模块: from mu.modes.microbit import MicrobitMode [as 别名]
# 或者: from mu.modes.microbit.MicrobitMode import flash [as 别名]
def test_flash_existing_user_specified_device_path():
"""
Ensure that if a micro:bit is not automatically found by uflash and the
user has previously specified a path to the device, then the hex is saved
in the specified location.
"""
mock_flasher = mock.MagicMock()
mock_flasher_class = mock.MagicMock(return_value=mock_flasher)
with mock.patch('mu.logic.uflash.find_microbit', return_value=None),\
mock.patch('mu.logic.os.path.exists', return_value=True),\
mock.patch('mu.modes.microbit.DeviceFlasher',
mock_flasher_class), \
mock.patch('mu.modes.microbit.sys.platform', 'win32'):
view = mock.MagicMock()
view.current_tab.text = mock.MagicMock(return_value='foo')
view.get_microbit_path = mock.MagicMock(return_value='bar')
view.show_message = mock.MagicMock()
editor = mock.MagicMock()
mm = MicrobitMode(editor, view)
mm.user_defined_microbit_path = 'baz'
mm.flash()
assert view.get_microbit_path.call_count == 0
assert editor.show_status_message.call_count == 1
mock_flasher_class.assert_called_once_with(['baz', ], b'foo', None)