Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclary committed Oct 11, 2024
1 parent fc01c80 commit 88a1bc5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 29 deletions.
18 changes: 11 additions & 7 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
get_home_dir, get_conf_path, get_module_path, running_in_ci,
running_in_ci_with_conda)
from spyder.config.manager import CONF
from spyder.config.utils import is_anaconda
from spyder.dependencies import DEPENDENCIES
from spyder.plugins.debugger.api import DebuggerWidgetActions
from spyder.plugins.externalterminal.api import ExtTerminalShConfiguration
Expand All @@ -90,6 +89,7 @@
from spyder.utils.clipboard_helper import CLIPBOARD_HELPER
from spyder.utils.programs import find_program
from spyder.widgets.dock import DockTitleBar
from spyder_kernels.utils.pythonenv import is_conda_env


@pytest.mark.order(1)
Expand Down Expand Up @@ -1503,7 +1503,9 @@ def test_run_code(main_window, qtbot, tmpdir):
shell.execute('a = 100')
editor.go_to_line(6)
qtbot.keyClick(code_editor, Qt.Key_Right)
run_from_line_action = main_window.run.get_action('run selection from line')
run_from_line_action = main_window.run.get_action(
'run selection from line'
)
with qtbot.waitSignal(shell.executed):
run_from_line_action.trigger()
qtbot.wait(500)
Expand Down Expand Up @@ -2268,7 +2270,7 @@ def test_plots_scroll(main_window, qtbot):
sb.set_current_index(5)
scrollbar.setValue(scrollbar.minimum())

# make sure we didn't scroll to the end and a new thumbnail was not selected
# Ensure we didn't scroll to the end and a new thumbnail was not selected
assert len(sb._thumbnails) == 45
assert sb._thumbnails[-1] != sb.current_thumbnail
assert scrollbar.value() != scrollbar.maximum()
Expand Down Expand Up @@ -3345,7 +3347,9 @@ def test_preferences_shortcut_reset_regression(main_window, qtbot):
@pytest.mark.order(1)
@flaky(max_runs=3)
@pytest.mark.order(before="test_PYTHONPATH_in_consoles")
@pytest.mark.skipif(not is_anaconda(), reason='Only works with Anaconda')
@pytest.mark.skipif(
not is_conda_env(sys.prefix), reason='Only works with Anaconda'
)
@pytest.mark.skipif(not running_in_ci(), reason='Only works on CIs')
@pytest.mark.skipif(
not sys.platform.startswith("linux"),
Expand Down Expand Up @@ -5359,7 +5363,7 @@ def test_copy_paste(main_window, qtbot, tmpdir):
" print()\n"
" def c():\n"
" print()\n"
)
)

shell = main_window.ipyconsole.get_current_shellwidget()
qtbot.waitUntil(
Expand Down Expand Up @@ -5405,7 +5409,7 @@ def test_copy_paste(main_window, qtbot, tmpdir):
"\n"
" def c():\n"
" print()\n"
)
)
assert expected in code_editor.toPlainText()


Expand Down Expand Up @@ -5720,7 +5724,7 @@ def test_out_runfile_runcell(main_window, qtbot):
"a = 1 + 3; a;": (4, False),
"a = 1 + 5\na": (6, True),
"a = 1 + 7\na;": (8, False)
}
}
for code in codes:
num, shown = codes[code]
# create new file
Expand Down
7 changes: 5 additions & 2 deletions spyder/config/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
import os.path as osp
from pathlib import Path
import shutil
import sys


# Third party imports
import pytest

# Local imports
import spyder.config.base
from spyder.config.utils import is_anaconda
from spyder.utils.conda import get_list_conda_envs
from spyder_kernels.utils.pythonenv import is_conda_env


