Esempio n. 1
0
def test_yatai_service_start():
    runner = CliRunner()

    cli = create_bento_service_cli()
    add_yatai_service_sub_command(cli)

    yatai_service_start_cmd = cli.commands["yatai-service-start"]

    with mock.patch("bentoml.cli.yatai_service.start_yatai_service_grpc_server"
                    ) as mocked_start_yatai_service_grpc_server:
        runner.invoke(yatai_service_start_cmd)
        mocked_start_yatai_service_grpc_server.assert_called()
        mocked_start_yatai_service_grpc_server.assert_called_with(
            db_url=SQLITE_DATABASE_URL,
            grpc_port=50051,
            ui_port=3000,
            with_ui=True,
            base_url=".",
            repository_type="file_system",
            file_system_directory=FILE_SYSTEM_REPOSITORY,
            s3_url=None,
            s3_endpoint_url=None,
            gcs_url=None,
        )

        runner.invoke(yatai_service_start_cmd,
                      ["--repo-base-url=s3://url_address"])
        mocked_start_yatai_service_grpc_server.assert_called()
        mocked_start_yatai_service_grpc_server.assert_called_with(
            db_url=SQLITE_DATABASE_URL,
            grpc_port=50051,
            ui_port=3000,
            with_ui=True,
            base_url=".",
            repository_type="s3",
            file_system_directory=FILE_SYSTEM_REPOSITORY,
            s3_url="s3://url_address",
            s3_endpoint_url=None,
            gcs_url=None,
        )

        runner.invoke(yatai_service_start_cmd,
                      ["--repo-base-url=gs://url_address"])
        mocked_start_yatai_service_grpc_server.assert_called()
        mocked_start_yatai_service_grpc_server.assert_called_with(
            db_url=SQLITE_DATABASE_URL,
            grpc_port=50051,
            ui_port=3000,
            with_ui=True,
            base_url=".",
            repository_type="gcs",
            file_system_directory=FILE_SYSTEM_REPOSITORY,
            s3_url=None,
            s3_endpoint_url=None,
            gcs_url="gs://url_address",
        )
Esempio n. 2
0
def test_serve_command():
    runner = CliRunner()

    cli = create_bento_service_cli()
    gunicorn_cmd = cli.commands["serve"]

    with mock.patch('bentoml.cli.bento_service.start_dev_server',
                    ) as mocked_start_dev_server:
        runner.invoke(
            gunicorn_cmd,
            ["/"],
        )
        assert mocked_start_dev_server.called
Esempio n. 3
0
def test_gunicorn_serve_command():
    runner = CliRunner()

    cli = create_bento_service_cli()
    gunicorn_cmd = cli.commands["serve-gunicorn"]

    with mock.patch("bentoml.cli.bento_service.start_prod_server"
                    ) as mocked_start_prod_server:
        runner.invoke(
            gunicorn_cmd,
            ["/"],
        )
        mocked_start_prod_server.assert_called()
        mocked_start_prod_server.assert_called_with(
            "/",
            port=5000,
            workers=1,
            timeout=60,
            enable_microbatch=False,
            enable_swagger=True,
            mb_max_batch_size=None,
            mb_max_latency=None,
            microbatch_workers=1,
        )

        runner.invoke(
            gunicorn_cmd,
            [
                "/",
                "--port=5050",
                "--workers=10",
                "--timeout=120",
                "--enable-microbatch",
                "--enable-swagger",
                "--mb-max-batch-size=10000",
                "--mb-max-latency=20000",
                "--microbatch-workers=5",
            ],
        )
        mocked_start_prod_server.assert_called()
        mocked_start_prod_server.assert_called_with(
            "/",
            port=5050,
            workers=10,
            timeout=120,
            enable_microbatch=True,
            enable_swagger=True,
            mb_max_batch_size=10000,
            mb_max_latency=20000,
            microbatch_workers=5,
        )
