Skip to content

Commit

Permalink
f-d
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Oct 6, 2023
1 parent 5d3cf30 commit 1fabd9f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
6 changes: 0 additions & 6 deletions aiidalab_launch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,6 @@ async def _async_start(
fg="yellow",
)

if instance.image is None:
raise click.ClickException(
f"Unable to find image '{profile.image}'. "
"Try to use '--pull' to pull the image prior to start."
)

# Check if the container configuration has changed.
if instance.container:
configuration_changed = any(instance.configuration_changes())
Expand Down
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ def docker_client():
pytest.skip("docker not available")


@pytest.fixture(scope="function")
def remove_created_images(docker_client):
"""Remove all images created by the tests."""
images = docker_client.images.list()
yield
for image in docker_client.images.list():
if image not in images:
try:
image.remove()
except docker.errors.APIError:
pass


@pytest.fixture(autouse=True)
def _select_default_image(monkeypatch_session, pytestconfig):
_default_image = pytestconfig.getoption("default_image")
Expand Down
17 changes: 17 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def test_get_latest_version_timeout(mock_pypi_request_timeout):


@pytest.mark.usefixtures("enable_docker_pull")
@pytest.mark.usefixtures("remove_created_images")
def test_image_is_latest(docker_client):
"""Test that the latest version is identified correctly."""
# download the alpine image for testing
Expand All @@ -25,3 +26,19 @@ def test_image_is_latest(docker_client):

# check that the image is identified as latest
assert image_is_latest(docker_client, image_name)


@pytest.mark.usefixtures("enable_docker_pull")
@pytest.mark.usefixtures("remove_created_images")
def test_image_is_not_latest(docker_client):
"""Test that the outdate version is identified correctly and will ask for pull the latest."""
# download the alpine image for testing
old_image_name = "alpine:2.6"
latest_image_name = "alpine:latest"

# pull the old image and retag it as latest to mock the outdated image
old_image = docker_client.images.pull(old_image_name)
old_image.tag(latest_image_name)

# check that the image is identified as latest
assert not image_is_latest(docker_client, latest_image_name)

0 comments on commit 1fabd9f

Please sign in to comment.