Skip to content

Commit

Permalink
Change tests to pass 653d6ae
Browse files Browse the repository at this point in the history
  • Loading branch information
remisalmon committed Feb 17, 2021
1 parent 653d6ae commit 5fde9ae
Showing 1 changed file with 59 additions and 94 deletions.
153 changes: 59 additions & 94 deletions spyder/plugins/editor/widgets/tests/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 5fde9ae

Please sign in to comment.