Skip to content

Commit 5d3cf30

Browse files
committed
monkeypatch and test the warning pop
1 parent e658d11 commit 5d3cf30

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

aiidalab_launch/__main__.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@
2121
from .core import LOGGER
2222
from .instance import AiidaLabInstance
2323
from .profile import DEFAULT_IMAGE, DEFAULT_PORT, Profile
24-
from .util import (
25-
confirm_with_value,
26-
get_latest_version,
27-
image_is_latest,
28-
spinner,
29-
webbrowser_available,
30-
)
24+
from .util import confirm_with_value, get_latest_version, spinner, webbrowser_available
3125
from .version import __version__
3226

3327
MSG_MOUNT_POINT_CONFLICT = """Warning: There is at least one other running
@@ -353,11 +347,13 @@ async def _async_start(
353347
with spinner(msg):
354348
instance.pull()
355349
else:
350+
from aiidalab_launch import util
351+
356352
# use local image
357353
msg = f"Using local image '{profile.image}'."
358354

359355
# check if local image is outdated and pull latest version if so
360-
if not image_is_latest(instance.client, profile.image):
356+
if not util.image_is_latest(instance.client, profile.image):
361357
click.secho(
362358
"Warning! Local image is outdated, please run with --pull to update.",
363359
fg="yellow",

tests/test_cli.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def test_remove_running_profile(self):
208208
@pytest.mark.slow
209209
@pytest.mark.trylast
210210
class TestInstanceLifecycle:
211-
def test_start_stop_reset(self, instance, docker_client, caplog):
211+
def test_start_stop_reset(self, instance, docker_client, caplog, monkeypatch):
212212
caplog.set_level(logging.DEBUG)
213213

214214
def get_volume(volume_name):
@@ -260,6 +260,20 @@ def assert_status_down():
260260
assert result.exit_code == 0
261261
assert_status_up()
262262

263+
# test the warning message of image not the latest is not raised
264+
assert "Warning!" not in result.output.strip()
265+
266+
# Then by monkeypatching the image_is_latest function, we can test that
267+
# the warning message is raised
268+
def image_is_latest(docker_client, image_name):
269+
return False
270+
271+
monkeypatch.setattr("aiidalab_launch.util.image_is_latest", image_is_latest)
272+
result: Result = runner.invoke(
273+
cli.cli, ["start", "--no-browser", "--no-pull", "--wait=300"]
274+
)
275+
assert "Warning!" in result.output.strip()
276+
263277
# Restart instance.
264278
# TODO: This test is currently disabled, because it is too flaky. For
265279
# a currently unknown reason, the docker client will not be able to

0 commit comments

Comments
 (0)