-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
test_findreplace.py
86 lines (69 loc) · 2.2 KB
/
test_findreplace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#
"""
Tests for pathmanager.py
"""
# Standard library imports
import sys
import os
# Test library imports
import pytest
from qtpy.QtCore import Qt, QTimer
from qtpy.QtWidgets import QMessageBox, QPushButton
# Local imports
from spyder.plugins.editor.widgets.codeeditor import CodeEditor
from spyder.widgets.findreplace import FindReplace
@pytest.fixture
def findreplace_editor(qtbot, request):
"""Set up PathManager."""
editor = CodeEditor()
editor.setup_editor()
widget = FindReplace(None)
widget.set_editor(editor)
qtbot.addWidget(widget)
qtbot.addWidget(editor)
return widget, editor
def test_findreplace_multiline_replacement(findreplace_editor, qtbot):
"""
Test find replace widget for multiline regex replacements
See: spyder-ide/spyder#2675
"""
expected = '\n\nhello world!\n\n'
findreplace, editor = findreplace_editor
editor.set_text('\n\nhello\n\n\nworld!\n\n')
editor.show()
findreplace.show()
findreplace.show_replace()
findreplace.re_button.setChecked(True)
edit = findreplace.search_text.lineEdit()
edit.clear()
edit.setText('\\n\\n\\n')
findreplace.replace_text.setCurrentText(' ')
qtbot.wait(1000)
findreplace.replace_find_all()
qtbot.wait(1000)
assert editor.toPlainText() == expected
def test_replace_selection(findreplace_editor, qtbot):
"""Test find replace final selection in the editor.
For further information see spyder-ide/spyder#12745
"""
expected = 'Spyder is greit!\nSpyder is greit!'
findreplace, editor = findreplace_editor
editor.set_text('Spyder as great!\nSpyder as great!')
editor.show()
editor.select_lines(0, 2)
findreplace.show()
findreplace.show_replace()
edit = findreplace.search_text.lineEdit()
edit.clear()
edit.setText('a')
findreplace.replace_text.setCurrentText('i')
findreplace.replace_find_selection()
qtbot.wait(1000)
assert editor.get_selected_text() == expected
assert len(editor.get_selected_text()) == len(expected)
if __name__ == "__main__":
pytest.main([os.path.basename(__file__)])