Пример #1
0
def test_hub_build_push_push_again():
    args = set_hub_build_parser().parse_args(
        [os.path.join(cur_dir, 'hub-mwu'), '--push', '--host-info'])
    summary = HubIO(args).build()

    with open(os.path.join(cur_dir, 'hub-mwu', 'manifest.yml')) as fp:
        manifest = yaml.load(fp)

    assert summary['is_build_success']
    assert manifest['version'] == summary['version']
    assert manifest['description'] == summary['manifest_info']['description']
    assert manifest['author'] == summary['manifest_info']['author']
    assert manifest['kind'] == summary['manifest_info']['kind']
    assert manifest['type'] == summary['manifest_info']['type']
    assert manifest['vendor'] == summary['manifest_info']['vendor']
    assert manifest['keywords'] == summary['manifest_info']['keywords']

    args = set_hub_list_parser().parse_args([
        '--name', summary['manifest_info']['name'], '--keywords',
        summary['manifest_info']['keywords'][0], '--type',
        summary['manifest_info']['type']
    ])
    response = HubIO(args).list()
    manifests = response

    assert len(manifests) >= 1
    assert manifests[0]['name'] == summary['manifest_info']['name']

    # try and push same version again should fail
    args = set_hub_build_parser().parse_args(
        [os.path.join(cur_dir, 'hub-mwu'), '--push', '--host-info'])
    summary = HubIO(args).build()
    print(summary['is_build_success'])
Пример #2
0
def test_hub_build_push_push_again():
    args = set_hub_build_parser().parse_args([str(cur_dir / 'hub-mwu'), '--push', '--host-info'])
    summary = HubIO(args).build()

    with open(cur_dir / 'hub-mwu' / 'manifest.yml') as fp:
        manifest = JAML.load(fp)

    assert summary['is_build_success']
    assert manifest['version'] == summary['version']
    assert manifest['description'] == summary['manifest_info']['description']
    assert manifest['author'] == summary['manifest_info']['author']
    assert manifest['kind'] == summary['manifest_info']['kind']
    assert manifest['type'] == summary['manifest_info']['type']
    assert manifest['vendor'] == summary['manifest_info']['vendor']
    assert manifest['keywords'] == summary['manifest_info']['keywords']

    args = set_hub_list_parser().parse_args([
        '--name', summary['manifest_info']['name'],
        '--keywords', summary['manifest_info']['keywords'][0],
        '--type', summary['manifest_info']['type']
    ])
    response = HubIO(args).list()
    manifests = response

    assert len(manifests) >= 1
    assert manifests[0]['name'] == summary['manifest_info']['name']

    with pytest.raises(ImageAlreadyExists):
        # try and push same version again should fail with `--no-overwrite`
        args = set_hub_build_parser().parse_args([str(cur_dir / 'hub-mwu'), '--push', '--host-info', '--no-overwrite'])
        HubIO(args).build()
Пример #3
0
def test_hub_build_no_pymodules():
    args = set_hub_build_parser().parse_args(
        [os.path.join(cur_dir, 'hub-mwu-bad', 'fail-to-start')])
    assert HubIO(args).build()['is_build_success']

    args = set_hub_build_parser().parse_args(
        [os.path.join(cur_dir, 'hub-mwu-bad', 'fail-to-start'), '--test-uses'])
    assert not HubIO(args).build()['is_build_success']
Пример #4
0
def test_hub_build_uses():
    args = set_hub_build_parser().parse_args(
        [str(cur_dir / 'hub-mwu'), '--test-uses', '--raise-error'])
    HubIO(args).build()
    # build again it shall not fail
    HubIO(args).build()

    args = set_hub_build_parser().parse_args(
        [str(cur_dir / 'hub-mwu'), '--test-uses', '--daemon', '--raise-error'])
    HubIO(args).build()
    # build again it shall not fail
    HubIO(args).build()
