Exemplo n.º 1
0
def test_debug_button_step_over():
    """
    Ensure the do_next method is called when the step-over button is clicked.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    dm.button_step_over(None)
    dm.debugger.do_next.assert_called_once_with()
Exemplo n.º 2
0
def test_debug_button_stop():
    """
    Ensure the stop method is called when the stop button is clicked.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.stop = mock.MagicMock()
    dm.button_stop(None)
    dm.stop.assert_called_once_with()
Exemplo n.º 3
0
def test_debug_button_continue():
    """
    Ensure the do_run method is called when the continue button is clicked.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    dm.button_continue(None)
    dm.debugger.do_run.assert_called_once_with()
Exemplo n.º 4
0
def test_debug_start_no_tab():
    """
    If there's no active tab, there can be no runner either.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.current_tab = None
    dm = DebugMode(editor, view)
    dm.start()
    assert dm.runner is None
Exemplo n.º 5
0
def test_debug_on_return():
    """
    Returning from a function causes the debugger to step out of the function.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    dm.debug_on_return(None)
    dm.debugger.do_step.assert_called_once_with()
Exemplo n.º 6
0
def test_debug_on_finished():
    """
    When the debugger is finished, the view is reset.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.finished = mock.MagicMock()
    dm.debug_on_finished()
    dm.finished.assert_called_once_with()
Exemplo n.º 7
0
def test_debug_on_call():
    """
    Calling a function causes the debugger to step into the function.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    dm.debug_on_call(None)
    dm.debugger.do_step.assert_called_once_with()
Exemplo n.º 8
0
def test_debug_on_error():
    """
    Error messages result in a status message being shown by the editor.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debug_on_error('message')
    expected = 'Debugger error: message'
    editor.show_status_message.assert_called_once_with(expected)
Exemplo n.º 9
0
def test_debug_on_line_ignore_file():
    """
    If the filename is in the ignored bucket, do a return.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    dm.debug_on_line('bdb.py', 100)
    dm.debugger.do_return.assert_called_once_with()
Exemplo n.º 10
0
def test_debug_on_warning():
    """
    Warning messages result in a status message being shown by the editor.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debug_on_warning("message")
    expected = "Debugger warning: message"
    editor.show_status_message.assert_called_once_with(expected)
Exemplo n.º 11
0
def test_debug_on_stack_no_stack():
    """
    In certain rare situations the runner could send an empty stack.

    ToDo: Look into this.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debug_on_stack([])
    assert view.update_debug_inspector.call_count == 0
Exemplo n.º 12
0
def test_debug_button_step_out():
    """
    Ensure the do_return method is called when the step-out button is clicked.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    dm.button_step_out(None)
    dm.debugger.do_return.assert_called_once_with()
    assert view.current_tab.reset_debugger_highlight.call_count == 1
Exemplo n.º 13
0
def test_debug_on_postmortem():
    """
    Ensure that the args and kwargs passed as a context for postmortem and
    appended to the text area displaying stdout from the Python process.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    args = ["foo", "bar"]
    kwargs = {"baz": "qux"}
    dm.debug_on_postmortem(args, kwargs)
    assert view.process_runner.append.call_count == 3
Exemplo n.º 14
0
def test_debug_on_exception():
    """
    Since an exception has been signalled, allow the script to run to the
    end of life so the error is correctly reported via stdout.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    dm.debug_on_exception("Exception", "Exception information")
    dm.debugger.do_run.assert_called_once_with()
    assert view.current_tab.reset_debugger_highlight.call_count == 1
Exemplo n.º 15
0
def test_debug_on_line():
    """
    Ensure the view is updated to the expected tab and the correct line is
    selected therein.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    mock_tab = mock.MagicMock()
    editor.get_tab.return_value = mock_tab
    dm.debug_on_line('foo.py', 100)
    view.current_tab.setSelection.assert_called_once_with(0, 0, 0, 0)
    mock_tab.setSelection(99, 0, 100, 0)
Exemplo n.º 16
0
def test_debug_on_fail():
    """
    Ensure an appropriate message is shown to the user and the UI is put into
    the correct state if the debug client calls this function because it can't
    connect to the runner.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.finished = mock.MagicMock()
    dm.debug_on_fail()
    assert view.process_runner.append.call_count == 1  # message shown.
    dm.finished.assert_called_once_with()
    view.process_runner.finished.assert_called_once_with(1, -1)
Exemplo n.º 17
0
def test_debug_on_breakpoint_disable():
    """
    Handle the signal that shows the debug runner has disabled a breakpoint.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    mock_tab = mock.MagicMock()
    view.current_tab = mock_tab
    dm = DebugMode(editor, view)
    mock_breakpoint = mock.MagicMock()
    mock_breakpoint.line = 1
    dm.debug_on_breakpoint_disable(mock_breakpoint)
    mock_tab.markerDelete.assert_called_once_with(mock_breakpoint.line - 1,
                                                  mock_tab.BREAKPOINT_MARKER)
Exemplo n.º 18
0
def test_debug_start_prompt_for_unsaved_file():
    """
    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
    dm = DebugMode(editor, view)
    dm.stop = mock.MagicMock()
    dm.start()
    editor.save.assert_called_once_with()
    assert dm.runner is None
    dm.stop.assert_called_once_with()
