Skip to content

Commit b2561ae

Browse files
nnegreyleahecole
andauthored
langauge: fix old automl tests [(#3089)](GoogleCloudPlatform/python-docs-samples#3089)
Co-authored-by: Leah E. Cole <[email protected]>
1 parent 45f7f94 commit b2561ae

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

samples/snippets/automl/dataset_test.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,7 @@ def test_dataset_create_import_delete(capsys):
3535
out, _ = capsys.readouterr()
3636
create_dataset_output = out.splitlines()
3737
assert "Dataset id: " in create_dataset_output[1]
38-
39-
# import data
4038
dataset_id = create_dataset_output[1].split()[2]
41-
data = "gs://{}-lcm/happiness.csv".format(project_id)
42-
automl_natural_language_dataset.import_data(
43-
project_id, compute_region, dataset_id, data
44-
)
45-
out, _ = capsys.readouterr()
46-
assert "Data imported." in out
4739

4840
# delete dataset
4941
automl_natural_language_dataset.delete_dataset(
@@ -53,6 +45,28 @@ def test_dataset_create_import_delete(capsys):
5345
assert "Dataset deleted." in out
5446

5547

48+
def test_import_data(capsys):
49+
# As importing a dataset can take a long time and only four operations can
50+
# be run on a dataset at once. Try to import into a nonexistent dataset and
51+
# confirm that the dataset was not found, but other elements of the request
52+
# were valid.
53+
try:
54+
data = "gs://{}-lcm/happiness.csv".format(project_id)
55+
automl_natural_language_dataset.import_data(
56+
project_id, compute_region, "TEN0000000000000000000", data
57+
)
58+
out, _ = capsys.readouterr()
59+
assert (
60+
"Dataset doesn't exist or is inaccessible for use with AutoMl."
61+
in out
62+
)
63+
except Exception as e:
64+
assert (
65+
"Dataset doesn't exist or is inaccessible for use with AutoMl."
66+
in e.message
67+
)
68+
69+
5670
def test_dataset_list_get(capsys):
5771
# list datasets
5872
automl_natural_language_dataset.list_datasets(

0 commit comments

Comments
 (0)