def flow_with_dump_interval():
    return Flow().add(uses='_index', dump_interval=1)
示例#2
0
def test_flow_load_yaml_extra_search_paths():
    f = Flow.load_config(os.path.join(cur_dir, 'flow/flow.yml'))
    with f:
        da = f.post('/', inputs=Document())
    assert da[0].text == 'done'
示例#3
0
def test_gateway_only_flows_no_error(capsys, protocol):
    f = Flow(protocol=protocol)
    with f:
        pass
    captured = capsys.readouterr()
    assert not captured.err
示例#4
0
def test_flow_set_asyncio_switch_post(is_async):
    f = Flow(asyncio=is_async)
    assert inspect.isasyncgenfunction(f.post) == is_async
示例#5
0
def test_flow_load_executor_yaml_extra_search_paths():
    f = Flow(extra_search_paths=[os.path.join(cur_dir, 'executor')]).add(
        uses='config.yml')
    with f:
        da = f.post('/', inputs=Document())
    assert da[0].text == 'done'
示例#6
0
def test_flow_with_one_container_pod(docker_image_built):
    f = Flow().add(name='dummyEncoder1', uses=f'docker://{img_name}')

    with f:
        f.post(on='/index', inputs=random_docs(10))
示例#7
0
def test_flow_host_expose_shortcut(input, expect_host, expect_port):
    f = Flow().add(host=input).build()
    assert f['pod0'].args.host == expect_host
    if expect_port is not None:
        assert f['pod0'].args.port_expose == expect_port
示例#8
0
def test_single_document_flow_index():
    d = Document()
    with Flow().add() as f:
        f.index(d)
        f.index(lambda: d)
示例#9
0
def test_flow_get_item():
    f1 = Flow().add().add(needs='gateway').needs_all(name='joiner')
    assert isinstance(f1[1], BaseDeployment)
    assert isinstance(f1['executor0'], BaseDeployment)
示例#10
0
def test_flow_with_pod_envs():
    f = Flow.load_config(os.path.join(cur_dir, 'yaml/flow-with-envs.yml'))
    with f:
        _validate_flow(f)
示例#11
0
def test_flow_host_expose_shortcut(input):
    f = Flow().add(host=input).build()
    assert f['executor0'].args.host == input
示例#12
0
def test_refactor_num_part_proxy():
    f = (Flow().add(name='r1').add(name='r2', needs='r1').add(
        name='r3', needs='r1').join(['r2', 'r3']))

    with f:
        _validate_flow(f)
示例#13
0
def test_dry_run_with_two_pathways_diverging_at_non_gateway():
    f = (Flow().add(name='r1').add(name='r2').add(name='r3', needs='r1').join(
        ['r2', 'r3']))

    with f:
        _validate_flow(f)
示例#14
0
def hello_world(args):
    """
    Execute the multimodal example.

    :param args: arguments passed from CLI
    """
    Path(args.workdir).mkdir(parents=True, exist_ok=True)

    with ImportExtensions(
            required=True,
            help_text=
            'this demo requires Pytorch and Transformers to be installed, '
            'if you haven\'t, please do `pip install jina[torch,transformers]`',
    ):
        import torch
        import torchvision
        import transformers

        assert [
            torch,
            transformers,
            torchvision,
        ]  #: prevent pycharm auto remove the above line

    # args.workdir = '0bae16ce-5bb2-43be-bcd4-6f1969e8068f'
    targets = {
        'people-img': {
            'url': args.index_data_url,
            'filename': os.path.join(args.workdir, 'dataset.zip'),
        }
    }

    # download the data
    if not os.path.exists(targets['people-img']['filename']):
        download_data(targets,
                      args.download_proxy,
                      task_name='download zip data')

    with zipfile.ZipFile(targets['people-img']['filename'], 'r') as fp:
        fp.extractall(args.workdir)

    # this envs are referred in index and query flow YAMLs
    os.environ['HW_WORKDIR'] = args.workdir
    os.environ['PY_MODULE'] = os.path.abspath(
        os.path.join(cur_dir, 'my_executors.py'))
    # now comes the real work
    # load index flow from a YAML file

    # index it!
    f = Flow.load_config('flow-index.yml')

    with f, open(f'{args.workdir}/people-img/meta.csv', newline='') as fp:
        f.index(inputs=DocumentArray.from_csv(fp),
                request_size=10,
                show_progress=True)
        f.post(on='/dump', target_executor='textIndexer')
        f.post(on='/dump', target_executor='imageIndexer')
        f.post(on='/dump', target_executor='keyValueIndexer')

    # search it!
    f = Flow.load_config('flow-search.yml')
    # switch to HTTP gateway
    f.protocol = 'http'
    f.port = args.port

    url_html_path = 'file://' + os.path.abspath(
        os.path.join(cur_dir, 'static/index.html'))
    with f:
        try:
            webbrowser.open(url_html_path, new=2)
        except:
            pass  # intentional pass, browser support isn't cross-platform
        finally:
            default_logger.info(
                f'You should see a demo page opened in your browser, '
                f'if not, you may open {url_html_path} manually')
        if not args.unblock_query_flow:
            f.block()
def flow_with_load_interval():
    return Flow().add(uses='_index', load_interval=1)
示例#16
0
def test_flow_add_class():
    f = Flow().add(uses=BaseExecutor).add(uses=CustomizedExecutor)

    with f:
        pass
示例#17
0
def test_pass_arbitrary_kwargs_from_yaml():
    f = Flow.load_config(os.path.join(cur_dir, 'flow.yml'))
    assert f._pod_nodes['executor1'].args.docker_kwargs == {
        'hello': 0,
        'environment': ['VAR1=BAR', 'VAR2=FOO'],
    }
示例#18
0
def test_flow_common_kwargs():

    with Flow(name='hello', something_random=True).add() as f:
        assert f._common_kwargs == {'something_random': True}
示例#19
0
文件: test_flow.py 项目: tchen7/jina
def test_flow_no_container(restful):
    f = (Flow(restful=restful)
         .add(name='dummyEncoder', uses=os.path.join(cur_dir, '../mwu-encoder/mwu_encoder.yml')))

    with f:
        f.index(input_fn=random_docs(10))
示例#20
0
def test_flow_arguments_priorities():
    f = Flow(port_expose=12345).add(name='test', port_expose=23456)
    assert f._pod_nodes['test'].args.port_expose == 23456

    f = Flow(port_expose=12345).add(name='test')
    assert f._pod_nodes['test'].args.port_expose == 12345