Exemple #1
0
def test_ProxyToVim_showFeedback_empty():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)

    to_vim = ProxyToVim(communicator)
    to_vim.showFeedback('')

    assert not communicator.called
Exemple #2
0
def test_ProxyToVim_showFeedback_empty():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)

    to_vim = ProxyToVim(communicator)
    to_vim.showFeedback('')

    assert not communicator.called
Exemple #3
0
def test_ProxyToVim_showFileAtLine_wrong_file():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)
    communicator._remote_expr.return_value = '1'

    to_vim = ProxyToVim(communicator)
    to_vim.showFileAtLine('bla.vim', 1)

    assert not communicator.called
Exemple #4
0
def test_ProxyToVim_isRemoteSetup():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)

    to_vim = ProxyToVim(communicator)
    to_vim.isRemoteSetup()

    assert communicator._remote_expr.call_count == 1
    communicator._remote_expr.assert_called_with("exists('*PDB_setup_egg')")
Exemple #5
0
def test_ProxyToVim_showFileAtLine_wrong_file():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)
    communicator._remote_expr.return_value = '1'

    to_vim = ProxyToVim(communicator)
    to_vim.showFileAtLine('bla.vim', 1)

    assert not communicator.called
Exemple #6
0
def test_ProxyToVim_isRemoteSetup():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)

    to_vim = ProxyToVim(communicator)
    to_vim.isRemoteSetup()

    assert communicator._remote_expr.call_count == 1
    communicator._remote_expr.assert_called_with("exists('*PDB_setup_egg')")
Exemple #7
0
def test_ProxyToVim_setupRemote_does_nothing():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)
    communicator._remote_expr.return_value = '1'

    to_vim = ProxyToVim(communicator)
    to_vim.setupRemote()

    assert communicator._remote_expr.call_count == 1, (
        "_remote_expr not called")
    communicator._remote_expr.assert_called_with("exists('*PDB_setup_egg')")
Exemple #8
0
def test_ProxyToVim_setupRemote_does_nothing():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)
    communicator._remote_expr.return_value = '1'

    to_vim = ProxyToVim(communicator)
    to_vim.setupRemote()

    assert communicator._remote_expr.call_count == 1, (
        "_remote_expr not called")
    communicator._remote_expr.assert_called_with("exists('*PDB_setup_egg')")
Exemple #9
0
def test_ProxyToVim_showFeedback_content():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)
    communicator._remote_expr.return_value = '1'

    to_vim = ProxyToVim(communicator)
    to_vim.showFeedback('first\nsecond')

    assert communicator._remote_expr.call_count == 1
    communicator._remote_expr.assert_called_with("exists('*PDB_setup_egg')")
    assert communicator._send.call_count == 1
    communicator._send.assert_called_with(
        ":call PDB_show_feedback(['first', 'second'])<CR>")
Exemple #10
0
def test_ProxyToVim_showFeedback_content():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)
    communicator._remote_expr.return_value = '1'

    to_vim = ProxyToVim(communicator)
    to_vim.showFeedback('first\nsecond')

    assert communicator._remote_expr.call_count == 1
    communicator._remote_expr.assert_called_with("exists('*PDB_setup_egg')")
    assert communicator._send.call_count == 1
    communicator._send.assert_called_with(
        ":call PDB_show_feedback(['first', 'second'])<CR>")
Exemple #11
0
 def __init__(self):
     Pdb.__init__(self)
     self.capturing = False
     config = getConfiguration()
     self.to_vim = ProxyToVim(config)
     self.from_vim = ProxyFromVim(config)
     self._textOutput = ''
Exemple #12
0
def test_ProxyToVim_instantiation():
    from vimpdb.proxy import ProxyToVim

    communicator = Mock()

    to_vim = ProxyToVim(communicator)
    assert isinstance(to_vim, ProxyToVim)
    assert to_vim.communicator == communicator
Exemple #13
0
def test_ProxyToVim_showFileAtLine_existing_file():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator
    from vimpdb.config import get_package_path

    existingFile = get_package_path(
        test_ProxyToVim_showFileAtLine_existing_file)

    communicator = Mock(spec=Communicator)
    communicator._remote_expr.return_value = '1'

    to_vim = ProxyToVim(communicator)
    to_vim.showFileAtLine(existingFile, 1)

    communicator._remote_expr.assert_called_with("exists('*PDB_setup_egg')")
    assert communicator._send.call_count == 1
    call_args, call_kwargs = communicator._send.call_args
    assert call_args[0].startswith(':call PDB_show_file_at_line("')
    assert call_args[0].endswith(' "1")<CR>')
    assert not '\\' in call_args[0]
Exemple #14
0
def test_ProxyToVim_showFileAtLine_existing_file():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator
    from vimpdb.config import get_package_path

    existingFile = get_package_path(
        test_ProxyToVim_showFileAtLine_existing_file)

    communicator = Mock(spec=Communicator)
    communicator._remote_expr.return_value = '1'

    to_vim = ProxyToVim(communicator)
    to_vim.showFileAtLine(existingFile, 1)

    communicator._remote_expr.assert_called_with("exists('*PDB_setup_egg')")
    assert communicator._send.call_count == 1
    call_args, call_kwargs = communicator._send.call_args
    assert call_args[0].startswith(':call PDB_show_file_at_line("')
    assert call_args[0].endswith(' "1")<CR>')
    assert not '\\' in call_args[0]