Пример #5
0
def test_hub_build_push(monkeypatch, mocker):
    monkeypatch.setattr(Path, 'is_file', True)
    mock_access_token = mocker.patch.object(hubapi,
                                            '_fetch_access_token',
                                            autospec=True)
    mock_access_token.return_value = os.environ.get('GITHUB_TOKEN', None)
    args = set_hub_build_parser().parse_args(
        [str(cur_dir + '/hub-mwu'), '--push', '--host-info'])
    summary = HubIO(args).build()

    with open(cur_dir + '/hub-mwu' + '/manifest.yml') as fp:
        manifest_jaml = JAML.load(fp, substitute=True)
        manifest = expand_dict(manifest_jaml)

    assert summary['is_build_success']
    assert manifest['version'] == summary['version']
    assert manifest['description'] == summary['manifest_info']['description']
    assert manifest['author'] == summary['manifest_info']['author']
    assert manifest['kind'] == summary['manifest_info']['kind']
    assert manifest['type'] == summary['manifest_info']['type']
    assert manifest['vendor'] == summary['manifest_info']['vendor']
    assert manifest['keywords'] == summary['manifest_info']['keywords']

    args = set_hub_list_parser().parse_args([
        '--name', summary['manifest_info']['name'], '--keywords',
        summary['manifest_info']['keywords'][0], '--type',
        summary['manifest_info']['type']
    ])
    response = HubIO(args).list()
    manifests = response

    assert len(manifests) >= 1
    assert manifests[0]['name'] == summary['manifest_info']['name']
Пример #6
0
def test_use_from_local_dir_flow_container_level():
    args = set_hub_build_parser().parse_args(
        [os.path.join(cur_dir, 'dummyhub'), '--test-uses', '--raise-error'])
    HubIO(args).build()
    with Flow().add(
            uses=f'jinahub/pod.crafter.dummyhubexecutor:0.0.0-{jina_version}'):
        pass
Пример #7
0
def test_hub_build_push():
    args = set_hub_build_parser().parse_args([str(cur_dir / 'hub-mwu'), '--push', '--host-info'])
    summary = HubIO(args).build()

    with open(cur_dir / 'hub-mwu' / 'manifest.yml') as fp:
        manifest = JAML.load(fp)

    assert summary['is_build_success']
    assert manifest['version'] == summary['version']
    assert manifest['description'] == summary['manifest_info']['description']
    assert manifest['author'] == summary['manifest_info']['author']
    assert manifest['kind'] == summary['manifest_info']['kind']
    assert manifest['type'] == summary['manifest_info']['type']
    assert manifest['vendor'] == summary['manifest_info']['vendor']
    assert manifest['keywords'] == summary['manifest_info']['keywords']

    args = set_hub_list_parser().parse_args([
        '--name', summary['manifest_info']['name'],
        '--keywords', summary['manifest_info']['keywords'][0],
        '--type', summary['manifest_info']['type']
    ])
    response = HubIO(args).list()
    manifests = response

    assert len(manifests) >= 1
    assert manifests[0]['name'] == summary['manifest_info']['name']
Пример #8
0
def test_use_executor_pretrained_model_except():
    args = set_hub_build_parser().parse_args([
        os.path.join(cur_dir, 'dummyhub_pretrained'), '--test-uses',
        '--raise-error'
    ])

    with pytest.raises(HubBuilderError):
        HubIO(args).build()
Пример #9
0
def test_hub_build_failures():
    for j in [
            'bad-dockerfile', 'bad-pythonfile', 'missing-dockerfile',
            'missing-manifest'
    ]:
        args = set_hub_build_parser().parse_args(
            [os.path.join(cur_dir, 'hub-mwu-bad', j)])
        assert not HubIO(args).build()['is_build_success']
Пример #10
0
def test_build_timeout_ready():
    args = set_hub_build_parser().parse_args([
        os.path.join(cur_dir, 'dummyhub_slow'), '--timeout-ready', '20000',
        '--test-uses', '--raise-error'
    ])
    HubIO(args).build()
    with Flow(
    ).add(uses=f'jinahub/pod.crafter.dummyhubexecutorslow:0.0.0-{jina_version}',
          timeout_ready=20000):
        pass
