3
3
# Copyright © Spyder Project Contributors
4
4
# Licensed under the terms of the MIT License
5
5
#
6
+
6
7
"""Tests for close quotes."""
7
8
8
9
# Third party imports
9
10
import pytest
10
11
from qtpy .QtCore import Qt
11
- from qtpy .QtGui import QTextCursor
12
+ from qtpy .QtGui import QFont , QTextCursor
12
13
13
14
# Local imports
14
- from spyder .utils . qthelpers import qapplication
15
+ from spyder .config . base import running_in_ci
15
16
from spyder .plugins .editor .widgets .codeeditor import CodeEditor
16
17
from spyder .plugins .editor .utils .editor import TextHelper
17
18
from spyder .plugins .editor .extensions .closequotes import (
18
19
CloseQuotesExtension )
19
20
20
21
21
- # --- Fixtures
22
+ # ---- Fixtures
22
23
# -----------------------------------------------------------------------------
23
24
@pytest .fixture
24
- def editor_close_quotes ():
25
+ def editor_close_quotes (qtbot ):
25
26
"""Set up Editor with close quotes activated."""
26
- app = qapplication ()
27
27
editor = CodeEditor (parent = None )
28
- kwargs = {}
29
- kwargs ['language' ] = 'Python'
30
- kwargs ['close_quotes' ] = True
31
- editor .setup_editor (** kwargs )
32
- return editor
28
+ editor .setup_editor (
29
+ color_scheme = 'spyder/dark' ,
30
+ font = QFont ("Courier New" , 10 ),
31
+ language = 'Python' ,
32
+ close_quotes = True
33
+ )
33
34
34
- # --- Tests
35
- # -----------------------------------------------------------------------------
35
+ editor .resize (480 , 360 )
36
+ editor .show ()
37
+ qtbot .addWidget (editor )
38
+
39
+ return editor
36
40
37
41
42
+ # ---- Tests
43
+ # -----------------------------------------------------------------------------
38
44
@pytest .mark .parametrize (
39
45
'text, expected_text, cursor_column' ,
40
46
[
@@ -48,13 +54,19 @@ def editor_close_quotes():
48
54
("''''" , "''''''" , 3 ),
49
55
('"some_string"' , '"some_string"' , 13 ), # Write a string
50
56
("'some_string'" , "'some_string'" , 13 ),
57
+ (r'"\""' , r'"\""' , 4 ), # Write escaped quotes
58
+ (r"'\''" , r"'\''" , 4 ),
59
+ (r'"\\"' , r'"\\"' , 4 ), # Don't enter escaped quote if the previous
60
+ (r"'\\'" , r"'\\'" , 4 ), # char is a backslash (for Windows paths)
51
61
])
52
62
def test_close_quotes (qtbot , editor_close_quotes , text , expected_text ,
53
63
cursor_column ):
54
64
"""Test insertion of extra quotes."""
55
65
editor = editor_close_quotes
56
66
57
67
qtbot .keyClicks (editor , text )
68
+ if not running_in_ci ():
69
+ qtbot .wait (1000 )
58
70
assert editor .toPlainText () == expected_text
59
71
60
72
assert cursor_column == TextHelper (editor ).current_column_nbr ()
0 commit comments