Skip to content

Commit

Permalink
Fix test by providing conf value for executable
Browse files Browse the repository at this point in the history
The Spyder conf value for `main_interpreter/executable` is set in
the maininterpreter plugin, which the test does not initialize.
Thus, we provide the conf value explicitly in the test.
  • Loading branch information
jitseniesen committed May 22, 2023
1 parent c5bf915 commit 46bcf9b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions spyder_line_profiler/tests/test_lineprofiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

# Standard library imports
import os
import sys

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

# Local imports
from spyder_line_profiler.spyder.widgets import SpyderLineProfilerWidget
Expand All @@ -27,7 +28,7 @@ def foo():
xs = xs + ['x']
foo()"""


def test_profile_and_display_results(qtbot, tmpdir):
"""Run profiler on simple script and check that results are okay."""
os.chdir(tmpdir.strpath)
Expand All @@ -39,23 +40,29 @@ def test_profile_and_display_results(qtbot, tmpdir):
MockQMessageBox = Mock()

widget = SpyderLineProfilerWidget(None)
widget.setup()
qtbot.addWidget(widget)
with qtbot.waitSignal(widget.sig_finished, timeout=10000, raising=True):
widget.analyze(testfilename)
with patch.object(widget, 'get_conf',
return_value=sys.executable) as mock_get_conf:
widget.setup()
qtbot.addWidget(widget)
with qtbot.waitSignal(widget.sig_finished, timeout=10000,
raising=True):
widget.analyze(testfilename)

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

dt = widget.datatree
assert dt.topLevelItemCount() == 1 # number of functions profiled
top = dt.topLevelItem(0)

top = dt.topLevelItem(0)
assert top.data(0, Qt.DisplayRole).startswith('foo ')
assert top.childCount() == 6
for i in range(6):
assert top.child(i).data(0, Qt.DisplayRole) == i + 2 # line no

assert top.child(2).data(1, Qt.DisplayRole) == '1' # hits
assert top.child(3).data(1, Qt.DisplayRole) == '1'
assert top.child(3).data(1, Qt.DisplayRole) == '1'
assert top.child(4).data(1, Qt.DisplayRole) in ['100', '101'] # result depends on Python version
assert top.child(5).data(1, Qt.DisplayRole) == '100'

Expand Down

0 comments on commit 46bcf9b

Please sign in to comment.