Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
Added test_update_no_asset and test_get_asset_info
  • Loading branch information
mrclary committed Oct 1, 2024
1 parent 9e773a7 commit b2da67c
Showing 1 changed file with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions spyder/plugins/updatemanager/tests/test_update_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

import os
import logging
from packaging.version import parse

import pytest

from spyder.config.base import running_in_ci
from spyder.plugins.updatemanager import workers
from spyder.plugins.updatemanager.workers import WorkerUpdate, HTTP_ERROR_MSG
from spyder.plugins.updatemanager.workers import (
get_asset_info, WorkerUpdate, HTTP_ERROR_MSG
)
from spyder.plugins.updatemanager.widgets import update
from spyder.plugins.updatemanager.widgets.update import UpdateManagerWidget

Expand Down Expand Up @@ -49,7 +52,7 @@ def test_updates(qtbot, mocker, caplog, version, channel):
mocker.patch.object(
UpdateManagerWidget, "start_update", new=lambda x: None
)
mocker.patch.object(workers, "__version__", new=version)
mocker.patch.object(workers, "CURR_VER", new=parse(version))
mocker.patch.object(
workers, "get_spyder_conda_channel", return_value=channel
)
Expand Down Expand Up @@ -77,25 +80,59 @@ def test_updates(qtbot, mocker, caplog, version, channel):
assert update_available
else:
assert not update_available
assert len(um.update_worker.releases) >= 1


@pytest.mark.parametrize("release", ["4.0.1", "4.0.1a1"])
@pytest.mark.parametrize("release", ["6.0.0", "6.0.0b3"])
@pytest.mark.parametrize("version", ["4.0.0a1", "4.0.0"])
@pytest.mark.parametrize("stable_only", [True, False])
def test_update_non_stable(qtbot, mocker, version, release, stable_only):
"""Test we offer unstable updates."""
mocker.patch.object(workers, "__version__", new=version)
mocker.patch.object(workers, "CURR_VER", new=parse(version))

release = parse(release)
worker = WorkerUpdate(stable_only)
worker.releases = [release]
worker._check_update_available()
worker._check_update_available([release])

update_available = worker.update_available
if "a" in release and stable_only:
assert not update_available
if release.is_prerelease and stable_only:
assert not worker.update_available
else:
assert update_available
assert worker.update_available


@pytest.mark.parametrize("version", ["4.0.0", "6.0.0"])
def test_update_no_asset(qtbot, mocker, version):
"""Test update availability when asset is not available"""
mocker.patch.object(workers, "CURR_VER", new=parse(version))

releases = [parse("6.0.1"), parse("6.100.0")]
worker = WorkerUpdate(True)
worker._check_update_available(releases)

# For both values of version, there should be an update available
# However, the available version should be 6.0.1, since there is
# no asset for 6.100.0
assert worker.update_available
assert worker.latest_release == releases[0]


@pytest.mark.parametrize(
"release,update_type",
[("6.0.1", "micro"), ("6.1.0", "minor"), ("7.0.0", "major")]
)
@pytest.mark.parametrize("app", [True, False])
def test_get_asset_info(qtbot, mocker, release, update_type, app):
mocker.patch.object(workers, "CURR_VER", new=parse("6.0.0"))
mocker.patch.object(workers, "is_conda_based_app", return_value=app)

info = get_asset_info(release)
assert info['update_type'] == update_type

if update_type == "major" or not app:
assert info['url'].endswith(('.exe', '.pkg', '.sh'))
assert info['name'].endswith(('.exe', '.pkg', '.sh'))
else:
assert info['url'].endswith(".zip")
assert info['name'].endswith(".zip")


# ---- Test WorkerDownloadInstaller
Expand Down

0 comments on commit b2da67c

Please sign in to comment.