Skip to content

Commit

Permalink
Merge from 3.1.x: PR #4079
Browse files Browse the repository at this point in the history
Fixes #4072
  • Loading branch information
ccordoba12 committed Jan 31, 2017
2 parents 537fd0c + 53b5d71 commit 6d2cd29
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
26 changes: 26 additions & 0 deletions spyder/utils/fixtures.py
Expand Up @@ -11,11 +11,18 @@
# Standard library imports
import shutil
import tempfile
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock # Python 2

# Third party imports
import pytest

# Local imports
# Local imports
from spyder.widgets.editor import EditorStack
from spyder.widgets.findreplace import FindReplace
from spyder.config.user import UserConfig
from spyder.config.main import CONF_VERSION, DEFAULTS

Expand All @@ -41,3 +48,22 @@ def fin():

request.addfinalizer(fin)
return CONF

@pytest.fixture
def setup_editor(qtbot):
"""
Set up EditorStack with CodeEditor containing some Python code.
The cursor is at the empty line below the code.
Returns tuple with EditorStack and CodeEditor.
"""
text = ('a = 1\n'
'print(a)\n'
'\n'
'x = 2') # a newline is added at end
editorStack = EditorStack(None, [])
editorStack.set_introspector(Mock())
editorStack.set_find_widget(FindReplace(editorStack))
editorStack.set_io_actions(Mock(), Mock(), Mock(), Mock())
finfo = editorStack.new('foo.py', 'utf-8', text)
qtbot.addWidget(editorStack)
return editorStack, finfo.editor
2 changes: 2 additions & 0 deletions spyder/widgets/mixins.py
Expand Up @@ -477,6 +477,8 @@ def find_text(self, text, changed=True, forward=True, case=False,
findflag = QTextDocument.FindFlag()
if not forward:
findflag = findflag | QTextDocument.FindBackward
if case:
findflag = findflag | QTextDocument.FindCaseSensitively
moves = [QTextCursor.NoMove]
if forward:
moves += [QTextCursor.NextWord, QTextCursor.Start]
Expand Down
42 changes: 16 additions & 26 deletions spyder/widgets/tests/test_editor.py
Expand Up @@ -8,35 +8,11 @@
Tests for editor.py
"""

# Standard library imports
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock # Python 2

# Third party imports
import pytest

# Local imports
from spyder.widgets.editor import EditorStack

def setup_editor(qtbot):
"""
Set up EditorStack with CodeEditor containing some Python code.
The cursor is at the empty line below the code.
Returns tuple with EditorStack and CodeEditor.
"""
text = ('a = 1\n'
'print(a)\n'
'\n'
'x = 2') # a newline is added at end
editorStack = EditorStack(None, [])
editorStack.set_introspector(Mock())
editorStack.set_find_widget(Mock())
editorStack.set_io_actions(Mock(), Mock(), Mock(), Mock())
finfo = editorStack.new('foo.py', 'utf-8', text)
qtbot.addWidget(editorStack)
return editorStack, finfo.editor
from spyder.utils.fixtures import setup_editor

def test_run_top_line(qtbot):
editorStack, editor = setup_editor(qtbot)
Expand Down Expand Up @@ -84,6 +60,20 @@ def test_run_last_line_when_nonempty(qtbot):
assert editor.toPlainText() == expected_new_text # check blank line got added
assert editor.get_cursor_line_column() == (4, 0) # check cursor moves down


def test_find_replace_case_sensitive(qtbot):
editorStack, editor = setup_editor(qtbot)
editorStack.find_widget.case_button.setChecked(True)
text = ' test \nTEST \nTest \ntesT '
editor.set_text(text)
editorStack.find_widget.search_text.add_text('test')
editorStack.find_widget.replace_text.add_text('pass')
editorStack.find_widget.replace_find()
editorStack.find_widget.replace_find()
editorStack.find_widget.replace_find()
editorStack.find_widget.replace_find()
editor_text = editor.toPlainText()
assert editor_text == ' pass \nTEST \nTest \ntesT '


if __name__ == "__main__":
pytest.main()

0 comments on commit 6d2cd29

Please sign in to comment.