• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python microbit.MicrobitMode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mu.modes.microbit.MicrobitMode的典型用法代码示例。如果您正苦于以下问题:Python MicrobitMode类的具体用法?Python MicrobitMode怎么用?Python MicrobitMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_flash_with_attached_device_as_not_windows

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()
开发者ID:lordmauve,项目名称:mu,代码行数:34,代码来源:test_microbit.py


示例2: test_flash_user_specified_device_path

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)
开发者ID:lordmauve,项目名称:mu,代码行数:25,代码来源:test_microbit.py


示例3: test_custom_hex_read

def test_custom_hex_read():
    """
    Test that a custom hex file path can be read
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    with mock.patch('mu.modes.microbit.get_settings_path',
                    return_value='tests/settingswithcustomhex.json'), \
            mock.patch('mu.modes.microbit.os.path.exists', return_value=True),\
            mock.patch('mu.modes.base.BaseMode.workspace_dir',
                       return_value=TEST_ROOT):
        assert "customhextest.hex" in mm.get_hex_path()
    """
    Test that a corrupt settings file returns None for the
    runtime hex path
    """
    with mock.patch('mu.modes.microbit.get_settings_path',
                    return_value='tests/settingscorrupt.json'), \
            mock.patch('mu.modes.base.BaseMode.workspace_dir',
                       return_value=TEST_ROOT):
        assert mm.get_hex_path() is None
    """
    Test that a missing settings file returns None for the
    runtime hex path
    """
    with mock.patch('mu.modes.microbit.get_settings_path',
                    return_value='tests/settingswithmissingcustomhex.json'), \
            mock.patch('mu.modes.base.BaseMode.workspace_dir',
                       return_value=TEST_ROOT):
        assert mm.get_hex_path() is None
开发者ID:lordmauve,项目名称:mu,代码行数:31,代码来源:test_microbit.py


示例4: test_flash_path_specified_does_not_exist

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
开发者ID:lordmauve,项目名称:mu,代码行数:29,代码来源:test_microbit.py


示例5: test_flash_without_device

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
开发者ID:lordmauve,项目名称:mu,代码行数:27,代码来源:test_microbit.py


示例6: test_api

def test_api():
    """
    Ensure the right thing comes back from the API.
    """
    view = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    api = mm.api()
    assert api == SHARED_APIS + MICROBIT_APIS
开发者ID:lordmauve,项目名称:mu,代码行数:9,代码来源:test_microbit.py


示例7: test_flash_no_tab

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
开发者ID:lordmauve,项目名称:mu,代码行数:9,代码来源:test_microbit.py


示例8: test_remove_fs_no_fs

def test_remove_fs_no_fs():
    """
    Removing a non-existent file system raises a RuntimeError.
    """
    view = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    mm.fs = None
    with pytest.raises(RuntimeError):
        mm.remove_fs()
开发者ID:lordmauve,项目名称:mu,代码行数:10,代码来源:test_microbit.py


示例9: test_add_fs_with_repl

def test_add_fs_with_repl():
    """
    If the REPL is active, you can't add the file system pane.
    """
    view = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    mm.repl = True
    with mock.patch('mu.modes.microbit.microfs.get_serial', return_value=True):
        mm.add_fs()
    assert view.add_filesystem.call_count == 0
开发者ID:lordmauve,项目名称:mu,代码行数:11,代码来源:test_microbit.py


示例10: test_toggle_files_with_plotter

def test_toggle_files_with_plotter():
    """
    If the plotter is active, ensure a helpful message is displayed.
    """
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    mm.plotter = True
    mm.fs = None
    mm.toggle_files(None)
    assert view.show_message.call_count == 1
开发者ID:willingc,项目名称:mu,代码行数:12,代码来源:test_microbit.py


示例11: test_add_fs_no_device

def test_add_fs_no_device():
    """
    If there's no device attached then ensure a helpful message is displayed.
    """
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    ex = IOError('BOOM')
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    with mock.patch('mu.modes.microbit.microfs.get_serial', side_effect=ex):
        mm.add_fs()
    assert view.show_message.call_count == 1
开发者ID:lordmauve,项目名称:mu,代码行数:12,代码来源:test_microbit.py


示例12: test_remove_fs

def test_remove_fs():
    """
    Removing the file system results in the expected state.
    """
    view = mock.MagicMock()
    view.remove_repl = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    mm.fs = True
    mm.remove_fs()
    assert view.remove_filesystem.call_count == 1
    assert mm.fs is None
开发者ID:lordmauve,项目名称:mu,代码行数:12,代码来源:test_microbit.py


示例13: test_toggle_repl

def test_toggle_repl():
    """
    If the file system is active, show a helpful message instead.
    """
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    with mock.patch('mu.modes.microbit.MicroPythonMode.toggle_repl') as tr:
        mm.repl = None
        mm.toggle_repl(None)
        tr.assert_called_once_with(None)
开发者ID:lordmauve,项目名称:mu,代码行数:12,代码来源:test_microbit.py


示例14: test_flash_finished

def test_flash_finished():
    """
    Ensure state is set back as expected when the flashing thread is finished.
    """
    view = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    mm.flash_thread = mock.MagicMock()
    mm.flash_timer = mock.MagicMock()
    mm.flash_finished()
    view.button_bar.slots['flash'].setEnabled.assert_called_once_with(True)
    editor.show_status_message.assert_called_once_with("Finished flashing.")
    assert mm.flash_thread is None
    assert mm.flash_timer is None
开发者ID:lordmauve,项目名称:mu,代码行数:14,代码来源:test_microbit.py


示例15: test_flash_script_too_big

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')
开发者ID:lordmauve,项目名称:mu,代码行数:14,代码来源:test_microbit.py


示例16: test_add_fs_no_repl

def test_add_fs_no_repl():
    """
    It's possible to add the file system pane if the REPL is inactive.
    """
    view = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    with mock.patch('mu.modes.microbit.FileManager') as mock_fm,\
            mock.patch('mu.modes.microbit.QThread'),\
            mock.patch('mu.modes.microbit.microfs.get_serial',
                       return_value=True):
        mm.add_fs()
        workspace = mm.workspace_dir()
        view.add_filesystem.assert_called_once_with(workspace, mock_fm())
        assert mm.fs
开发者ID:lordmauve,项目名称:mu,代码行数:15,代码来源:test_microbit.py


示例17: test_flash_failed

def test_flash_failed():
    """
    Ensure things are cleaned up if flashing failed.
    """
    view = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    mock_timer = mock.MagicMock()
    mm.flash_timer = mock_timer
    mm.flash_thread = mock.MagicMock()
    mm.flash_failed('Boom')
    assert view.show_message.call_count == 1
    view.button_bar.slots['flash'].setEnabled.assert_called_once_with(True)
    assert mm.flash_thread is None
    assert mm.flash_timer is None
    mock_timer.stop.assert_called_once_with()
开发者ID:lordmauve,项目名称:mu,代码行数:16,代码来源:test_microbit.py


示例18: test_microbit_mode_no_charts

def test_microbit_mode_no_charts():
    """
    If QCharts is not available, ensure plotter is not displayed.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    mm = MicrobitMode(editor, view)
    with mock.patch('mu.modes.microbit.CHARTS', False):
        actions = mm.actions()
        assert len(actions) == 3
        assert actions[0]['name'] == 'flash'
        assert actions[0]['handler'] == mm.flash
        assert actions[1]['name'] == 'files'
        assert actions[1]['handler'] == mm.toggle_files
        assert actions[2]['name'] == 'repl'
        assert actions[2]['handler'] == mm.toggle_repl
