def test_debug(self): """ Make sure the cursor works while debugging It might not because the console is "_executing" """ # Kernel client to test the responses of is_complete class TestIPyKernelClient(object): def is_complete(self, source): tm = TransformerManager() check_complete = tm.check_complete(source) responses.append(check_complete) # Initialize widget responses = [] w = ConsoleWidget() w._append_plain_text('Header\n') w._prompt = 'prompt>' w._show_prompt() w.kernel_client = TestIPyKernelClient() control = w._control # Execute incomplete statement inside a block code = "%debug range(1)\n" w._set_input_buffer(code) w.execute(interactive=True) # We should be able to move the cursor while debugging w._set_input_buffer("abd") QTest.keyClick(control, QtCore.Qt.Key_Left) QTest.keyClick(control, 'c') self.assertEqual(w._get_input_buffer(), "abcd")
def test_debug(self): """ Make sure the cursor works while debugging It might not because the console is "_executing" """ # Kernel client to test the responses of is_complete class TestIPyKernelClient(object): def is_complete(self, source): tm = TransformerManager() check_complete = tm.check_complete(source) responses.append(check_complete) # Initialize widget responses = [] w = ConsoleWidget() w._append_plain_text('Header\n') w._prompt = 'prompt>' w._show_prompt() w.kernel_client = TestIPyKernelClient() control = w._control # Execute incomplete statement inside a block code = "%debug range(1)\n" w._set_input_buffer(code) w.execute(interactive=True) # We should be able to move the cursor while debugging w._set_input_buffer("abd") QTest.keyClick(control, QtCore.Qt.Key_Left) QTest.keyClick(control, 'c') self.assertEqual(w._get_input_buffer(),"abcd")
def test_keypresses(self): """Test the event handling code for keypresses.""" w = ConsoleWidget() w._append_plain_text('Header\n') w._prompt = 'prompt>' w._show_prompt() control = w._control # Test setting the input buffer w._set_input_buffer('test input') self.assertEqual(w._get_input_buffer(), 'test input') # Ctrl+K kills input until EOL w._set_input_buffer('test input') c = control.textCursor() c.setPosition(c.position() - 3) control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_K, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), 'test in') # Ctrl+V pastes w._set_input_buffer('test input ') QtGui.qApp.clipboard().setText('pasted text') QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), 'test input pasted text') self.assertEqual(control.document().blockCount(), 2) # Paste should strip indentation w._set_input_buffer('test input ') QtGui.qApp.clipboard().setText(' pasted text') QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), 'test input pasted text') self.assertEqual(control.document().blockCount(), 2) # Multiline paste, should also show continuation marks w._set_input_buffer('test input ') QtGui.qApp.clipboard().setText('line1\nline2\nline3') QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), 'test input line1\nline2\nline3') self.assertEqual(control.document().blockCount(), 4) self.assertEqual(control.document().findBlockByNumber(1).text(), 'prompt>test input line1') self.assertEqual(control.document().findBlockByNumber(2).text(), '> line2') self.assertEqual(control.document().findBlockByNumber(3).text(), '> line3')
def test_indent(self): """Test the event handling code for indent/dedent keypresses .""" w = ConsoleWidget() w._append_plain_text('Header\n') w._prompt = 'prompt>' w._show_prompt() control = w._control # TAB with multiline selection should block-indent w._set_input_buffer("") c = control.textCursor() pos=c.position() w._set_input_buffer("If 1:\n pass") c.setPosition(pos, QtGui.QTextCursor.KeepAnchor) control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_Tab) self.assertEqual(w._get_input_buffer()," If 1:\n pass") # TAB with multiline selection, should block-indent to next multiple # of 4 spaces, if first line has 0 < indent < 4 w._set_input_buffer("") c = control.textCursor() pos=c.position() w._set_input_buffer(" If 2:\n pass") c.setPosition(pos, QtGui.QTextCursor.KeepAnchor) control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_Tab) self.assertEqual(w._get_input_buffer()," If 2:\n pass") # Shift-TAB with multiline selection should block-dedent w._set_input_buffer("") c = control.textCursor() pos=c.position() w._set_input_buffer(" If 3:\n pass") c.setPosition(pos, QtGui.QTextCursor.KeepAnchor) control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_Backtab) self.assertEqual(w._get_input_buffer(),"If 3:\n pass")
def test_indent(self): """Test the event handling code for indent/dedent keypresses .""" w = ConsoleWidget() w._append_plain_text('Header\n') w._prompt = 'prompt>' w._show_prompt() control = w._control # TAB with multiline selection should block-indent w._set_input_buffer("") c = control.textCursor() pos = c.position() w._set_input_buffer("If 1:\n pass") c.setPosition(pos, QtGui.QTextCursor.KeepAnchor) control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_Tab) self.assertEqual(w._get_input_buffer(), " If 1:\n pass") # TAB with multiline selection, should block-indent to next multiple # of 4 spaces, if first line has 0 < indent < 4 w._set_input_buffer("") c = control.textCursor() pos = c.position() w._set_input_buffer(" If 2:\n pass") c.setPosition(pos, QtGui.QTextCursor.KeepAnchor) control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_Tab) self.assertEqual(w._get_input_buffer(), " If 2:\n pass") # Shift-TAB with multiline selection should block-dedent w._set_input_buffer("") c = control.textCursor() pos = c.position() w._set_input_buffer(" If 3:\n pass") c.setPosition(pos, QtGui.QTextCursor.KeepAnchor) control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_Backtab) self.assertEqual(w._get_input_buffer(), "If 3:\n pass")
def test_keypresses(self): """Test the event handling code for keypresses.""" w = ConsoleWidget() w._append_plain_text('Header\n') w._prompt = 'prompt>' w._show_prompt() control = w._control # Test setting the input buffer w._set_input_buffer('test input') self.assertEqual(w._get_input_buffer(), 'test input') # Ctrl+K kills input until EOL w._set_input_buffer('test input') c = control.textCursor() c.setPosition(c.position() - 3) control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_K, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), 'test in') # Ctrl+V pastes w._set_input_buffer('test input ') QtGui.qApp.clipboard().setText('pasted text') QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), 'test input pasted text') self.assertEqual(control.document().blockCount(), 2) # Paste should strip indentation w._set_input_buffer('test input ') QtGui.qApp.clipboard().setText(' pasted text') QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), 'test input pasted text') self.assertEqual(control.document().blockCount(), 2) # Multiline paste, should also show continuation marks w._set_input_buffer('test input ') QtGui.qApp.clipboard().setText('line1\nline2\nline3') QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), 'test input line1\nline2\nline3') self.assertEqual(control.document().blockCount(), 4) self.assertEqual(control.document().findBlockByNumber(1).text(), 'prompt>test input line1') self.assertEqual(control.document().findBlockByNumber(2).text(), '> line2') self.assertEqual(control.document().findBlockByNumber(3).text(), '> line3') # Multiline paste should strip indentation intelligently # in the case where pasted text has leading whitespace on first line # and we're pasting into indented position w._set_input_buffer(' ') QtGui.qApp.clipboard().setText(' If 1:\n pass') QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), ' If 1:\n pass') # Ctrl+Backspace should intelligently remove the last word w._set_input_buffer("foo = ['foo', 'foo', 'foo', \n" " 'bar', 'bar', 'bar']") QTest.keyClick(control, QtCore.Qt.Key_Backspace, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), ("foo = ['foo', 'foo', 'foo', \n" " 'bar', 'bar', '")) QTest.keyClick(control, QtCore.Qt.Key_Backspace, QtCore.Qt.ControlModifier) QTest.keyClick(control, QtCore.Qt.Key_Backspace, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), ("foo = ['foo', 'foo', 'foo', \n" " '")) QTest.keyClick(control, QtCore.Qt.Key_Backspace, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), ("foo = ['foo', 'foo', 'foo', \n" "")) QTest.keyClick(control, QtCore.Qt.Key_Backspace, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), "foo = ['foo', 'foo', 'foo',") # Ctrl+Delete should intelligently remove the next word w._set_input_buffer("foo = ['foo', 'foo', 'foo', \n" " 'bar', 'bar', 'bar']") c = control.textCursor() c.setPosition(35) control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_Delete, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), ("foo = ['foo', 'foo', ', \n" " 'bar', 'bar', 'bar']")) QTest.keyClick(control, QtCore.Qt.Key_Delete, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), ("foo = ['foo', 'foo', \n" " 'bar', 'bar', 'bar']")) QTest.keyClick(control, QtCore.Qt.Key_Delete, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), "foo = ['foo', 'foo', 'bar', 'bar', 'bar']") w._set_input_buffer("foo = ['foo', 'foo', 'foo', \n" " 'bar', 'bar', 'bar']") c = control.textCursor() c.setPosition(48) control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_Delete, QtCore.Qt.ControlModifier) self.assertEqual(w._get_input_buffer(), ("foo = ['foo', 'foo', 'foo', \n" "'bar', 'bar', 'bar']")) # Left and right keys should respect the continuation prompt w._set_input_buffer("line 1\n" "line 2\n" "line 3") c = control.textCursor() c.setPosition(20) # End of line 1 control.setTextCursor(c) QTest.keyClick(control, QtCore.Qt.Key_Right) # Cursor should have moved after the continuation prompt self.assertEqual(control.textCursor().position(), 23) QTest.keyClick(control, QtCore.Qt.Key_Left) # Cursor should have moved to the end of the previous line self.assertEqual(control.textCursor().position(), 20)