Exemplo n.º 19
0
def test_debug_toggle_breakpoint_on_existing():
    """
    If the breakpoint doesn't exist, create it.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    mock_debugger = mock.MagicMock()
    dm.debugger = mock_debugger
    mock_debugger.breakpoints.return_value = {}
    mock_tab = mock.MagicMock()
    mock_tab.path = 'foo'
    mock_tab.markersAtLine.return_value = False
    dm.toggle_breakpoint(0, mock_tab)
    dm.debugger.create_breakpoint.assert_called_once_with(mock_tab.path, 1)
Exemplo n.º 20
0
def test_debug_on_bootstrap():
    """
    Ensure all the current breakpoints are set and the script is run.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    mock_tab = mock.MagicMock()
    mock_tab.path = 'foo'
    mock_tab.breakpoint_lines = set([0, ])
    view.widgets = [mock_tab, ]
    dm.debug_on_bootstrap()
    dm.debugger.create_breakpoint.assert_called_once_with(mock_tab.path, 1)
    dm.debugger.do_run.assert_called_once_with()
Exemplo n.º 21
0
def test_debug_finished():
    """
    Ensure the end-state of the mode is enacted when the running script has
    finished executing.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    view.button_bar.slots = {
        'stop': mock.MagicMock(),
        'run': mock.MagicMock(),
        'step-over': mock.MagicMock(),
        'step-in': mock.MagicMock(),
        'step-out': mock.MagicMock(),
    }
    dm = DebugMode(editor, view)
    mock_debugger = mock.MagicMock()
    dm.debugger = mock_debugger
    mock_debugger.bp_index = []
    mock_breakpoint = mock.MagicMock()
    mock_breakpoint.enabled = True
    mock_debugger.breakpoints.side_effect = [
        {
            1: mock_breakpoint,
        },
        {},
    ]
    tab1 = mock.MagicMock()
    tab1.path = 'foo'
    tab2 = mock.MagicMock()
    view.widgets = [tab1, tab2]
    dm.finished()
    # Buttons are set to the right state.
    assert view.button_bar.slots['stop'].setEnabled.call_count == 0
    view.button_bar.slots['run'].setEnabled.assert_called_once_with(False)
    view.button_bar.slots['step-over'].\
        setEnabled.assert_called_once_with(False)
    view.button_bar.slots['step-in'].setEnabled.assert_called_once_with(False)
    view.button_bar.slots['step-out'].setEnabled.assert_called_once_with(False)
    # Tabs are set to the right state.
    tab1.markerDeleteAll.assert_called_once_with()
    tab1.breakpoint_lines == set([
        1,
    ])
    tab1.setSelection.assert_called_once_with(0, 0, 0, 0)
    tab1.markerAdd(0, tab1.BREAKPOINT_MARKER)
    tab2.markerDeleteAll.assert_called_once_with()
    tab2.breakpoint_lines == set()
    tab2.setSelection.assert_called_once_with(0, 0, 0, 0)
Exemplo n.º 22
0
def test_debug_toggle_breakpoint_on_new():
    """
    If the breakpoint is off but disabled, enable it.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    mock_debugger = mock.MagicMock()
    dm.debugger = mock_debugger
    mock_breakpoint = mock.MagicMock()
    mock_debugger.breakpoints.side_effect = [{1: mock_breakpoint}]
    mock_tab = mock.MagicMock()
    mock_tab.path = "foo"
    mock_tab.markersAtLine.return_value = False
    dm.toggle_breakpoint(0, mock_tab)
    dm.debugger.enable_breakpoint.assert_called_once_with(mock_breakpoint)
Exemplo n.º 23
0
def test_debug_on_breakpoint_enable_marker_already_exists():
    """
    Handle the signal that shows the debug runner has created a breakpoint
    during the bootstrapping of the debug runner, so it doesn't add a second
    marker at the same location as the pre-existing one that caused the
    breakpoint to be created during bootstrapping.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    mock_tab = mock.MagicMock()
    mock_tab.markersAtLine.return_value = True
    view.current_tab = mock_tab
    dm = DebugMode(editor, view)
    mock_breakpoint = mock.MagicMock()
    mock_breakpoint.line = 1
    dm.debug_on_breakpoint_enable(mock_breakpoint)
    mock_tab.markerAdd.call_count == 0
Exemplo n.º 24
0
def test_debug_on_breakpoint_enable():
    """
    Handle the signal that shows the debug runner has created a breakpoint.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    mock_tab = mock.MagicMock()
    mock_tab.markersAtLine.return_value = False
    mock_tab.path = "foo"
    view.current_tab = mock_tab
    dm = DebugMode(editor, view)
    mock_breakpoint = mock.MagicMock()
    mock_breakpoint.filename = "foo"
    mock_breakpoint.line = 1
    dm.debug_on_breakpoint_enable(mock_breakpoint)
    mock_tab.markerAdd.assert_called_once_with(mock_breakpoint.line - 1,
                                               mock_tab.BREAKPOINT_MARKER)
