-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
test_hub_build_level.py
71 lines (56 loc) · 2.07 KB
/
test_hub_build_level.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import docker
import pytest
from jina.docker.hubio import HubIO
from jina.enums import BuildTestLevel
from jina.logging import JinaLogger
from jina.parsers.hub import set_hub_build_parser
cur_dir = os.path.dirname(os.path.abspath(__file__))
@pytest.fixture(scope='function')
def test_workspace(tmpdir):
os.environ['JINA_TEST_JOINT'] = str(tmpdir)
workspace_path = os.environ['JINA_TEST_JOINT']
yield workspace_path
del os.environ['JINA_TEST_JOINT']
@pytest.fixture(scope='function')
def docker_image():
def _filter_repo_tag(image, image_name='jinahub/pod.dummy_mwu_encoder'):
tags = image.attrs['RepoTags'] if 'RepoTags' in image.attrs else None
if tags:
return tags[0].startswith(image_name)
else:
return False
img_name = 'jinahub/pod.dummy_mwu_encoder:0.0.6'
client = docker.from_env()
client.images.pull(img_name)
images = client.images.list()
image_name = list(filter(lambda image: _filter_repo_tag(image), images))[0]
return image_name
def test_hub_build_level_pass(monkeypatch, test_workspace, docker_image):
args = set_hub_build_parser().parse_args(
['path/hub-mwu', '--push', '--host-info', '--test-level', 'EXECUTOR']
)
expected_failed_levels = []
_, failed_levels = HubIO(args)._test_build(
docker_image,
BuildTestLevel.EXECUTOR,
os.path.join(cur_dir, 'yaml/test-joint.yml'),
60000,
True,
JinaLogger('unittest'),
)
assert expected_failed_levels == failed_levels
def test_hub_build_level_fail(monkeypatch, test_workspace, docker_image):
args = set_hub_build_parser().parse_args(
['path/hub-mwu', '--push', '--host-info', '--test-level', 'FLOW']
)
expected_failed_levels = [BuildTestLevel.POD_DOCKER, BuildTestLevel.FLOW]
_, failed_levels = HubIO(args)._test_build(
docker_image,
BuildTestLevel.FLOW,
os.path.join(cur_dir, 'yaml/test-joint.yml'),
60000,
True,
JinaLogger('unittest'),
)
assert expected_failed_levels == failed_levels