def test_is_breakpoint_line_comment(): """ You can't set a breakpoint on a line that is a comment. """ assert is_breakpoint_line('# A comment') is False assert is_breakpoint_line('""" A comment """') is False assert is_breakpoint_line("''' A comment'''") is False
def test_is_breakpoint_line_comment(): """ You can't set a breakpoint on a line that is a comment. """ assert is_breakpoint_line("# A comment") is False assert is_breakpoint_line('""" A comment """') is False assert is_breakpoint_line("''' A comment'''") is False
def test_is_breakpoint_line_closing_collection(): """ It's common to write things like: foo = [ 'a', 'b', 'c', ] Breakpoints cannot be set on the final line of this statement (for all collection types). """ assert is_breakpoint_line("]") is False assert is_breakpoint_line("}") is False assert is_breakpoint_line(")") is False
def do_break(self, filename, line, temporary=False): """ Set a breakpoint. """ globs = self.curframe.f_globals if hasattr(self, "curframe") else None code = linecache.getline(filename, line, globs) if is_breakpoint_line(code): err = self.set_break(filename, line, temporary, None, None) if err: self.output("error", message=err) else: bp = self.get_breaks(filename, line)[-1] self.output( "breakpoint_create", bpnum=bp.number, filename=bp.file, line=bp.line, temporary=bp.temporary, funcname=bp.funcname, ) else: self.output( "error", message="{}:{} is not executable".format(filename, line), )
def test_is_breakpoint_line_closing_collection(): """ It's common to write things like: foo = [ 'a', 'b', 'c', ] Breakpoints cannot be set on the final line of this statement (for all collection types). """ assert is_breakpoint_line(']') is False assert is_breakpoint_line('}') is False assert is_breakpoint_line(')') is False
def test_is_breakpoint_line_opening_collection(): """ It's common to write things like: foo = [ 'a', 'b', 'c', ] Breakpoints cannot be set on the first line of this statement (for all collection types). """ assert is_breakpoint_line('foo = [') is False assert is_breakpoint_line('foo = {') is False assert is_breakpoint_line('foo = (') is False
def debug_on_bootstrap(self): """ Once the debugger is bootstrapped ensure all the current breakpoints are set. Do not set breakpoints (and remove the marker) if: * The marker is not visible (the line is -1) * The marker is not a duplicate of an existing line. * The line with the marker is not a valid breakpoint line. """ for tab in self.view.widgets: break_lines = set() for handle in list(tab.breakpoint_handles): line = tab.markerLine(handle) code = tab.text(line) if ( line > -1 and line not in break_lines and is_breakpoint_line(code) ): self.debugger.create_breakpoint(tab.path, line + 1) break_lines.add(line) else: tab.breakpoint_handles.remove(handle) tab.markerDelete(line, -1) # Start the script running. self.debugger.do_run()
def do_break(self, filename, line, temporary=False): """ Set a breakpoint. """ globs = self.curframe.f_globals if hasattr(self, 'curframe') else None code = linecache.getline(filename, line, globs) if is_breakpoint_line(code): err = self.set_break(filename, line, temporary, None, None) if err: self.output('error', message=err) else: bp = self.get_breaks(filename, line)[-1] self.output( 'breakpoint_create', bpnum=bp.number, filename=bp.file, line=bp.line, temporary=bp.temporary, funcname=bp.funcname ) else: self.output('error', message='{}:{} is not executable'.format( filename, line))
def debug_on_bootstrap(self): """ Once the debugger is bootstrapped ensure all the current breakpoints are set. Do not set breakpoints (and remove the marker) if: * The marker is not visible (the line is -1) * The marker is not a duplicate of an existing line. * The line with the marker is not a valid breakpoint line. """ for tab in self.view.widgets: break_lines = set() for handle in list(tab.breakpoint_handles): line = tab.markerLine(handle) code = tab.text(line) if line > -1 and line not in break_lines and \ is_breakpoint_line(code): self.debugger.create_breakpoint(tab.path, line + 1) break_lines.add(line) else: tab.breakpoint_handles.remove(handle) tab.markerDelete(line, -1) # Start the script running. self.debugger.do_run()
def test_is_breakpoint_line_valid_code(): """ A simple check to ensure a valid line of Python returns True. """ code = 'print("Hello")' assert is_breakpoint_line(code)
def test_is_breakpoint_line_valid_blank_line(): """ If the line is blank, you can't set a breakpoint. """ assert is_breakpoint_line(" ") is False
def test_is_breakpoint_line_valid_code_with_whitespace(): """ If the line of code is indented with whitespace, ensure it returns True. """ code = ' print("Hello")' assert is_breakpoint_line(code)
def test_is_breakpoint_line_valid_blank_line(): """ If the line is blank, you can't set a breakpoint. """ assert is_breakpoint_line(' ') is False