Skip to content

Commit

Permalink
replace exception by critical log
Browse files Browse the repository at this point in the history
  • Loading branch information
awoimbee committed Nov 20, 2024
1 parent d67aef0 commit 1e9ad3e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/ansys/simai/core/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ def warn_package_outdated(package: str, current_version: str, latest_version: st
version_current.major < version_latest.major
or version_current.minor < version_latest.minor
):
raise SimAIError(warn_template % "required")
logger.critical(warn_template % "required")
else:
logger.warning(warn_template % "available")
50 changes: 19 additions & 31 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,34 @@ def test_client_creation_invalid_config():
SimAIClient.from_config(path=Path(__file__).resolve())


@pytest.mark.parametrize(
"local_ver,latest_ver,expected",
[
("1.1.0", "1.1.1", "available."),
("1.0.9-rc8", "1.0.9", "available."),
("1.0.9", "1.9.0", "required."),
]
)
@responses.activate
def test_client_version_auto_warn(caplog, mocker):
def test_client_version_auto_warn(
caplog,
mocker,
local_ver,
latest_ver,
expected
):
"""WHEN the SDK version is slightly outdated compared to what the API responds
THEN a warning is printed
"""
mocker.patch(
"ansys.simai.core.client.__version__",
"1.1.0",
local_ver,
)
responses.add(
responses.GET,
"https://pypi.org/pypi/ansys-simai-core/json",
json={"info": {"version": "1.1.1"}},
json={"info": {"version": latest_ver}},
status=200,
)
SimAIClient(
Expand All @@ -61,31 +76,4 @@ def test_client_version_auto_warn(caplog, mocker):
no_sse_connection=True,
skip_version_check=False,
)
assert "A new version of ansys-simai-core is available" in caplog.text


@responses.activate
def test_client_version_auto_error(caplog, mocker):
"""WHEN the SDK version is grossly outdated compared to what the API responds
THEN an exception is raised
"""
mocker.patch(
"ansys.simai.core.client.__version__",
"1.0.9-rc8",
)

responses.add(
responses.GET,
"https://pypi.org/pypi/ansys-simai-core/json",
json={"info": {"version": "1.9.0"}},
status=200,
)
with pytest.raises(err.SimAIError) as exc:
SimAIClient(
url="https://test.test",
organization="dummy",
_disable_authentication=True,
no_sse_connection=True,
skip_version_check=False,
)
assert "A new version of ansys-simai-core is required" in str(exc.value)
assert f"A new version of ansys-simai-core is {expected}" in caplog.text

0 comments on commit 1e9ad3e

Please sign in to comment.