This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
/
dataset_test.py
69 lines (57 loc) · 2.07 KB
/
dataset_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# Copyright 2018 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
import uuid
import pytest
import automl_translation_dataset
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
compute_region = "us-central1"
@pytest.mark.slow
def test_dataset_create_import_delete(capsys):
# create dataset
dataset_name = f"test_{uuid.uuid4().hex[:27]}"
automl_translation_dataset.create_dataset(
project_id, compute_region, dataset_name, "en", "ja"
)
out, _ = capsys.readouterr()
create_dataset_output = out.splitlines()
assert "Dataset id: " in create_dataset_output[1]
# import data
dataset_id = create_dataset_output[1].split()[2]
data = "gs://{}-vcm/en-ja.csv".format(project_id)
automl_translation_dataset.import_data(
project_id, compute_region, dataset_id, data
)
out, _ = capsys.readouterr()
assert "Data imported." in out
# delete dataset
automl_translation_dataset.delete_dataset(
project_id, compute_region, dataset_id
)
out, _ = capsys.readouterr()
assert "Dataset deleted." in out
def test_dataset_list_get(capsys):
# list datasets
automl_translation_dataset.list_datasets(project_id, compute_region, "")
out, _ = capsys.readouterr()
list_dataset_output = out.splitlines()
assert "Dataset id: " in list_dataset_output[2]
# get dataset
dataset_id = list_dataset_output[2].split()[2]
automl_translation_dataset.get_dataset(
project_id, compute_region, dataset_id
)
out, _ = capsys.readouterr()
assert "Dataset name: " in out