Пример #11
0
def test_hub_build_pull():
    args = set_hub_build_parser().parse_args(
        [str(cur_dir / 'hub-mwu'), '--push', '--test-uses', '--raise-error'])
    HubIO(args).build()

    args = set_hub_pushpull_parser().parse_args(['jinahub/pod.dummy_mwu_encoder'])
    HubIO(args).pull()

    args = set_hub_pushpull_parser().parse_args(['jinahub/pod.dummy_mwu_encoder:0.0.6'])
    HubIO(args).pull()
Пример #12
0
def test_hub_build_level_pass(monkeypatch, mock_load_config):
    monkeypatch.setattr(BaseExecutor, "load_config", mock_load_config)
    args = set_hub_build_parser().parse_args(
        ['path/hub-mwu', '--push', '--host-info', '--test-level', 'EXECUTOR'])

    p_names, failed_levels = HubIO._test_build("jinahub/pod.dummy_mwu_encoder",
                                               BuildTestLevel.EXECUTOR,
                                               "sample/yaml.yaml", True)
    expected_failed_levels = []
    assert expected_failed_levels == failed_levels
Пример #13
0
def test_hub_build_level_fail(monkeypatch, mock_load_config):
    monkeypatch.setattr(BaseExecutor, "load_config", mock_load_config)
    args = set_hub_build_parser().parse_args(
        ['path/hub-mwu', '--push', '--host-info', '--test-level', 'FLOW'])

    expected_failed_levels = [
        BuildTestLevel.POD_NONDOCKER, BuildTestLevel.POD_DOCKER,
        BuildTestLevel.FLOW
    ]
    p_names, failed_levels = HubIO(args)._test_build(
        "jinahub/pod.dummy_mwu_encoder", BuildTestLevel.FLOW,
        'sampleconfig/yaml', True)
    assert expected_failed_levels == failed_levels
Пример #14
0
def test_hub_build_push_push_again(monkeypatch, access_token_github):
    monkeypatch.setattr(Path, 'is_file', True)
    monkeypatch.setattr(hubapi, '_fetch_access_token', access_token_github)
    args = set_hub_build_parser().parse_args(
        [str(cur_dir) + '/hub-mwu', '--push', '--host-info'])
    summary = HubIO(args).build()

    with open(str(cur_dir) + '/hub-mwu' + '/manifest.yml') as fp:
        manifest_jaml = JAML.load(fp, substitute=True)
        manifest = expand_dict(manifest_jaml)

    assert summary['is_build_success']
    assert manifest['version'] == summary['version']
    assert manifest['description'] == summary['manifest_info']['description']
    assert manifest['author'] == summary['manifest_info']['author']
    assert manifest['kind'] == summary['manifest_info']['kind']
    assert manifest['type'] == summary['manifest_info']['type']
    assert manifest['vendor'] == summary['manifest_info']['vendor']
    assert manifest['keywords'] == summary['manifest_info']['keywords']

    args = set_hub_list_parser().parse_args([
        '--name', summary['manifest_info']['name'], '--keywords',
        summary['manifest_info']['keywords'][0], '--type',
        summary['manifest_info']['type']
    ])
    response = HubIO(args).list()
    manifests = response

    assert len(manifests) >= 1
    assert manifests[0]['name'] == summary['manifest_info']['name']

    with pytest.raises(ImageAlreadyExists):
        # try and push same version again should fail with `--no-overwrite`
        args = set_hub_build_parser().parse_args([
            str(cur_dir) + '/hub-mwu', '--push', '--host-info',
            '--no-overwrite'
        ])
        HubIO(args).build()
Пример #15
0
def test_use_executor_pretrained_model_except():
    args = set_hub_build_parser().parse_args([
        os.path.join(cur_dir, 'dummyhub_pretrained'), '--test-uses',
        '--raise-error'
    ])
    assert HubIO(args).build()['is_build_success']