Skip to content

Commit a487ed1

Browse files
nayaknishantdandhlee
authored andcommitted
test: Backoff on predict_test.py (#302)
* docs: removed default model comment and added comment to test * fix: backoff on predict_test.py * fix: backoff on predict_test.py * fix: added backoff to predict_test.py * fix: added backoff to predict_test.py * fix: added backoff to predict_test.py
1 parent 26286db commit a487ed1

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

automl/snippets/translate_create_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def create_model(project_id, dataset_id, display_name):
2727

2828
# A resource that represents Google Cloud Platform location.
2929
project_location = f"projects/{project_id}/locations/us-central1"
30-
# Leave model unset to use the default base model provided by Google
3130
translation_model_metadata = automl.TranslationModelMetadata()
3231
model = automl.Model(
3332
display_name=display_name,

automl/snippets/translate_create_model_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def test_translate_create_model(capsys):
2626
PROJECT_ID, DATASET_ID, "translate_test_create_model"
2727
)
2828
out, _ = capsys.readouterr()
29+
# After setting DATASET_ID, change line below to
30+
# assert "Training started..." in out
2931
assert "Dataset does not exist." in out
3032
except Exception as e:
33+
# After setting DATASET_ID, change line below to
34+
# assert "Training started..." in e.message
3135
assert "Dataset does not exist." in e.message

automl/tables/predict_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,23 @@
1616

1717
import os
1818

19+
import backoff
20+
1921
from google.cloud.automl_v1beta1 import Model
2022

2123
import automl_tables_model
2224
import automl_tables_predict
2325
import model_test
2426

25-
2627
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
2728
REGION = "us-central1"
2829
STATIC_MODEL = model_test.STATIC_MODEL
30+
MAX_TIMEOUT = 200
2931

3032

33+
@backoff.on_exception(
34+
wait_gen=lambda: iter([50, 150, MAX_TIMEOUT]), exception=Exception, max_tries=3
35+
)
3136
def test_predict(capsys):
3237
inputs = {
3338
"Age": 31,

automl/tables/requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pytest==6.2.5
2+
backoff==1.11.1

0 commit comments

Comments
 (0)