Skip to content

Commit

Permalink
samples: Automl table batch test [(#4267)](GoogleCloudPlatform/python…
Browse files Browse the repository at this point in the history
…-docs-samples#4267)

* added rtest req.txt

* samples: added automl batch predict test

* added missing package

* Update tables/automl/batch_predict_test.py

Co-authored-by: Bu Sun Kim <[email protected]>

Co-authored-by: Bu Sun Kim <[email protected]>
  • Loading branch information
munkhuushmgl and busunkim96 authored Jul 9, 2020
1 parent bb71346 commit 26a0653
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions samples/tables/batch_predict_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from google.cloud.automl_v1beta1.gapic import enums

import pytest

import automl_tables_model
import automl_tables_predict
import model_test


PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
REGION = "us-central1"
STATIC_MODEL = model_test.STATIC_MODEL
GCS_INPUT = "gs://{}-automl-tables-test/bank-marketing.csv".format(PROJECT)
GCS_OUTPUT = "gs://{}-automl-tables-test/TABLE_TEST_OUTPUT/".format(PROJECT)


@pytest.mark.slow
def test_batch_predict(capsys):
ensure_model_online()
automl_tables_predict.batch_predict(
PROJECT, REGION, STATIC_MODEL, GCS_INPUT, GCS_OUTPUT
)
out, _ = capsys.readouterr()
assert "Batch prediction complete" in out


def ensure_model_online():
model = model_test.ensure_model_ready()
if model.deployment_state != enums.Model.DeploymentState.DEPLOYED:
automl_tables_model.deploy_model(PROJECT, REGION, model.display_name)

return automl_tables_model.get_model(PROJECT, REGION, model.display_name)

0 comments on commit 26a0653

Please sign in to comment.