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


Python microbit.MicrobitMode类代码示例

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


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


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