Esempio n. 4
0
def test_gunicorn_serve_command():
    runner = CliRunner()

    cli = create_bento_service_cli()
    gunicorn_cmd = cli.commands["serve-gunicorn"]

    with mock.patch('bentoml.server.gunicorn_server.GunicornBentoServer',
                    ) as mocked_class:
        runner.invoke(
            gunicorn_cmd,
            ["/"],
        )
        instance = mocked_class.return_value
        assert instance.run.called
Esempio n. 5
0
def test_serve_command():
    runner = CliRunner()

    cli = create_bento_service_cli()
    serve_cmd = cli.commands["serve"]

    with mock.patch("bentoml.cli.bento_service.start_dev_server",
                    ) as mocked_start_dev_server:
        runner.invoke(
            serve_cmd,
            ["/"],
        )
        mocked_start_dev_server.assert_called()
        mocked_start_dev_server.assert_called_with(
            '/',
            port=5000,
            enable_microbatch=False,
            mb_max_batch_size=None,
            mb_max_latency=None,
            run_with_ngrok=False,
            enable_swagger=True,
        )

        runner.invoke(
            serve_cmd,
            [
                "/",
                "--port=5050",
                "--enable-microbatch",
                "--enable-swagger",
                "--mb-max-batch-size=10000",
                "--mb-max-latency=20000",
                "--run-with-ngrok",
            ],
        )
        mocked_start_dev_server.assert_called()
        mocked_start_dev_server.assert_called_with(
            '/',
            port=5050,
            enable_microbatch=True,
            mb_max_batch_size=10000,
            mb_max_latency=20000,
            run_with_ngrok=True,
            enable_swagger=True,
        )
Esempio n. 6
0
def create_bentoml_cli():
    # pylint: disable=unused-variable

    _cli = create_bento_service_cli()

    # Commands created here aren't mean to be used from generated BentoService CLI when
    # installed as PyPI package. The are only used as part of BentoML cli command.

    config_sub_command = get_configuration_sub_command()
    aws_sagemaker_sub_command = get_aws_sagemaker_sub_command()
    aws_lambda_sub_command = get_aws_lambda_sub_command()
    deployment_sub_command = get_deployment_sub_command()
    azure_function_sub_command = get_azure_functions_sub_command()
    add_bento_sub_command(_cli)
    add_yatai_service_sub_command(_cli)
    _cli.add_command(config_sub_command)
    _cli.add_command(aws_sagemaker_sub_command)
    _cli.add_command(aws_lambda_sub_command)
    _cli.add_command(azure_function_sub_command)
    _cli.add_command(deployment_sub_command)

    return _cli
Esempio n. 7
0
def test_run_command_with_input_file(bento_bundle_path):
    input_path = generate_test_input_file()
    runner = CliRunner()

    cli = create_bento_service_cli()
    run_cmd = cli.commands["run"]
    result = runner.invoke(
        run_cmd,
        [
            bento_bundle_path,
            "predict_dataframe",
            "--input",
            input_path,
            "-o",
            "json",
            "--quiet",
        ],
    )

    assert result.exit_code == 0
    assert result.output.strip() == '3'

    result = runner.invoke(
        run_cmd,
        [
            bento_bundle_path,
            "predict_dataframe_v1",
            "--input",
            input_path,
            "-o",
            "json",
            "--quiet",
        ],
    )

    assert result.exit_code == 0
    assert result.output.strip() == '3'
Esempio n. 8
0
import os
import sys
import logging

from bentoml import saved_bundle, configure_logging
from bentoml.cli.bento_service import create_bento_service_cli

# By default, ignore warnings when loading BentoService installed as PyPI distribution
# CLI will change back to default log level in config(info), and by adding --quiet or
# --verbose CLI option, user can change the CLI output behavior
configure_logging(logging.ERROR)

__VERSION__ = "20210203191726_06780F"

__module_path = os.path.abspath(os.path.dirname(__file__))

ToxicCommentClassification = saved_bundle.load_bento_service_class(
    __module_path)

cli = create_bento_service_cli(__module_path)


def load():
    return saved_bundle.load_from_dir(__module_path)


__all__ = ['__version__', 'ToxicCommentClassification', 'load']