def test_editor_rstrip_keypress( editorbot, input_text, expected_text, keys, strip_all): """ Test that whitespace is removed when leaving a line. """ qtbot, widget = editorbot widget.strip_trailing_spaces_on_modify = strip_all widget.set_text(input_text) cursor = widget.textCursor() cursor.movePosition(QTextCursor.End) widget.setTextCursor(cursor) for key in keys: if isinstance(key, tuple): # Mouse event button, position = key cursor = widget.textCursor() cursor.setPosition(position) xypos = widget.cursorRect(cursor).center() widget.mousePressEvent(QMouseEvent( QEvent.MouseButtonPress, xypos, button, button, Qt.NoModifier)) else: qtbot.keyPress(widget, key) assert widget.toPlainText() == expected_text
def test_undo_return(editorbot): """Test that we can undo a return.""" qtbot, editor = editorbot text = "if True:\n 0" returned_text = "if True:\n 0\n " editor.set_text(text) cursor = editor.textCursor() cursor.setPosition(14) editor.setTextCursor(cursor) qtbot.keyPress(editor, Qt.Key_Return) assert editor.toPlainText() == returned_text qtbot.keyPress(editor, "z", modifier=Qt.ControlModifier) assert editor.toPlainText() == text
def test_comment(editorbot): """ Test that in_string works correctly. """ qtbot, widget = editorbot widget.set_text("import numpy") cursor = widget.textCursor() cursor.setPosition(8) cursor.setPosition(11, QTextCursor.KeepAnchor) widget.setTextCursor(cursor) qtbot.keyPress(widget, "1", modifier=Qt.ControlModifier) assert widget.toPlainText() == "# import numpy" qtbot.keyPress(widget, "1", modifier=Qt.ControlModifier) assert widget.toPlainText() == "import numpy"
def test_editor_delete_char(editorbot): """Regression test for issue spyder-ide/spyder#12663.""" qtbot, editor = editorbot text = "0123456789\nabcdefghij\n9876543210\njihgfedcba\n" editor.set_text(text) expected_column = 2 cursor = editor.textCursor() cursor.setPosition(expected_column) editor.setTextCursor(cursor) for line in range(3): qtbot.keyPress(editor, Qt.Key_Delete) assert editor.textCursor().columnNumber() == expected_column qtbot.keyPress(editor, Qt.Key_Down) assert editor.textCursor().columnNumber() == expected_column for line in range(3): qtbot.keyPress(editor, Qt.Key_Delete) assert editor.textCursor().columnNumber() == expected_column qtbot.keyPress(editor, Qt.Key_Up) assert editor.textCursor().columnNumber() == expected_column
def test_array_inline_force_float_error_array(botinlinefloat): qtbot, dialog, widget = botinlinefloat qtbot.keyClicks(widget, '4 5 6 a 9') qtbot.keyPress(widget, Qt.Key_Return, modifier=Qt.ControlModifier) value = dialog.text() assert value == 'np.matrix([4.0, 5.0, 6.0, a, 9.0])'
def test_array_inline_nan_array(botinline): qtbot, dialog, widget = botinline qtbot.keyClicks(widget, '4 nan 6 8 9') qtbot.keyPress(widget, Qt.Key_Return, modifier=Qt.ControlModifier) value = dialog.text() assert value == 'np.matrix([4, np.nan, 6, 8, 9])'
def test_array_inline_array_invalid(botinline): qtbot, dialog, widget = botinline qtbot.keyClicks(widget, '1 2 3 4 5 6 7') qtbot.keyPress(widget, Qt.Key_Return) dialog.update_warning() assert not dialog.is_valid()
def test_array_inline_matrix(botinline): qtbot, dialog, widget = botinline qtbot.keyClicks(widget, '4 5 6 7 8 9') qtbot.keyPress(widget, Qt.Key_Return, modifier=Qt.ControlModifier) value = dialog.text() assert value == 'np.matrix([[4, 5, 6],\n [7, 8, 9]])'
def test_array_inline_array(botinline): qtbot, dialog, widget = botinline qtbot.keyClicks(widget, '1 2 3 4 5 6') qtbot.keyPress(widget, Qt.Key_Return) value = dialog.text() assert value == 'np.array([[1, 2, 3],\n [4, 5, 6]])'
def test_editor_delete_selection(editorbot): """Regression test for issue spyder-ide/spyder#12663.""" qtbot, editor = editorbot text = "0123456789\nabcdefghij\n9876543210\njihgfedcba\n" editor.set_text(text) expected_column = 5 cursor = editor.textCursor() cursor.setPosition(expected_column) editor.setTextCursor(cursor) # This first subtest does not trigger the original bug for press in range(3): qtbot.keyPress(editor, Qt.Key_Left, Qt.ShiftModifier) expected_column -= 3 qtbot.keyPress(editor, Qt.Key_Delete) assert editor.textCursor().columnNumber() == expected_column qtbot.keyPress(editor, Qt.Key_Down) assert editor.textCursor().columnNumber() == expected_column # However, this second subtest does trigger the original bug for press in range(3): qtbot.keyPress(editor, Qt.Key_Right, Qt.ShiftModifier) qtbot.keyPress(editor, Qt.Key_Delete) assert editor.textCursor().columnNumber() == expected_column qtbot.keyPress(editor, Qt.Key_Up) assert editor.textCursor().columnNumber() == expected_column