Skip to content

Commit

Permalink
samples: tests refactored due to overwhelmed resources (#79)
Browse files Browse the repository at this point in the history
* samples: tests refactored due to overwhelmed resources

* fixed the lint issues

* lint
  • Loading branch information
munkhuushmgl authored Sep 25, 2020
1 parent 411d98f commit c6b4576
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 116 deletions.
2 changes: 1 addition & 1 deletion automl/beta/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-automl==1.0.1
google-cloud-automl==2.0.0
34 changes: 9 additions & 25 deletions automl/beta/video_classification_create_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,20 @@
# limitations under the License.

import os
import uuid

from google.cloud import automl_v1beta1 as automl
import pytest

import video_classification_create_model

PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
DATASET_ID = "VCN510437278078730240"
DATASET_ID = "VCN00000000000000000"
OPERATION_ID = None


@pytest.fixture(scope="function", autouse=True)
def teardown():
yield

# Cancel the training operation
client = automl.AutoMlClient()
client._transport.operations_client.cancel_operation(OPERATION_ID)


def test_video_classification_create_model(capsys):
model_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32]
video_classification_create_model.create_model(
PROJECT_ID, DATASET_ID, model_name
)

out, _ = capsys.readouterr()
assert "Training started" in out

# Cancel the operation
global OPERATION_ID
OPERATION_ID = out.split("Training operation name: ")[1].split("\n")[0]
try:
video_classification_create_model.create_model(
PROJECT_ID, DATASET_ID, "video_class_test_create_model"
)
out, _ = capsys.readouterr()
assert "Dataset does not exist." in out
except Exception as e:
assert "Dataset does not exist." in e.message
33 changes: 9 additions & 24 deletions automl/beta/video_object_tracking_create_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,20 @@
# limitations under the License.

import os
import uuid

from google.cloud import automl_v1beta1 as automl
import pytest

import video_object_tracking_create_model

PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
DATASET_ID = "VOT2823376535338090496"
DATASET_ID = "VOT00000000000000000000"
OPERATION_ID = None


@pytest.fixture(scope="function", autouse=True)
def teardown():
yield

# Cancel the training operation
client = automl.AutoMlClient()
client._transport.operations_client.cancel_operation(OPERATION_ID)


def test_video_classification_create_model(capsys):
model_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32]
video_object_tracking_create_model.create_model(
PROJECT_ID, DATASET_ID, model_name
)
out, _ = capsys.readouterr()
assert "Training started" in out

# Cancel the operation
global OPERATION_ID
OPERATION_ID = out.split("Training operation name: ")[1].split("\n")[0]
try:
video_object_tracking_create_model.create_model(
PROJECT_ID, DATASET_ID, "video_object_test_create_model"
)
out, _ = capsys.readouterr()
assert "Dataset does not exist." in out
except Exception as e:
assert "Dataset does not exist." in e.message
21 changes: 9 additions & 12 deletions automl/snippets/language_sentiment_analysis_create_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@

import os

import pytest

import language_sentiment_analysis_create_model

PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
DATASET_ID = os.environ["SENTIMENT_ANALYSIS_DATASET_ID"]
DATASET_ID = "TST00000000000000000"


@pytest.mark.slow
def test_sentiment_analysis_create_model(capsys):
operation = language_sentiment_analysis_create_model.create_model(
PROJECT_ID, DATASET_ID, "sentiment_test_create_model"
)
out, _ = capsys.readouterr()
assert "Training started" in out

# Cancel the operation
operation.cancel()
try:
language_sentiment_analysis_create_model.create_model(
PROJECT_ID, DATASET_ID, "lang_sent_test_create_model"
)
out, _ = capsys.readouterr()
assert "Dataset does not exist." in out
except Exception as e:
assert "Dataset does not exist." in e.message
24 changes: 9 additions & 15 deletions automl/snippets/language_text_classification_create_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,18 @@

