Skip to content

Commit 920704d

Browse files
committed
Bryans suggestions
1 parent 4ec3b9d commit 920704d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

synapseclient/core/version_check.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
1212
"""
1313

14-
import importlib
1514
import json
1615
import logging
1716
import re
1817
import sys
18+
from importlib.resources import files
1919
from typing import Any, Optional
2020

2121
import httpx
@@ -37,7 +37,8 @@ def version_check(
3737
Recommends upgrade, if a newer version exists.
3838
3939
This wraps the _version_check function in a try except block.
40-
The purpose of this is so that no exception caught running the version check stops the client from running.
40+
The purpose of this is so that no exception caught running the version
41+
check stops the client from running.
4142
4243
Arguments:
4344
current_version: The current version of the package.
@@ -178,7 +179,7 @@ def _get_local_package_metadata() -> dict[str, Any]:
178179
Returns:
179180
dict[str, Any]: This will have various fields relating the version of the client
180181
"""
181-
ref = importlib.resources.files("synapseclient").joinpath("synapsePythonClient")
182+
ref = files("synapseclient").joinpath("synapsePythonClient")
182183
with ref.open("r") as fp:
183184
pkg_metadata = json.loads(fp.read())
184185
return pkg_metadata

tests/integration/synapseclient/core/test_version_check.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
"""Integration tests for version checking"""
22

3+
from pytest_mock import MockerFixture
4+
5+
import synapseclient.core.version_check
36
from synapseclient.core.version_check import _get_version_info_from_pypi, version_check
47

58

6-
async def test_version_check():
9+
async def test_version_check(mocker: MockerFixture):
710
"""Integration checks for version_check"""
8-
# Check current version against pypi version file
9-
version_check()
10-
1111
# Should be higher than current version and return true
1212
assert version_check(current_version="999.999.999")
1313

1414
# Test out of date version
1515
assert not version_check(current_version="0.0.1")
1616

17+
# Assert _get_version_info_from_pypi called when running version_check
18+
spy = mocker.spy(synapseclient.core.version_check, "_get_version_info_from_pypi")
19+
version_check()
20+
spy.assert_called_once()
21+
1722

1823
def test_get_version_info_from_pypi():
1924
"""Integration test for _get_version_info_from_pypi"""

0 commit comments

Comments
 (0)