# ============================================================================
Expand Down Expand Up @@ -57,7 +58,9 @@ def test_get_conf_path(monkeypatch, use_dev_config_dir):
@pytest.mark.skipif(
not spyder.config.base.running_in_ci(), reason="Only works on CIs"
)
@pytest.mark.skipif(not is_anaconda(), reason='Only works with Anaconda')
@pytest.mark.skipif(
not is_conda_env(sys.prefix), reason='Only works with Anaconda'
)
def test_is_conda_based_app():
"""Test that is_conda_based_app is working as expected."""
# Get conda env to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
# Local imports
from spyder.config.base import running_in_ci
from spyder.config.manager import CONF
from spyder.config.utils import is_anaconda
from spyder.plugins.completion.api import (
CompletionRequestTypes, CompletionItemKind)
from spyder.plugins.completion.providers.languageserver.providers.utils import (
path_as_uri)
path_as_uri
)
from spyder.utils.conda import get_list_conda_envs
from spyder_kernels.utils.pythonenv import is_conda_env


# Location of this file
Expand Down Expand Up @@ -1012,7 +1013,9 @@ def spam():

@pytest.mark.order(1)
@flaky(max_runs=20)
@pytest.mark.skipif(not is_anaconda(), reason='Requires conda to work')
@pytest.mark.skipif(
not is_conda_env(sys.prefix), reason='Requires conda to work'
)
@pytest.mark.skipif(not running_in_ci(), reason="Only meant for CIs")
@pytest.mark.skipif(
not sys.platform.startswith('linux'), reason="Works reliably on Linux"
Expand Down Expand Up @@ -1156,12 +1159,12 @@ def test_file_completions(filename, mock_completions_codeeditor, qtbot):
@pytest.mark.parametrize(
"directory",
[
pytest.param(
'/home',
marks=pytest.mark.skipif(
not sys.platform.startswith('linux'),
reason='Only works on Linux'
)
pytest.param(
'/home',
marks=pytest.mark.skipif(
not sys.platform.startswith('linux'),
reason='Only works on Linux'
)
),
pytest.param(
'C:\\Users',
Expand Down
14 changes: 10 additions & 4 deletions spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
# Local imports
from spyder.config.base import running_in_ci, running_in_ci_with_conda
from spyder.config.gui import get_color_scheme
from spyder.config.utils import is_anaconda
from spyder.py3compat import to_text_string
from spyder.plugins.help.tests.test_plugin import check_text
from spyder.plugins.ipythonconsole.tests.conftest import (
get_conda_test_env, get_console_background_color, get_console_font_color,
NEW_DIR, SHELL_TIMEOUT, PY312_OR_GREATER)
from spyder.plugins.ipythonconsole.widgets import ShellWidget
from spyder.utils.conda import get_list_conda_envs
from spyder_kernels.utils.pythonenv import is_conda_env


@flaky(max_runs=3)
Expand Down Expand Up @@ -291,7 +291,9 @@ def test_cython_client(ipyconsole, qtbot):
@flaky(max_runs=3)
@pytest.mark.order(1)
@pytest.mark.environment_client
@pytest.mark.skipif(not is_anaconda(), reason='Only works with Anaconda')
@pytest.mark.skipif(
not is_conda_env(sys.prefix), reason='Only works with Anaconda'
)
@pytest.mark.skipif(not running_in_ci(), reason='Only works on CIs')
@pytest.mark.skipif(not os.name == 'nt', reason='Works reliably on Windows')
def test_environment_client(ipyconsole, qtbot):
Expand Down Expand Up @@ -1339,7 +1341,9 @@ def test_calltip(ipyconsole, qtbot):
@flaky(max_runs=3)
@pytest.mark.order(1)
@pytest.mark.test_environment_interpreter
@pytest.mark.skipif(not is_anaconda(), reason='Only works with Anaconda')
@pytest.mark.skipif(
not is_conda_env(sys.prefix), reason='Only works with Anaconda'
)
@pytest.mark.skipif(not running_in_ci(), reason='Only works on CIs')
@pytest.mark.skipif(not os.name == 'nt', reason='Works reliably on Windows')
def test_conda_env_activation(ipyconsole, qtbot):
Expand Down Expand Up @@ -2350,7 +2354,9 @@ def test_run_script(ipyconsole, qtbot, tmp_path):
assert sw.get_value(variable_name) == 1


@pytest.mark.skipif(not is_anaconda(), reason="Only works with Anaconda")
@pytest.mark.skipif(
not is_conda_env(sys.prefix), reason="Only works with Anaconda"
)
def test_show_spyder_kernels_error_on_restart(ipyconsole, qtbot):
"""Test that we show Spyder-kernels error message on restarts."""
# Wait until the window is fully up
Expand Down
6 changes: 4 additions & 2 deletions spyder/plugins/maininterpreter/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

# Local imports
from spyder.config.base import running_in_ci
from spyder.config.utils import is_anaconda
from spyder.plugins.maininterpreter.plugin import MainInterpreter
from spyder_kernels.utils.pythonenv import is_conda_env


@pytest.fixture
Expand All @@ -28,7 +28,9 @@ def maininterpreter(qtbot):
return plugin


@pytest.mark.skipif(not is_anaconda(), reason="Requires conda to be installed")
@pytest.mark.skipif(
not is_conda_env(sys.prefix), reason="Requires conda to be installed"
)
@pytest.mark.skipif(not running_in_ci(), reason="Only meant for CIs")
def test_conda_interpreters(maininterpreter, qtbot):
"""Test info from conda interpreters."""
Expand Down
10 changes: 7 additions & 3 deletions spyder/plugins/pylint/tests/test_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# Standard library imports
from io import open
import os.path as osp
import sys
from unittest.mock import Mock, MagicMock

# Third party imports
Expand All @@ -30,11 +31,11 @@
from spyder.api.plugin_registration.registry import PLUGIN_REGISTRY
from spyder.config.base import running_in_ci
from spyder.config.manager import CONF
from spyder.config.utils import is_anaconda
from spyder.plugins.pylint.plugin import Pylint
from spyder.plugins.pylint.utils import get_pylintrc_path
from spyder.utils.conda import get_list_conda_envs
from spyder.utils.misc import get_python_executable
from spyder_kernels.utils.pythonenv import is_conda_env

# pylint: disable=redefined-outer-name

Expand Down Expand Up @@ -65,6 +66,7 @@
good-names=e
"""


class MainWindowMock(QMainWindow):
sig_editor_focus_changed = Signal(str)

Expand Down Expand Up @@ -204,7 +206,7 @@ def test_get_pylintrc_path(pylintrc_files, mocker):
actual_path = get_pylintrc_path(
search_paths=list(search_paths.values()),
home_path=search_paths[HOME_DIR],
)
)
assert actual_path == expected_path


Expand Down Expand Up @@ -293,7 +295,9 @@ def test_pylint_max_history_conf(pylint_plugin, pylint_test_scripts):

@flaky(max_runs=3)
@pytest.mark.parametrize("custom_interpreter", [True, False])
@pytest.mark.skipif(not is_anaconda(), reason='Only works with Anaconda')
@pytest.mark.skipif(
not is_conda_env(sys.prefix), reason='Only works with Anaconda'
)
@pytest.mark.skipif(not running_in_ci(), reason='Only works on CIs')
def test_custom_interpreter(pylint_plugin, tmp_path, qtbot,
custom_interpreter):
Expand Down
4 changes: 2 additions & 2 deletions spyder/utils/tests/test_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

# Local imports
from spyder.config.base import running_in_ci
from spyder.config.utils import is_anaconda
from spyder.plugins.ipythonconsole.tests.conftest import get_conda_test_env
from spyder.utils.conda import (
find_conda,
Expand All @@ -25,8 +24,9 @@
get_list_conda_envs_cache,
get_spyder_conda_channel,
)
from spyder_kernels.utils.pythonenv import is_conda_env

if not is_anaconda():
if not is_conda_env(sys.prefix):
pytest.skip("Requires conda to be installed", allow_module_level=True)

if os.name == 'nt':
Expand Down

0 comments on commit 88a1bc5

Please sign in to comment.