Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclary committed May 5, 2023
1 parent 6b7dbab commit 95ff870
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
37 changes: 17 additions & 20 deletions spyder/workers/tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,46 @@
from spyder.workers.updates import WorkerUpdates


def test_update(qtbot):
@pytest.fixture
def worker():
return WorkerUpdates(None)


def test_update(qtbot, worker):
"""Test we offer updates for lower versions."""
worker = WorkerUpdates(None, False, version="1.0.0")
worker.version = "1.0.0"
worker.start()
assert worker.update_available


def test_no_update(qtbot):
def test_no_update(qtbot, worker):
"""Test we don't offer updates for very high versions."""
worker = WorkerUpdates(None, False, version="1000.0.0")
worker.start()
assert not worker.update_available


def test_no_update_development(qtbot):
"""Test we don't offer updates for development versions."""
worker = WorkerUpdates(None, False, version="3.3.2.dev0",
releases=['3.3.1'])
worker.version = "1000.0.0"
worker.start()
assert not worker.update_available


def test_update_pre_to_pre(qtbot):
def test_update_pre_to_pre(qtbot, worker):
"""Test we offer updates between prereleases."""
worker = WorkerUpdates(None, False, version="4.0.0a1",
releases=['4.0.0b5'])
worker.version = "4.0.0a1"
worker.releases = ['4.0.0b5']
worker.start()
assert worker.update_available


def test_update_pre_to_final(qtbot):
def test_update_pre_to_final(qtbot, worker):
"""Test we offer updates from prereleases to the final versions."""
worker = WorkerUpdates(None, False, version="4.0.0b3",
releases=['4.0.0'])
worker.version = "4.0.0b3"
worker.releases = ['4.0.0']
worker.start()
assert worker.update_available


@pytest.mark.skipif(not is_anaconda(),
reason='It only makes sense for Anaconda.')
def test_releases_anaconda(qtbot):
def test_releases_anaconda(qtbot, worker):
"""Test we don't include spyder-kernels releases in detected releases."""
worker = WorkerUpdates(None, False, version="3.3.1")
worker.version = "3.3.1"
worker.start()
assert '0.2.4' not in worker.releases

Expand Down
19 changes: 10 additions & 9 deletions spyder/workers/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

# Local imports
from spyder import __version__
from spyder.config.base import _, is_stable_version, is_conda_based_app
from spyder.config.base import (_, is_stable_version, is_conda_based_app,
running_under_pytest)
from spyder.py3compat import is_text_string
from spyder.utils.programs import check_version

Expand Down Expand Up @@ -52,16 +53,12 @@ class WorkerUpdates(QObject):
"""
sig_ready = Signal()

def __init__(self, parent, version=""):
def __init__(self, parent):
QObject.__init__(self)
self._parent = parent
self.error = None
self.releases = []

if not version:
self.version = __version__
else:
self.version = version
self.version = __version__

self.update_available = None
self.latest_release = None
Expand Down Expand Up @@ -111,6 +108,10 @@ def get_releases(self):
data = data.decode()
data = json.loads(data)

if running_under_pytest() and self.releases:
# If releases set in pytest, don't overwrite
return

if self.update_from_github:
self.releases = [item['tag_name'].replace('v', '')
for item in data]
Expand All @@ -129,7 +130,7 @@ def start(self):
logger.debug("Starting WorkerUpdates.")

self.update_available = False
self.latest_release = __version__
self.latest_release = self.version
self.error = None

try:
Expand Down Expand Up @@ -228,7 +229,7 @@ def _download_installer(self):
dir_path, self.latest_release_version)
os.makedirs(installer_dir_path, exist_ok=True)
for file in os.listdir(dir_path):
if file not in [__version__, self.latest_release_version]:
if file not in [self.version, self.latest_release_version]:
remove = osp.join(dir_path, file)
os.remove(remove)

Expand Down

0 comments on commit 95ff870

Please sign in to comment.