diff --git a/spyder/plugins/editor/widgets/tests/test_comments.py b/spyder/plugins/editor/widgets/tests/test_comments.py index 7f0684977ff..568f02da6aa 100644 --- a/spyder/plugins/editor/widgets/tests/test_comments.py +++ b/spyder/plugins/editor/widgets/tests/test_comments.py @@ -53,109 +53,74 @@ def code_editor_bot(qtbot): def test_single_line_comment(code_editor_bot): """Test toggle comment in a single line.""" editor, qtbot = code_editor_bot - text = ("#class a():\n" - "# self.b = 1\n" - " # print(self.b)\n" - "# \n" - ) - editor.set_text(text) - # Toggle comment without spaces from the prefix and manually inserted + TEXT = ("a = (1,\n" + " 2)\n" + "ab = (1,\n" + " 2)\n" + "\n") + editor.set_text(TEXT) + # Toggle comment on text = toggle_comment(editor) - assert text == ("class a():\n" - "# self.b = 1\n" - " # print(self.b)\n" - "# \n" - ) - # Toggle comment with space insertion + assert text == ("# a = (1,\n" + " 2)\n" + "ab = (1,\n" + " 2)\n" + "\n") + # Toggle comment off text = toggle_comment(editor) - assert text == ("# class a():\n" - "# self.b = 1\n" - " # print(self.b)\n" - "# \n" - ) - # Toggle comment deleting the insert space - text = toggle_comment(editor) - assert text == ("class a():\n" - "# self.b = 1\n" - " # print(self.b)\n" - "# \n" - ) - # Toggle comment with space at the right of prefix but manually inserted - text = toggle_comment(editor, start_line=2) - assert text == ("class a():\n" - " self.b = 1\n" - " # print(self.b)\n" - "# \n" - ) - # Toggle comment with space insertion + assert text == TEXT + # Toggle comment on with leading spaces text = toggle_comment(editor, start_line=2) - assert text == ("class a():\n" - " # self.b = 1\n" - " # print(self.b)\n" - "# \n" - ) - # Toggle comment deleting inserted space + assert text == ("a = (1,\n" + " # 2)\n" + "ab = (1,\n" + " 2)\n" + "\n") + # Toggle comment off with leading spaces text = toggle_comment(editor, start_line=2) - assert text == ("class a():\n" - " self.b = 1\n" - " # print(self.b)\n" - "# \n" - ) - # Toggle comment with space at the right and left of prefix - # but manually inserted - text = toggle_comment(editor, start_line=3) - assert text == ("class a():\n" - " self.b = 1\n" - " print(self.b)\n" - "# \n" - ) - + assert text == TEXT + # Toggle comment on with empty line + text = toggle_comment(editor, start_line=5) + assert text == ("a = (1,\n" + " 2)\n" + "ab = (1,\n" + " 2)\n" + "# \n") + # Toggle comment off with empty line + text = toggle_comment(editor, start_line=5) + assert text == TEXT + # Manually inserted comment + TEXT = ("#a = 1\n") + editor.set_text(TEXT) + # Toggle manually inserted comment off + text = toggle_comment(editor) + assert text == ("a = 1\n") + # Manually inserted comment with empty line + TEXT = ("#\n") + editor.set_text(TEXT) + # Toggle manually inserted comment off with empty line + text = toggle_comment(editor) + assert text == ("\n") def test_selection_comment(code_editor_bot): - """Test toggle comments with selection of more tha one line.""" + """Test toggle comments with selection of more than one line.""" editor, qtbot = code_editor_bot - text = ("#class a():\n" - "# self.b = 1\n" - " # print(self.b)\n" - "# \n" - ) - editor.set_text(text) - # Toggle manually commented code - text = toggle_comment(editor, single_line=False) - assert text == ("class a():\n" - " self.b = 1\n" - " print(self.b)\n" - " \n" - ) - # Toggle comment inserting prefix and space + TEXT = ("a = (1,\n" + " 2)\n" + "ab = (1,\n" + " 2)\n" + "\n") + editor.set_text(TEXT) + # Toggle comments on with multiple lines and indentation spaces text = toggle_comment(editor, single_line=False) - assert text == ("# class a():\n" - "# self.b = 1\n" - "# print(self.b)\n" - " \n" - ) - # Toggle comment deleting inserted prefix and space + assert text == ("# a = (1,\n" + "# 2)\n" + "# ab = (1,\n" + "# 2)\n" + "\n") + # Toggle comments off with multiple lines and indentation spaces text = toggle_comment(editor, single_line=False) - assert text == ("class a():\n" - " self.b = 1\n" - " print(self.b)\n" - " \n" - ) - # Test compatibility with Spyder 3 commenting structure - text = ("#class a():\n" - "# self.b = 1\n" - "# print(self.b)\n" - "# \n" - ) - editor.set_text(text) - # Toggle comment deleting inserted prefix (without space) - text = toggle_comment(editor, single_line=False) - assert text == ("class a():\n" - " self.b = 1\n" - " print(self.b)\n" - " \n" - ) - + assert text == TEXT if __name__ == "__main__": pytest.main()