コード例 #1
0
ファイル: test_base.py プロジェクト: barseghyanartur/mu
def test_micropython_mode_add_repl_already_exists():
    """
    Ensure the editor raises a RuntimeError if the repl already exists.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.repl = True
    with pytest.raises(RuntimeError):
        mm.add_repl()
コード例 #2
0
def test_micropython_mode_add_repl_exception():
    """
    Ensure that any non-IOError based exceptions are logged.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    ex = Exception('BOOM')
    view.add_micropython_repl = mock.MagicMock(side_effect=ex)
    mm = MicroPythonMode(editor, view)
    mm.find_device = mock.MagicMock(return_value=('COM0', '12345'))
    with mock.patch('mu.modes.base.logger', return_value=None) as logger:
        mm.add_repl()
        logger.error.assert_called_once_with(ex)
コード例 #3
0
ファイル: test_base.py プロジェクト: lordmauve/mu
def test_micropython_mode_add_repl_exception():
    """
    Ensure that any non-IOError based exceptions are logged.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    ex = Exception('BOOM')
    view.add_micropython_repl = mock.MagicMock(side_effect=ex)
    mm = MicroPythonMode(editor, view)
    mm.find_device = mock.MagicMock(return_value='COM0')
    with mock.patch('mu.modes.base.logger', return_value=None) as logger:
        mm.add_repl()
        logger.error.assert_called_once_with(ex)
コード例 #4
0
def test_micropython_mode_add_repl_no_port():
    """
    If it's not possible to find a connected micro:bit then ensure a helpful
    message is enacted.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.find_device = mock.MagicMock(return_value=(None, None))
    mm.add_repl()
    assert view.show_message.call_count == 1
    message = 'Could not find an attached device.'
    assert view.show_message.call_args[0][0] == message
コード例 #5
0
ファイル: test_base.py プロジェクト: lordmauve/mu
def test_micropython_mode_add_repl_no_port():
    """
    If it's not possible to find a connected micro:bit then ensure a helpful
    message is enacted.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.find_device = mock.MagicMock(return_value=False)
    mm.add_repl()
    assert view.show_message.call_count == 1
    message = 'Could not find an attached device.'
    assert view.show_message.call_args[0][0] == message
コード例 #6
0
def test_micropython_mode_add_repl():
    """
    Nothing goes wrong so check the _view.add_micropython_repl gets the
    expected argument.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    view.add_micropython_repl = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.find_device = mock.MagicMock(return_value=('COM0', '12345'))
    with mock.patch('os.name', 'nt'):
        mm.add_repl()
    assert view.show_message.call_count == 0
    assert view.add_micropython_repl.call_args[0][0] == 'COM0'
コード例 #7
0
ファイル: test_base.py プロジェクト: lordmauve/mu
def test_micropython_mode_add_repl():
    """
    Nothing goes wrong so check the _view.add_micropython_repl gets the
    expected argument.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    view.add_micropython_repl = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.find_device = mock.MagicMock(return_value='COM0')
    with mock.patch('os.name', 'nt'):
        mm.add_repl()
    assert view.show_message.call_count == 0
    assert view.add_micropython_repl.call_args[0][0] == 'COM0'
コード例 #8
0
ファイル: test_base.py プロジェクト: watrt/mu
def test_micropython_mode_add_repl_exception(microbit):
    """
    Ensure that any non-IOError based exceptions are logged.
    """
    editor = mock.MagicMock()
    editor.current_device = microbit
    view = mock.MagicMock()
    ex = Exception("BOOM")
    mm = MicroPythonMode(editor, view)
    mock_repl_connection = mock.MagicMock()
    mock_repl_connection.open = mock.MagicMock(side_effect=ex)
    mock_connection_class = mock.MagicMock(return_value=mock_repl_connection)
    with mock.patch("mu.modes.base.logger", return_value=None) as logger:
        with mock.patch("mu.modes.base.REPLConnection", mock_connection_class):
            mm.add_repl()
            logger.error.assert_called_once_with(ex)
コード例 #9
0
ファイル: test_base.py プロジェクト: lordmauve/mu
def test_micropython_mode_add_repl_ioerror():
    """
    Sometimes when attempting to connect to the device there is an IOError
    because it's still booting up or connecting to the host computer. In this
    case, ensure a useful message is displayed.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    ex = IOError('BOOM')
    view.add_micropython_repl = mock.MagicMock(side_effect=ex)
    mm = MicroPythonMode(editor, view)
    mm.find_device = mock.MagicMock(return_value='COM0')
    mm.add_repl()
    assert view.show_message.call_count == 1
    assert view.show_message.call_args[0][0] == str(ex)
コード例 #10
0
def test_micropython_mode_add_repl_ioerror():
    """
    Sometimes when attempting to connect to the device there is an IOError
    because it's still booting up or connecting to the host computer. In this
    case, ensure a useful message is displayed.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    ex = IOError('BOOM')
    view.add_micropython_repl = mock.MagicMock(side_effect=ex)
    mm = MicroPythonMode(editor, view)
    mm.find_device = mock.MagicMock(return_value=('COM0', '12345'))
    mm.add_repl()
    assert view.show_message.call_count == 1
    assert view.show_message.call_args[0][0] == str(ex)
コード例 #11
0
def test_micropython_mode_add_repl_no_force_interrupt():
    """
    Nothing goes wrong so check the _view.add_micropython_repl gets the
    expected arguments (including the flag so no keyboard interrupt is called).
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    view.add_micropython_repl = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.force_interrupt = False
    mm.find_device = mock.MagicMock(return_value=('COM0', '12345'))
    with mock.patch('os.name', 'nt'):
        mm.add_repl()
    assert view.show_message.call_count == 0
    assert view.add_micropython_repl.call_args[0][0] == 'COM0'
    assert view.add_micropython_repl.call_args[0][2] is False
