Skip to content

Commit

Permalink
monkeypatch old spyder versions for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
skjerns committed Mar 18, 2022
1 parent 3ec43e1 commit 42049ee
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions spyder_line_profiler/tests/test_lineprofiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
MAIN_APP = qapplication()

# Local imports
import spyder
import spyder_line_profiler
from spyder_line_profiler.spyder.widgets import SpyderLineProfilerWidget
from spyder_line_profiler.spyder.widgets import PythonModulesComboBox


try:
from unittest.mock import Mock
except ImportError:
Expand All @@ -33,6 +38,19 @@ def foo():
for k in range(100):
xs = xs + ['x']
foo()"""


class MockPythonModulesComboBox(PythonModulesComboBox):

def __init__(self, parent, adjust_to_contents=False, id_=None, **kwargs):
version = int(''.join([str(x) for x in spyder.version_info]))
if version>=512:
PythonModulesComboBox.__init__(self, parent=parent, id_=id_,
adjust_to_contents=adjust_to_contents)
else:
PythonModulesComboBox.__init__(self, parent=parent,
adjust_to_contents=adjust_to_contents)


def test_profile_and_display_results(qtbot, tmpdir, monkeypatch):
"""Run profiler on simple script and check that results are okay."""
Expand All @@ -44,6 +62,7 @@ def test_profile_and_display_results(qtbot, tmpdir, monkeypatch):

MockQMessageBox = Mock()

spyder_line_profiler.spyder.widgets.PythonModulesComboBox = MockPythonModulesComboBox
widget = SpyderLineProfilerWidget(None)
widget.setup()
qtbot.addWidget(widget)
Expand Down

0 comments on commit 42049ee

Please sign in to comment.