forked from OpenHands/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_image_agnostic_util.py
More file actions
51 lines (40 loc) · 1.69 KB
/
test_image_agnostic_util.py
File metadata and controls
51 lines (40 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
)