Skip to content

Commit

Permalink
Testing: Replace repeated fixtures by codeeditor one
Browse files Browse the repository at this point in the history
Also remove unnecessary imports.
  • Loading branch information
ccordoba12 committed Dec 6, 2021
1 parent 6e45574 commit e9bc2f3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 71 deletions.
31 changes: 5 additions & 26 deletions spyder/plugins/editor/widgets/tests/test_comments.py
Expand Up @@ -12,10 +12,6 @@
import pytest
from qtpy.QtGui import QTextCursor

# Local imports
from spyder.py3compat import to_text_string
from spyder.plugins.editor.widgets.codeeditor import CodeEditor


# --- Helper methods
# -----------------------------------------------------------------------------
Expand All @@ -28,31 +24,14 @@ def toggle_comment(editor, single_line=True, start_line=1):
editor.moveCursor(QTextCursor.End, mode=QTextCursor.KeepAnchor)
editor.toggle_comment()
text = editor.toPlainText()
return to_text_string(text)


# --- Fixtures
# -----------------------------------------------------------------------------
@pytest.fixture
def code_editor_bot(qtbot):
"""
Setup CodeEditor with some text useful for folding related tests.
"""
editor = CodeEditor(parent=None)
indent_chars = " " * 4
tab_stop_width_spaces = 4
language = "Python"
editor.setup_editor(language=language, indent_chars=indent_chars,
tab_stop_width_spaces=tab_stop_width_spaces)

return editor, qtbot
return str(text)


# --- Tests
# -----------------------------------------------------------------------------
def test_single_line_comment(code_editor_bot):
def test_single_line_comment(codeeditor):
"""Test toggle comment in a single line."""
editor, qtbot = code_editor_bot
editor = codeeditor
text = ("#class a():\n"
"# self.b = 1\n"
" # print(self.b)\n"
Expand Down Expand Up @@ -111,9 +90,9 @@ def test_single_line_comment(code_editor_bot):
)


