Skip to content

Commit

Permalink
Merge from 5.x: PR #16084
Browse files Browse the repository at this point in the history
Fixes #16079
  • Loading branch information
ccordoba12 committed Jul 27, 2021
2 parents 655f262 + 7f8e2c4 commit c0a3697
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
11 changes: 7 additions & 4 deletions spyder/plugins/editor/widgets/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,12 +1531,15 @@ def handle_hover_response(self, contents):
try:
content = contents['params']

if isinstance(content, list):
# Prevent sporious errors when a client return a list
# - Don't display hover if there's no content to display.
# - Prevent spurious errors when a client returns a list.
if not content or isinstance(content, list):
return

self.sig_display_object_info.emit(content,
self._request_hover_clicked)
self.sig_display_object_info.emit(
content,
self._request_hover_clicked
)
if content is not None and self._show_hint and self._last_point:
# This is located in spyder/widgets/mixins.py
word = self._last_hover_word
Expand Down
48 changes: 38 additions & 10 deletions spyder/plugins/editor/widgets/tests/test_hints_and_calltips.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,36 @@ def test_get_calltips(qtbot, completions_codeeditor, params):
@pytest.mark.order(2)
@pytest.mark.skipif(sys.platform == 'darwin', reason='Fails on Mac')
@pytest.mark.parametrize('params', [
# Parameter, Expected Output
('"".format', '-> str'),
('import math', 'module'),
(TEST_TEXT, TEST_DOCSTRING)
]
)
# Parameter, Expected Output
('"".format', '-> str'),
('import math', 'module'),
(TEST_TEXT, TEST_DOCSTRING)
]
)
def test_get_hints(qtbot, completions_codeeditor, params, capsys):
"""Test that the editor is returning hover hints."""
code_editor, _ = completions_codeeditor
param, expected_output_text = params

# Move mouse to another position to be sure the hover is displayed when
# the cursor is put on top of the tested word.
qtbot.mouseMove(code_editor, QPoint(400, 400))

# Set text in editor
code_editor.set_text(param)

# Get cursor coordinates
code_editor.moveCursor(QTextCursor.End)
qtbot.keyPress(code_editor, Qt.Key_Left)

# Wait a bit in case the window manager repositions the window.
qtbot.wait(1000)

# Position cursor on top of word we want the hover for.
x, y = code_editor.get_coordinates('cursor')
point = code_editor.calculate_real_position(QPoint(x, y))

# Get hover and compare
with qtbot.waitSignal(code_editor.sig_display_object_info,
timeout=30000) as blocker:
qtbot.mouseMove(code_editor, point)
Expand All @@ -175,20 +185,38 @@ def test_get_hints(qtbot, completions_codeeditor, params, capsys):
@pytest.mark.slow
@pytest.mark.order(2)
@pytest.mark.skipif(sys.platform == 'darwin', reason='Fails on Mac')
def test_get_hints_not_triggered(qtbot, completions_codeeditor):
@pytest.mark.parametrize('text', [
'def test():\n pass\n\ntest',
'# a comment',
'"a string"',
]
)
def test_get_hints_not_triggered(qtbot, completions_codeeditor, text):
"""Test that the editor is not returning hover hints for empty docs."""
code_editor, _ = completions_codeeditor

# Set text in editor
code_editor.set_text('def test():\n pass\n\ntest')
code_editor.set_text(text)

# Move mouse to another position.
qtbot.mouseMove(code_editor, QPoint(400, 400))

# Get cursor coordinates
code_editor.moveCursor(QTextCursor.End)
qtbot.keyPress(code_editor, Qt.Key_Left)

for _ in range(3):
qtbot.keyPress(code_editor, Qt.Key_Left)

# Wait a bit in case the window manager repositions the window.
qtbot.wait(1000)

# Position cursor on top of word we want the hover for.
x, y = code_editor.get_coordinates('cursor')
point = code_editor.calculate_real_position(QPoint(x, y))

with qtbot.waitSignal(code_editor.sig_display_object_info, timeout=30000):
# Check that no hover was generated.
with qtbot.waitSignal(code_editor.completions_response_signal,
timeout=30000):
qtbot.mouseMove(code_editor, point)
qtbot.mouseClick(code_editor, Qt.LeftButton, pos=point)
qtbot.wait(1000)
Expand Down

0 comments on commit c0a3697

Please sign in to comment.