コード例 #12
0
ファイル: test_base.py プロジェクト: ZanderBrown/mu
def test_micropython_mode_add_repl_no_force_interrupt():
    """
    Nothing goes wrong so check the _view.add_micropython_repl gets the
    expected arguments (including the flag so no keyboard interrupt is called).
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    view.add_micropython_repl = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.force_interrupt = False
    mm.find_device = mock.MagicMock(return_value=('COM0', '12345'))
    with mock.patch('os.name', 'nt'):
        mm.add_repl()
    assert view.show_message.call_count == 0
    assert view.add_micropython_repl.call_args[0][0] == 'COM0'
    assert view.add_micropython_repl.call_args[0][2] is False
コード例 #13
0
ファイル: test_base.py プロジェクト: watrt/mu
def test_micropython_mode_add_repl_no_force_interrupt(microbit):
    """
    Nothing goes wrong so check the _view.add_micropython_repl gets the
    expected arguments (including the flag so no keyboard interrupt
    is called).
    """
    editor = mock.MagicMock()
    editor.current_device = microbit
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.force_interrupt = False
    mock_repl_connection = mock.MagicMock()
    mock_connection_class = mock.MagicMock(return_value=mock_repl_connection)
    with mock.patch("mu.modes.base.REPLConnection", mock_connection_class):
        mm.add_repl()
    view.show_message.assert_not_called()
    mock_repl_connection.send_interrupt.assert_not_called()
コード例 #14
0
ファイル: test_base.py プロジェクト: watrt/mu
def test_micropython_mode_add_repl(microbit):
    """
    Nothing goes wrong so check the _view.add_micropython_repl gets the
    expected argument.
    """
    editor = mock.MagicMock()
    editor.current_device = microbit
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    view.add_micropython_repl = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mock_repl_connection = mock.MagicMock()
    mock_connection_class = mock.MagicMock(return_value=mock_repl_connection)
    with mock.patch("mu.modes.base.REPLConnection", mock_connection_class):
        mm.add_repl()
    assert view.show_message.call_count == 0
    assert view.add_micropython_repl.call_args[0][1] == mock_repl_connection
    mock_repl_connection.send_interrupt.assert_called_once_with()
コード例 #15
0
ファイル: test_base.py プロジェクト: watrt/mu
def test_micropython_mode_add_repl_ioerror(microbit):
    """
    Sometimes when attempting to connect to the device there is an IOError
    because it's still booting up or connecting to the host computer. In this
    case, ensure a useful message is displayed.
    """
    editor = mock.MagicMock()
    editor.current_device = microbit
    view = mock.MagicMock()
    view.show_message = mock.MagicMock()
    ex = IOError("BOOM")
    mm = MicroPythonMode(editor, view)
    mock_repl_connection = mock.MagicMock()
    mock_repl_connection.open = mock.MagicMock(side_effect=ex)
    mock_connection_class = mock.MagicMock(return_value=mock_repl_connection)
    with mock.patch("mu.modes.base.REPLConnection", mock_connection_class):
        mm.add_repl()
    assert view.show_message.call_count == 1
    assert view.show_message.call_args[0][0] == str(ex)
コード例 #16
0
def test_micropython_mode_toggle_repl_on():
    """
    There is no repl, so toggle on.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.add_repl = mock.MagicMock()
    mm.repl = None
    mm.toggle_repl(None)
    assert mm.add_repl.call_count == 1
コード例 #17
0
ファイル: test_base.py プロジェクト: lordmauve/mu
def test_micropython_mode_toggle_repl_on():
    """
    There is no repl, so toggle on.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.add_repl = mock.MagicMock()
    mm.repl = None
    mm.toggle_repl(None)
    assert mm.add_repl.call_count == 1
コード例 #18
0
ファイル: test_base.py プロジェクト: watrt/mu
def test_micropython_device_changed(microbit):
    """
    Ensure REPL/Plotter and connection are reconnected, when the
    user changes device.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.show_device_selector = mock.MagicMock()
    view.hide_device_selector = mock.MagicMock()
    mm = MicroPythonMode(editor, view)
    mm.add_repl = mock.MagicMock()
    mm.add_plotter = mock.MagicMock()
    mm.remove_repl = mock.MagicMock()
    mm.remove_plotter = mock.MagicMock()
    mm.repl = True
    mm.plotter = True
    mm.connection = mock.MagicMock()
    mm.activate()
    mm.device_changed(microbit)
    mm.add_repl.assert_called_once_with()
    mm.add_plotter.assert_called_once_with()
    mm.remove_repl.assert_called_once_with()
    mm.remove_plotter.assert_called_once_with()
    mm.connection.send_interrupt.assert_called_once_with()