开发者ID:lordmauve,项目名称:mu,代码行数:16,代码来源:test_microbit.py


示例19: test_toggle_plotter

def test_toggle_plotter():
    """
    Ensure the plotter is toggled on if the file system pane is absent.
    """
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)

    def side_effect(*args, **kwargs):
        mm.plotter = True

    with mock.patch('mu.modes.microbit.MicroPythonMode.toggle_plotter',
                    side_effect=side_effect) as tp:
        mm.plotter = None
        mm.toggle_plotter(None)
        tp.assert_called_once_with(None)
        view.button_bar.slots['files'].\
            setEnabled.assert_called_once_with(False)
开发者ID:willingc,项目名称:mu,代码行数:19,代码来源:test_microbit.py


示例20: test_toggle_repl

def test_toggle_repl():
    """
    Ensure the REPL is able to toggle on if there's no file system pane.
    """
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    editor = mock.MagicMock()
    mm = MicrobitMode(editor, view)

    def side_effect(*args, **kwargs):
        mm.repl = True

    with mock.patch('mu.modes.microbit.MicroPythonMode.toggle_repl',
                    side_effect=side_effect) as tr:
        mm.repl = None
        mm.toggle_repl(None)
        tr.assert_called_once_with(None)
        view.button_bar.slots['files'].\
            setEnabled.assert_called_once_with(False)
开发者ID:willingc,项目名称:mu,代码行数:19,代码来源:test_microbit.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python python3.PythonMode类代码示例发布时间:2022-05-27
下一篇:
Python debugger.DebugMode类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap