Skip to content

Commit

Permalink
Tests: Mock TextEditor to catch errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jitseniesen committed Apr 18, 2024
1 parent c51726e commit f15ec05
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions spyder_line_profiler/tests/test_lineprofiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# Third party imports
from qtpy.QtCore import Qt
from unittest.mock import Mock, patch
from unittest.mock import patch

# Local imports
from spyder_line_profiler.spyder.widgets import SpyderLineProfilerWidget
Expand All @@ -40,11 +40,12 @@ def test_profile_and_display_results(qtbot, tmpdir):
with open(testfilename, 'w', encoding='utf-8') as f:
f.write(TEST_SCRIPT)

MockQMessageBox = Mock()

widget = SpyderLineProfilerWidget(None)
with patch.object(widget, 'get_conf',
return_value=sys.executable) as mock_get_conf:
return_value=sys.executable) as mock_get_conf, \
patch('spyder_line_profiler.spyder.widgets.TextEditor') \
as MockTextEditor:

widget.setup()
qtbot.addWidget(widget)
with qtbot.waitSignal(widget.sig_finished, timeout=10000,
Expand All @@ -53,7 +54,7 @@ def test_profile_and_display_results(qtbot, tmpdir):

mock_get_conf.assert_called_once_with(
'executable', section='main_interpreter')
MockQMessageBox.assert_not_called()
MockTextEditor.assert_not_called()

dt = widget.datatree
assert dt.topLevelItemCount() == 1 # number of functions profiled
Expand Down

0 comments on commit f15ec05

Please sign in to comment.