Exemplo n.º 25
0
def test_debug_on_bootstrap_remove_missing_marker_handles():
    """
    Ensure all marker handles that are not currently associated with a line
    are removed from the breakpoint_handles set.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    mock_tab = mock.MagicMock()
    mock_tab.path = "foo"
    mock_tab.breakpoint_handles = set([0])
    mock_tab.markerLine.return_value = -1
    view.widgets = [mock_tab]
    dm.debug_on_bootstrap()
    assert dm.debugger.create_breakpoint.call_count == 0
    assert 0 not in mock_tab.breakpoint_handles
Exemplo n.º 26
0
def test_debug_on_bootstrap():
    """
    Ensure all the current breakpoints are set and the script is run.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    mock_tab = mock.MagicMock()
    mock_tab.path = "foo"
    mock_tab.text.return_value = "print('Hello')"
    mock_tab.breakpoint_handles = set([0])
    mock_tab.markerLine.return_value = 0
    view.widgets = [mock_tab]
    dm.debug_on_bootstrap()
    dm.debugger.create_breakpoint.assert_called_once_with(mock_tab.path, 1)
    dm.debugger.do_run.assert_called_once_with()
Exemplo n.º 27
0
def test_debug_stop():
    """
    Ensure the script runner is cleaned up properly.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    mock_runner = mock.MagicMock()
    dm.runner = mock_runner
    dm.stop()
    assert dm.runner is None
    assert dm.debugger is None
    mock_runner.stop_process.assert_called_once_with()
    view.remove_python_runner.assert_called_once_with()
    view.remove_debug_inspector.assert_called_once_with()
    editor.change_mode.assert_called_once_with("python")
    assert editor.mode == "python"
    view.set_read_only.assert_called_once_with(False)
Exemplo n.º 28
0
def test_debug_on_bootstrap_ignore_duplicate_handles():
    """
    Sometimes it's possible for two different handles to be found on a single
    line due to how Scintilla moves markers around as lines are concatenated.
    This ensures only one breakpoint is created per marker.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    dm.debugger = mock.MagicMock()
    mock_tab = mock.MagicMock()
    mock_tab.path = "foo"
    mock_tab.text.return_value = "print('Hello')"
    mock_tab.breakpoint_handles = set([0, 1])
    mock_tab.markerLine.side_effect = [1, 1]
    view.widgets = [mock_tab]
    dm.debug_on_bootstrap()
    assert dm.debugger.create_breakpoint.call_count == 1
Exemplo n.º 29
0
def test_debug_toggle_breakpoint_off():
    """
    If a breakpoint is on, it's toggled off.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    dm = DebugMode(editor, view)
    mock_debugger = mock.MagicMock()
    dm.debugger = mock_debugger
    mock_breakpoint = mock.MagicMock()
    mock_debugger.breakpoints.side_effect = [{1: mock_breakpoint}]
    mock_tab = mock.MagicMock()
    mock_tab.path = "foo"
    mock_tab.markersAtLine.return_value = True
    dm.toggle_breakpoint(0, mock_tab)
    mock_debugger.breakpoints.assert_called_once_with(mock_tab.path)
    mock_tab.markersAtLine.assert_called_once_with(0)
    mock_debugger.disable_breakpoint.assert_called_once_with(mock_breakpoint)
    mock_tab.markerDelete.assert_called_once_with(0,
                                                  mock_tab.BREAKPOINT_MARKER)
Exemplo n.º 30
0
def test_debug_on_breakpoint_enable_different_tab():
    """
    When the breakpoints are set on bootstrap, some of them may be for tabs
    that are not the currently visible tab. In any case, when breakpoints are
    set "on_breakpoint_enable" is called. This check ensures the marker is only
    created IF the current tab has the same path as the filename associated
    with the newly created breakpoint.
    """
    editor = mock.MagicMock()
    view = mock.MagicMock()
    mock_tab = mock.MagicMock()
    mock_tab.markersAtLine.return_value = False
    mock_tab.path = "foo"
    view.current_tab = mock_tab
    dm = DebugMode(editor, view)
    mock_breakpoint = mock.MagicMock()
    mock_breakpoint.filename = "bar"
    mock_breakpoint.line = 1
    dm.debug_on_breakpoint_enable(mock_breakpoint)
    assert mock_tab.markerAdd.call_count == 0