|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -import datetime |
16 | 15 | import os |
17 | 16 |
|
18 | | -from google.cloud import automl |
19 | | -import pytest |
20 | | - |
21 | 17 | import import_dataset |
22 | 18 |
|
23 | 19 | PROJECT_ID = os.environ["AUTOML_PROJECT_ID"] |
24 | 20 | BUCKET_ID = "{}-lcm".format(PROJECT_ID) |
25 | | - |
26 | | - |
27 | | -@pytest.fixture(scope="function") |
28 | | -def create_dataset(): |
29 | | - client = automl.AutoMlClient() |
30 | | - project_location = client.location_path(PROJECT_ID, "us-central1") |
31 | | - display_name = "test_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S") |
32 | | - metadata = automl.types.TextSentimentDatasetMetadata( |
33 | | - sentiment_max=4 |
34 | | - ) |
35 | | - dataset = automl.types.Dataset( |
36 | | - display_name=display_name, text_sentiment_dataset_metadata=metadata |
37 | | - ) |
38 | | - response = client.create_dataset(project_location, dataset) |
39 | | - dataset_id = response.result().name.split("/")[-1] |
40 | | - |
41 | | - yield dataset_id |
42 | | - |
43 | | - |
44 | | -@pytest.mark.slow |
45 | | -def test_import_dataset(capsys, create_dataset): |
46 | | - data = ( |
47 | | - "gs://{}/sentiment-analysis/dataset.csv".format(BUCKET_ID) |
48 | | - ) |
49 | | - dataset_id = create_dataset |
50 | | - import_dataset.import_dataset(PROJECT_ID, dataset_id, data) |
51 | | - out, _ = capsys.readouterr() |
52 | | - assert "Data imported." in out |
53 | | - |
54 | | - # delete created dataset |
55 | | - client = automl.AutoMlClient() |
56 | | - dataset_full_id = client.dataset_path( |
57 | | - PROJECT_ID, "us-central1", dataset_id |
58 | | - ) |
59 | | - response = client.delete_dataset(dataset_full_id) |
60 | | - response.result() |
| 21 | +DATASET_ID = "TEN0000000000000000000" |
| 22 | + |
| 23 | + |
| 24 | +def test_import_dataset(capsys): |
| 25 | + # As importing a dataset can take a long time and only four operations can |
| 26 | + # be run on a dataset at once. Try to import into a nonexistent dataset and |
| 27 | + # confirm that the dataset was not found, but other elements of the request |
| 28 | + # were valid. |
| 29 | + try: |
| 30 | + data = "gs://{}/sentiment-analysis/dataset.csv".format(BUCKET_ID) |
| 31 | + import_dataset.import_dataset(PROJECT_ID, DATASET_ID, data) |
| 32 | + out, _ = capsys.readouterr() |
| 33 | + assert ( |
| 34 | + "The Dataset doesn't exist or is inaccessible for use with AutoMl." |
| 35 | + in out |
| 36 | + ) |
| 37 | + except Exception as e: |
| 38 | + assert ( |
| 39 | + "The Dataset doesn't exist or is inaccessible for use with AutoMl." |
| 40 | + in e.message |
| 41 | + ) |
0 commit comments