Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Update to Spyder 5.2 API #166

Merged
merged 7 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/linux-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
PYTHON_VERSION: ['3.6', '3.7', '3.8']
PYTHON_VERSION: ['3.7', '3.8', '3.9']
steps:
- name: Checkout branch
uses: actions/checkout@v2
Expand All @@ -28,11 +28,10 @@ jobs:
sudo apt-get update
sudo apt-get install libegl1-mesa
- name: Install Conda
uses: goanpeca/setup-miniconda@v1
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: test
channels: conda-forge
auto-update-conda: true
auto-activate-base: false
python-version: ${{ matrix.PYTHON_VERSION }}
- name: Install package dependencies
shell: bash -l {0}
Expand All @@ -55,6 +54,6 @@ jobs:
run: xvfb-run --auto-servernum pytest spyder_unittest --cov=spyder_unittest -x -vv
timeout-minutes: 10
- name: Upload coverage to Codecov
if: matrix.PYTHON_VERSION == '3.8'
if: matrix.PYTHON_VERSION == '3.9'
shell: bash -l {0}
run: codecov -t 3458851b-c7a5-4108-be5e-9d19066a2fde
7 changes: 3 additions & 4 deletions .github/workflows/macos-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ jobs:
strategy:
fail-fast: false
matrix:
PYTHON_VERSION: ['3.6', '3.7', '3.8']
PYTHON_VERSION: ['3.7', '3.8', '3.9']
steps:
- name: Checkout branch
uses: actions/checkout@v2
- name: Install Conda
uses: goanpeca/setup-miniconda@v1
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: test
channels: conda-forge
auto-update-conda: true
auto-activate-base: false
python-version: ${{ matrix.PYTHON_VERSION }}
- name: Install package dependencies
shell: bash -l {0}
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/windows-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ jobs:
strategy:
fail-fast: false
matrix:
PYTHON_VERSION: ['3.6', '3.7', '3.8']
PYTHON_VERSION: ['3.7', '3.8', '3.9']
steps:
- name: Checkout branch
uses: actions/checkout@v2
- name: Install Conda
uses: goanpeca/setup-miniconda@v1
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: test
channels: conda-forge
auto-update-conda: true
auto-activate-base: false
python-version: ${{ matrix.PYTHON_VERSION }}
- name: Install package dependencies
shell: bash -l {0}
Expand Down
2 changes: 1 addition & 1 deletion requirements/conda.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
lxml
spyder
spyder>=5.2
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_package_data(name, extlist):


# Requirements
REQUIREMENTS = ['lxml', 'spyder>=3', 'pyzmq']
REQUIREMENTS = ['lxml', 'spyder>=5.2', 'pyzmq']
EXTLIST = ['.jpg', '.png', '.json', '.mo', '.ini']
LIBNAME = 'spyder_unittest'

Expand Down Expand Up @@ -72,4 +72,7 @@ def get_package_data(name, extlist):
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Testing',
'Topic :: Text Editors :: Integrated Development Environments (IDE)'])
'Topic :: Text Editors :: Integrated Development Environments (IDE)'],
entry_points={
'spyder.plugins': [
'unittest = spyder_unittest.unittestplugin:UnitTestPlugin']})
3 changes: 2 additions & 1 deletion spyder_unittest/backend/pytestrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def finished(self):
"""
self.reader.close()
output = self.read_all_process_output()
self.sig_finished.emit([] if "no tests ran" in output else None, output)
no_tests_ran = "no tests ran" in output.splitlines()[-1]
self.sig_finished.emit([] if no_tests_ran else None, output)


def normalize_module_name(name):
Expand Down
35 changes: 18 additions & 17 deletions spyder_unittest/tests/test_unittestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

# Third party imports
import pytest
from spyder.plugins.projects.projecttypes import EmptyProject
from spyder.plugins.projects.api import EmptyProject

# Local imports
from spyder_unittest.unittestplugin import UnitTestPlugin
from spyder_unittest.widgets.configdialog import Config

try:
from unittest.mock import Mock
from unittest.mock import MagicMock
except ImportError:
from mock import Mock # Python 2
from mock import MagicMock # Python 2


class PluginForTesting(UnitTestPlugin):
Expand All @@ -25,43 +25,42 @@ class PluginForTesting(UnitTestPlugin):
def __init__(self, parent):
UnitTestPlugin.__init__(self, parent)


@pytest.fixture
def plugin(qtbot):
"""Set up the unittest plugin."""
res = PluginForTesting(None)
qtbot.addWidget(res)
res.main = Mock()
res.main.get_spyder_pythonpath = lambda: 'fakepythonpath'
res.main.run_menu_actions = [42]
res.main.editor.pythonfile_dependent_actions = [42]
res.main.projects.get_active_project_path = lambda: None
res.register_plugin()
res = UnitTestPlugin(None, None)
res._main = MagicMock()
res._main.get_spyder_pythonpath = MagicMock(return_value='fakepythonpath')
res.initialize()
return res


@pytest.mark.skip('not clear how to test interactions between plugins')
def test_plugin_initialization(plugin):
plugin.show()
assert len(plugin.main.run_menu_actions) == 2
assert plugin.main.run_menu_actions[1].text() == 'Run unit tests'


def test_plugin_pythonpath(plugin):
# Test signal/slot connection
plugin.main.sig_pythonpath_changed.connect.assert_called_with(
plugin.get_main().sig_pythonpath_changed.connect.assert_called_with(
plugin.update_pythonpath)

# Test pythonpath is set to path provided by Spyder
assert plugin.unittestwidget.pythonpath == 'fakepythonpath'
assert plugin.get_widget().pythonpath == 'fakepythonpath'

# Test that change in path propagates
plugin.main.get_spyder_pythonpath = lambda: 'anotherpath'
plugin.get_main().get_spyder_pythonpath = MagicMock(
return_value='anotherpath')
plugin.update_pythonpath()
assert plugin.unittestwidget.pythonpath == 'anotherpath'
assert plugin.get_widget().pythonpath == 'anotherpath'


@pytest.mark.skip('not clear how to test interactions between plugins')
def test_plugin_wdir(plugin, monkeypatch, tmpdir):
# Test signal/slot connections
plugin.main.workingdirectory.set_explorer_cwd.connect.assert_called_with(
plugin.main.workingdirectory.sig_current_directory_changed.connect.assert_called_with(
plugin.update_default_wdir)
plugin.main.projects.sig_project_created.connect.assert_called_with(
plugin.handle_project_change)
Expand Down Expand Up @@ -90,6 +89,7 @@ def test_plugin_wdir(plugin, monkeypatch, tmpdir):
assert plugin.unittestwidget.default_wdir == 'fakecwd'


@pytest.mark.skip('not clear how to test interactions between plugins')
def test_plugin_config(plugin, tmpdir, qtbot):
# Test config file does not exist and config is empty
config_file_path = tmpdir.join('.spyproject', 'config', 'unittest.ini')
Expand Down Expand Up @@ -126,6 +126,7 @@ def test_plugin_config(plugin, tmpdir, qtbot):
assert plugin.unittestwidget.config == config


@pytest.mark.skip('not clear how to test interactions between plugins')
def test_plugin_goto_in_editor(plugin, qtbot):
plugin.unittestwidget.sig_edit_goto.emit('somefile', 42)
plugin.main.editor.load.assert_called_with('somefile', 43, '')
Loading