From 1bc25e4e2443df8e8248887a8a93b32944a5296a Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Fri, 10 Jan 2025 16:19:10 -0500 Subject: [PATCH] Editor: Fix code style for some multicursor tests --- .../codeeditor/tests/test_multicursor.py | 113 ++++++++++-------- 1 file changed, 66 insertions(+), 47 deletions(-) diff --git a/spyder/plugins/editor/widgets/codeeditor/tests/test_multicursor.py b/spyder/plugins/editor/widgets/codeeditor/tests/test_multicursor.py index a2d532b2e6b..2bb09e8d619 100644 --- a/spyder/plugins/editor/widgets/codeeditor/tests/test_multicursor.py +++ b/spyder/plugins/editor/widgets/codeeditor/tests/test_multicursor.py @@ -79,7 +79,6 @@ def test_add_cursor(codeeditor, qtbot): qtbot.keyClick(codeeditor, "b") assert codeeditor.toPlainText() == "a01234b5a6789" - # Don't add another cursor on top of main cursor click_at(codeeditor, qtbot, 7, ctrl=True, alt=True) assert not bool(codeeditor.extra_cursors) @@ -87,7 +86,6 @@ def test_add_cursor(codeeditor, qtbot): # Test removing cursors click_at(codeeditor, qtbot, 2, ctrl=True, alt=True) - # Remove main cursor click_at(codeeditor, qtbot, 2, ctrl=True, alt=True) assert codeeditor.textCursor().position() == 7 @@ -107,7 +105,6 @@ def test_column_add_cursor(codeeditor, qtbot): ) codeeditor.setTextCursor(cursor) - # Column cursor click at top row 6th column click_at(codeeditor, qtbot, 6, ctrl=True, alt=True, shift=True) @@ -165,7 +162,6 @@ def test_multi_cursor_verticalMovementX(codeeditor, qtbot): assert codeeditor.extra_cursors[0].position() == 25 assert codeeditor.textCursor().position() == 35 - for _ in range(3): qtbot.keyClick(codeeditor, Qt.Key.Key_Up) assert codeeditor.extra_cursors[0].position() == 4 @@ -237,72 +233,95 @@ def test_overwrite_mode(codeeditor, qtbot): # assert codeeditor._drag_cursor is None # assert codeeditor.toPlainText() == "abcdefghij\n0123456789\n" +# fmt: off +# Disable formatting so that Black/Ruff don't incorrectly format the multiline +# strings below. def test_smart_text(codeeditor, qtbot): """ Test smart text features: Smart backspace, whitespace insertion, colon insertion, parenthesis and quote matching. """ - codeeditor.set_text("def test1\n" - "def test2\n") + # Closing paren was inserted? + codeeditor.set_text("def test1\ndef test2\n") click_at(codeeditor, qtbot, 9) click_at(codeeditor, qtbot, 19, ctrl=True, alt=True) qtbot.keyClick(codeeditor, Qt.Key.Key_ParenLeft) - # Closing paren was inserted? - assert codeeditor.toPlainText() == ("def test1()\n" - "def test2()\n") - qtbot.keyClick(codeeditor, Qt.Key.Key_ParenRight) + assert codeeditor.toPlainText() == ("def test1()\ndef test2()\n") + # Typing close paren advances cursor without adding extra paren? - assert codeeditor.toPlainText() == ("def test1()\n" - "def test2()\n") - qtbot.keyClick(codeeditor, Qt.Key.Key_Return) + qtbot.keyClick(codeeditor, Qt.Key.Key_ParenRight) + assert codeeditor.toPlainText() == ("def test1()\ndef test2()\n") + # Auto colon and indent? - assert codeeditor.toPlainText() == ("def test1():\n" - " \n" - "def test2():\n" - " \n") + qtbot.keyClick(codeeditor, Qt.Key.Key_Return) + assert codeeditor.toPlainText() == ( + "def test1():\n" + " \n" + "def test2():\n" + " \n" + ) + # Add some extraneous whitespace qtbot.keyClick(codeeditor, Qt.Key.Key_Tab) qtbot.keyClick(codeeditor, Qt.Key.Key_Tab) - assert codeeditor.toPlainText() == ("def test1():\n" - " \n" - "def test2():\n" - " \n") - qtbot.keyClick(codeeditor, Qt.Key.Key_Backspace) + assert codeeditor.toPlainText() == ( + "def test1():\n" + " \n" + "def test2():\n" + " \n" + ) + # Smart backspace to correct indent? - assert codeeditor.toPlainText() == ("def test1():\n" - " \n" - "def test2():\n" - " \n") + qtbot.keyClick(codeeditor, Qt.Key.Key_Backspace) + assert codeeditor.toPlainText() == ( + "def test1():\n" + " \n" + "def test2():\n" + " \n" + ) + for cursor in codeeditor.all_cursors: cursor.insertText("return") - assert codeeditor.toPlainText() == ("def test1():\n" - " return\n" - "def test2():\n" - " return\n") + assert codeeditor.toPlainText() == ( + "def test1():\n" + " return\n" + "def test2():\n" + " return\n" + ) + + # Automatic quote codeeditor.set_close_quotes_enabled(True) qtbot.keyClick(codeeditor, Qt.Key.Key_Space) qtbot.keyClick(codeeditor, Qt.Key.Key_Apostrophe) - # Automatic quote - assert codeeditor.toPlainText() == ("def test1():\n" - " return ''\n" - "def test2():\n" - " return ''\n") - qtbot.keyClick(codeeditor, Qt.Key.Key_Apostrophe) + assert codeeditor.toPlainText() == ( + "def test1():\n" + " return ''\n" + "def test2():\n" + " return ''\n" + ) + # Automatic close quote - assert codeeditor.toPlainText() == ("def test1():\n" - " return ''\n" - "def test2():\n" - " return ''\n") - qtbot.keyClick(codeeditor, Qt.Key.Key_Return) + qtbot.keyClick(codeeditor, Qt.Key.Key_Apostrophe) + assert codeeditor.toPlainText() == ( + "def test1():\n" + " return ''\n" + "def test2():\n" + " return ''\n" + ) + # Automatic dedent? - assert codeeditor.toPlainText() == ("def test1():\n" - " return ''\n" - "\n" - "def test2():\n" - " return ''\n" - "\n") + qtbot.keyClick(codeeditor, Qt.Key.Key_Return) + assert codeeditor.toPlainText() == ( + "def test1():\n" + " return ''\n" + "\n" + "def test2():\n" + " return ''\n" + "\n" + ) +# fmt: on # ---- shortcuts