Exemple #15
0
def test_ProxyToVim_setupRemote():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)
    communicator._remote_expr.return_value = '0'

    to_vim = ProxyToVim(communicator)
    to_vim.setupRemote()

    communicator._remote_expr.assert_called_with("exists('*PDB_setup_egg')")
    assert communicator._send.call_count == 4
    call_args_list = communicator._send.call_args_list
    call_args, call_kwargs = call_args_list[0]
    assert call_args[0].endswith('vimpdb/vimpdb.vim<CR>')
    call_args, call_kwargs = call_args_list[1]
    assert call_args[0].startswith(':call PDB_setup_egg(')
    call_args, call_kwargs = call_args_list[2]
    assert call_args[0].startswith(':call PDB_setup_egg(')
    call_args, call_kwargs = call_args_list[3]
    assert call_args[0].startswith(':call PDB_init_controller(')
Exemple #16
0
def test_ProxyToVim_setupRemote():
    from vimpdb.proxy import ProxyToVim
    from vimpdb.proxy import Communicator

    communicator = Mock(spec=Communicator)
    communicator._remote_expr.return_value = '0'

    to_vim = ProxyToVim(communicator)
    to_vim.setupRemote()

    communicator._remote_expr.assert_called_with("exists('*PDB_setup_egg')")
    assert communicator._send.call_count == 4
    call_args_list = communicator._send.call_args_list
    call_args, call_kwargs = call_args_list[0]
    assert call_args[0].endswith('vimpdb/vimpdb.vim<CR>')
    call_args, call_kwargs = call_args_list[1]
    assert call_args[0].startswith(':call PDB_setup_egg(')
    call_args, call_kwargs = call_args_list[2]
    assert call_args[0].startswith(':call PDB_setup_egg(')
    call_args, call_kwargs = call_args_list[3]
    assert call_args[0].startswith(':call PDB_init_controller(')
Exemple #17
0
class VimPdb(Pdb, Switcher):
    """
    debugger integrated with Vim
    """

    def __init__(self):
        Pdb.__init__(self)
        self.capturing = False
        config = getConfiguration()
        self.to_vim = ProxyToVim(config)
        self.from_vim = ProxyFromVim(config)
        self._textOutput = ''

    def trace_dispatch(self, frame, event, arg):
        """allow to switch to Pdb instance"""
        if hasattr(self, 'pdb'):
            return self.pdb.trace_dispatch(frame, event, arg)
        else:
            return Pdb.trace_dispatch(self, frame, event, arg)

    def execRcLines(self):
        pass

    def cmdloop(self):
        stop = None
        self.preloop()
        while not stop:
            line = self.from_vim.waitFor(self)
            line = self.precmd(line)
            stop = self.onecmd(line)
            stop = self.postcmd(stop, line)
        self.postloop()

    def preloop(self):
        filename, lineno = self.getFileAndLine()
        self.to_vim.showFileAtLine(filename, lineno)

    def getFileAndLine(self):
        frame, lineno = self.stack[self.curindex]
        filename = self.canonic(frame.f_code.co_filename)
        return filename, lineno

    def showFileAtLine(self):
        filename, lineno = self.getFileAndLine()
        self.to_vim.showFileAtLine(filename, lineno)

    # stdout captures to send back to Vim
    def capture_sys_stdout(self):
        self.stdout = sys.stdout
        sys.stdout = StringIO.StringIO()
        self.capturing = True

    def stop_capture_sys_stdout(self):
        if self.capturing:
            self.capturing = False
            self.push_output(sys.stdout.getvalue())
            sys.stdout = self.stdout

    # stdout captures to send back to Vim
    def capture_self_stdout(self):
        self.initial_stdout = self.stdout
        self.stdout = StringIO.StringIO()
        self.capturing = True

    def stop_capture_self_stdout(self):
        if self.capturing:
            self.capturing = False
            self.push_output(self.stdout.getvalue())
            self.stdout = self.initial_stdout

    def push_output(self, text):
        self._textOutput += text

    def pop_output(self):
        result = self._textOutput
        self._textOutput = ''
        return result

    def do_pdb(self, line):
        """
        'pdb' command:
        switches back to debugging with (almost) standard pdb.Pdb
        except for added 'vim' command.
        """
        self.from_vim.closeSocket()
        self.pdb = get_hooked_pdb()
        self.pdb.set_trace_without_step(self.botframe)
        if self.has_gone_up():
            self.pdb.update_state(self)
            self.pdb.print_current_stack_entry()
            self.pdb.cmdloop()
        else:
            self.pdb.interaction(self.curframe, None)
        return 1

    do_u = do_up = show_line(Pdb.do_up)
    do_d = do_down = show_line(Pdb.do_down)
    do_a = do_args = capture(Pdb.do_args)
    do_b = do_break = capture(Pdb.do_break)
    do_c = do_continue = close_socket(Pdb.do_continue)

    @capture
    def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix):
        return Pdb.print_stack_entry(self, frame_lineno, prompt_prefix)

    def default(self, line):
        # first char should not be output (it is the '!' needed to escape)
        self.push_output(line[1:] + " = ")
        return Pdb.default(self, line)