OpenHands/tests/unit/test_image_agnostic_util.py
Xingyao Wang 9b1f59a56e
Arch: refactor and add unit tests for EventStreamRuntime docker image build (#2908)
* deprecating recall action

* fix integration tests

* fix integration tests

* refractor runtime to use async

* remove search memory

* rename .initialize to .ainit

* draft of runtime image building (separate from img agnostic)

* refractor runtime build into separate file and add unit tests for it

* fix image agnostic tests

* Update opendevin/runtime/utils/runtime_build.py

Co-authored-by: Mingzhang Zheng <649940882@qq.com>

---------

Co-authored-by: Mingzhang Zheng <649940882@qq.com>
2024-07-15 01:27:31 +00:00

52 lines
1.7 KiB
Python

from unittest.mock import MagicMock, patch
from opendevin.runtime.utils.image_agnostic import (
_get_new_image_name,
generate_dockerfile,
get_od_sandbox_image,
)
def test_generate_dockerfile():
base_image = 'debian:11'
dockerfile_content = generate_dockerfile(base_image)
assert base_image in dockerfile_content
assert (
'RUN apt update && apt install -y openssh-server wget sudo'
in dockerfile_content
)
def test_get_new_image_name_legacy():
# test non-eventstream runtime (sandbox-based)
base_image = 'debian:11'
new_image_name = _get_new_image_name(base_image)
assert new_image_name == 'od_sandbox:debian__11'
base_image = 'ubuntu:22.04'
new_image_name = _get_new_image_name(base_image)
assert new_image_name == 'od_sandbox:ubuntu__22.04'
base_image = 'ubuntu'
new_image_name = _get_new_image_name(base_image)
assert new_image_name == 'od_sandbox:ubuntu__latest'
@patch('opendevin.runtime.utils.image_agnostic._build_sandbox_image')
@patch('opendevin.runtime.utils.image_agnostic.docker.DockerClient')
def test_get_od_sandbox_image(mock_docker_client, mock_build_sandbox_image):
base_image = 'debian:11'
mock_docker_client.images.list.return_value = [
MagicMock(tags=['od_sandbox:debian__11'])
]
image_name = get_od_sandbox_image(base_image, mock_docker_client)
assert image_name == 'od_sandbox:debian__11'
mock_docker_client.images.list.return_value = []
image_name = get_od_sandbox_image(base_image, mock_docker_client)
assert image_name == 'od_sandbox:debian__11'
mock_build_sandbox_image.assert_called_once_with(
base_image, 'od_sandbox:debian__11', mock_docker_client
)