예제 #1
0
def test_download_proxy():
    import urllib.request
    # first test no proxy
    args = set_hw_parser().parse_args([])

    opener = urllib.request.build_opener()
    if args.download_proxy:
        proxy = urllib.request.ProxyHandler({
            'http': args.download_proxy,
            'https': args.download_proxy
        })
        opener.add_handler(proxy)
    urllib.request.install_opener(opener)
    # head check
    req = urllib.request.Request(args.index_data_url, method="HEAD")
    response = urllib.request.urlopen(req, timeout=5)
    assert response.status == 200

    # test with proxy
    args = set_hw_parser().parse_args(
        ["--download-proxy", os.getenv("HTTP_PROXY")])

    opener = urllib.request.build_opener()
    if args.download_proxy:
        proxy = urllib.request.ProxyHandler({
            'http': args.download_proxy,
            'https': args.download_proxy
        })
        opener.add_handler(proxy)
    urllib.request.install_opener(opener)
    # head check
    req = urllib.request.Request(args.index_data_url, method="HEAD")
    response = urllib.request.urlopen(req, timeout=5)
    assert response.status == 200
예제 #2
0
def test_helloworld_flow(tmpdir):
    args = set_hw_parser().parse_args([])

    os.environ['RESOURCE_DIR'] = resource_filename('jina', 'resources')
    os.environ['SHARDS'] = str(args.shards)
    os.environ['PARALLEL'] = str(args.parallel)
    os.environ['HW_WORKDIR'] = str(tmpdir)
    os.environ['WITH_LOGSERVER'] = str(args.logserver)

    f = Flow.load_config(
        resource_filename('jina', '/'.join(
            ('resources', 'helloworld.flow.index.yml'))))

    targets = {
        'index': {
            'url': args.index_data_url,
            'filename': os.path.join(tmpdir, 'index-original')
        },
        'query': {
            'url': args.query_data_url,
            'filename': os.path.join(tmpdir, 'query-original')
        }
    }

    # download the data
    Path(tmpdir).mkdir(parents=True, exist_ok=True)
    download_data(targets)

    # run it!
    with f:
        py_client(
            host=f.host,
            port_expose=f.port_expose,
        ).index(input_numpy(targets['index']['data']),
                batch_size=args.index_batch_size)
예제 #3
0
    def test_helloworld_flow_dry_run(self):
        args = set_hw_parser().parse_args([])

        os.environ['RESOURCE_DIR'] = resource_filename('jina', 'resources')
        os.environ['SHARDS'] = str(args.shards)
        os.environ['PARALLEL'] = str(args.parallel)
        os.environ['HW_WORKDIR'] = args.workdir
        os.environ['WITH_LOGSERVER'] = str(args.logserver)

        # run it!
        with Flow.load_config(resource_filename('jina', '/'.join(('resources', 'helloworld.flow.index.yml')))):
            pass

        # run it!
        with Flow.load_config(resource_filename('jina', '/'.join(('resources', 'helloworld.flow.query.yml')))):
            pass
예제 #4
0
def test_helloworld_py(tmpdir):
    from jina.parser import set_hw_parser
    from jina.helloworld import hello_world
    hello_world(set_hw_parser().parse_args(['--workdir', str(tmpdir)]))
예제 #5
0
 def test_helloworld_py(self):
     from jina.parser import set_hw_parser
     from jina.helloworld import hello_world
     hello_world(set_hw_parser().parse_args([]))