import os

from google.cloud import automl
import pytest

import language_text_classification_create_model

PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
DATASET_ID = os.environ["TEXT_CLASSIFICATION_DATASET_ID"]
DATASET_ID = "TCN00000000000000000000"


@pytest.mark.slow
def test_text_classification_create_model(capsys):
language_text_classification_create_model.create_model(
PROJECT_ID, DATASET_ID, "classification_test_create_model"
)
out, _ = capsys.readouterr()
assert "Training started" in out

# Cancel the operation
operation_id = out.split("Training operation name: ")[1].split("\n")[0]
client = automl.AutoMlClient()
client._transport.operations_client.cancel_operation(operation_id)
try:
language_text_classification_create_model.create_model(
PROJECT_ID, DATASET_ID, "lang_text_test_create_model"
)
out, _ = capsys.readouterr()
assert "Dataset does not exist." in out
except Exception as e:
assert "Dataset does not exist." in e.message
4 changes: 2 additions & 2 deletions automl/snippets/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
google-cloud-translate==2.0.2
google-cloud-translate==3.0.1
google-cloud-storage==1.31.2
google-cloud-automl==1.0.1
google-cloud-automl==2.0.0
22 changes: 9 additions & 13 deletions automl/snippets/translate_create_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@

import os

from google.cloud import automl

import translate_create_model

PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
DATASET_ID = os.environ["TRANSLATION_DATASET_ID"]
DATASET_ID = "TRL00000000000000000"


def test_translate_create_model(capsys):
translate_create_model.create_model(
PROJECT_ID, DATASET_ID, "translate_test_create_model"
)
out, _ = capsys.readouterr()
assert "Training started" in out

# Cancel the operation
operation_id = out.split("Training operation name: ")[1].split("\n")[0]
client = automl.AutoMlClient()
client._transport.operations_client.cancel_operation(operation_id)
try:
translate_create_model.create_model(
PROJECT_ID, DATASET_ID, "translate_test_create_model"
)
out, _ = capsys.readouterr()
assert "Dataset does not exist." in out
except Exception as e:
assert "Dataset does not exist." in e.message
21 changes: 9 additions & 12 deletions automl/snippets/vision_classification_create_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@

import os

import pytest

import vision_classification_create_model

PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
DATASET_ID = os.environ["VISION_CLASSIFICATION_DATASET_ID"]
DATASET_ID = "ICN000000000000000000"


@pytest.mark.slow
def test_vision_classification_create_model(capsys):
operation = vision_classification_create_model.create_model(
PROJECT_ID, DATASET_ID, "classification_test_create_model"
)
out, _ = capsys.readouterr()
assert "Training started" in out

# Cancel the operation
operation.cancel()
try:
vision_classification_create_model.create_model(
PROJECT_ID, DATASET_ID, "classification_test_create_model"
)
out, _ = capsys.readouterr()
assert "Dataset does not exist." in out
except Exception as e:
assert "Dataset does not exist." in e.message
21 changes: 9 additions & 12 deletions automl/snippets/vision_object_detection_create_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@

import os

import pytest

import vision_object_detection_create_model

PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
DATASET_ID = os.environ["OBJECT_DETECTION_DATASET_ID"]
DATASET_ID = "IOD0000000000000000"


@pytest.mark.slow
def test_vision_object_detection_create_model(capsys):
operation = vision_object_detection_create_model.create_model(
PROJECT_ID, DATASET_ID, "object_test_create_model"
)
out, _ = capsys.readouterr()
assert "Training started" in out

# Cancel the operation
operation.cancel()
try:
vision_object_detection_create_model.create_model(
PROJECT_ID, DATASET_ID, "object_test_create_model"
)
out, _ = capsys.readouterr()
assert "Dataset does not exist." in out
except Exception as e:
assert "Dataset does not exist." in e.message

0 comments on commit c6b4576

Please sign in to comment.