def test_selection_comment(code_editor_bot):
def test_selection_comment(codeeditor):
"""Test toggle comments with selection of more tha one line."""
editor, qtbot = code_editor_bot
editor = codeeditor
text = ("#class a():\n"
"# self.b = 1\n"
" # print(self.b)\n"
Expand Down
23 changes: 3 additions & 20 deletions spyder/plugins/editor/widgets/tests/test_decorations.py
Expand Up @@ -14,7 +14,7 @@
from flaky import flaky
import pytest
from qtpy.QtCore import Qt
from qtpy.QtGui import QFont, QTextCursor, QTextFormat
from qtpy.QtGui import QFont, QTextCursor

# Local imports
from spyder.plugins.editor.widgets.codeeditor import CodeEditor
Expand All @@ -24,26 +24,9 @@
PARENT = osp.dirname(HERE)


# --- Fixtures
# -----------------------------------------------------------------------------
@pytest.fixture
def construct_editor(qtbot):
"""Construct editor for testing decorations."""
editor = CodeEditor(parent=None)
editor.setup_editor(
language='Python',
color_scheme='spyder/dark',
font=QFont("Monospace", 10),
)
editor.resize(640, 480)
editor.show()
qtbot.addWidget(editor)
return editor


def test_decorations(construct_editor, qtbot):
def test_decorations(codeeditor, qtbot):
"""Test decorations."""
editor = construct_editor
editor = codeeditor

# Set random size
editor.resize(640, random.randint(200, 500))
Expand Down
2 changes: 0 additions & 2 deletions spyder/plugins/editor/widgets/tests/test_folding.py
Expand Up @@ -14,8 +14,6 @@
import pytest
from qtpy.QtCore import Qt

# Local imports
from spyder.widgets.findreplace import FindReplace

# ---Fixtures-----------------------------------------------------------------
text = """
Expand Down
41 changes: 18 additions & 23 deletions spyder/plugins/editor/widgets/tests/test_indentation.py
Expand Up @@ -41,25 +41,20 @@ def make_unindent(editor, single_line=True, start_line=1):
# --- Fixtures
# -----------------------------------------------------------------------------
@pytest.fixture
def code_editor_indent_bot(qtbot):
def codeeditor_indent(codeeditor):
"""
Setup CodeEditor with some text useful for folding related tests.
"""
editor = CodeEditor(parent=None)
indent_chars = " " * 2
tab_stop_width_spaces = 4
language = "Python"
editor.setup_editor(language=language, indent_chars=indent_chars,
tab_stop_width_spaces=tab_stop_width_spaces)

return editor, qtbot
editor = codeeditor
editor.set_indent_chars(" " * 2)
return editor


# --- Tests
# -----------------------------------------------------------------------------
def test_single_line_indent(code_editor_indent_bot):
def test_single_line_indent(codeeditor_indent):
"""Test indentation in a single line."""
editor, qtbot = code_editor_indent_bot
editor = codeeditor_indent
text = ("class a():\n"
"self.b = 1\n"
"print(self.b)\n"
Expand All @@ -76,9 +71,9 @@ def test_single_line_indent(code_editor_indent_bot):
assert new_text == expected


def test_selection_indent(code_editor_indent_bot):
def test_selection_indent(codeeditor_indent):
"""Test indentation with selection of more than one line."""
editor, qtbot = code_editor_indent_bot
editor = codeeditor_indent
text = ("class a():\n"
"self.b = 1\n"
"print(self.b)\n"
Expand All @@ -96,9 +91,9 @@ def test_selection_indent(code_editor_indent_bot):
assert new_text == expected


def test_fix_indentation(code_editor_indent_bot):
def test_fix_indentation(codeeditor_indent):
"""Test fix_indentation() method."""
editor, qtbot = code_editor_indent_bot
editor = codeeditor_indent
# Contains tabs.
original = ("\t\n"
"class a():\t\n"
Expand Down Expand Up @@ -126,9 +121,9 @@ def test_fix_indentation(code_editor_indent_bot):
assert editor.document().isModified()


def test_single_line_unindent(code_editor_indent_bot):
def test_single_line_unindent(codeeditor_indent):
"""Test unindentation in a single line."""
editor, qtbot = code_editor_indent_bot
editor = codeeditor_indent
text = ("class a():\n"
" self.b = 1\n"
"print(self.b)\n"
Expand All @@ -145,9 +140,9 @@ def test_single_line_unindent(code_editor_indent_bot):
assert new_text == expected


def test_selection_unindent(code_editor_indent_bot):
def test_selection_unindent(codeeditor_indent):
"""Test unindentation with selection of more than one line."""
editor, qtbot = code_editor_indent_bot
editor = codeeditor_indent
text = ("class a():\n"
" self.b = 1\n"
" print(self.b)\n"
Expand All @@ -164,9 +159,9 @@ def test_selection_unindent(code_editor_indent_bot):
assert new_text == expected


def test_single_line_unindent_to_grid(code_editor_indent_bot):
def test_single_line_unindent_to_grid(codeeditor_indent):
"""Test unindentation in a single line."""
editor, qtbot = code_editor_indent_bot
editor = codeeditor_indent
text = ("class a():\n"
" self.b = 1\n"
"print(self.b)\n"
Expand All @@ -191,9 +186,9 @@ def test_single_line_unindent_to_grid(code_editor_indent_bot):
assert new_text2 == expected2


def test_selection_unindent_to_grid(code_editor_indent_bot):
def test_selection_unindent_to_grid(codeeditor_indent):
"""Test unindentation with selection of more than one line."""
editor, qtbot = code_editor_indent_bot
editor = codeeditor_indent
text = ("class a():\n"
" self.b = 1\n"
" print(self.b)\n"
Expand Down

0 comments on commit e9bc2f3

Please sign in to comment.