Skip to content

Commit 5d9b71c

Browse files
committed
Merge branch 'master' into hardcoded-acct-integ-tests
2 parents 159467c + b4e6f3d commit 5d9b71c

File tree

3 files changed

+107
-2
lines changed

3 files changed

+107
-2
lines changed

tests/integ/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
NO_LDA_REGIONS = ["eu-west-3", "eu-north-1", "sa-east-1", "ap-east-1", "me-south-1"]
7878
NO_MARKET_PLACE_REGIONS = ["eu-west-3", "eu-north-1", "sa-east-1", "ap-east-1", "me-south-1"]
79+
NO_AUTO_ML_REGIONS = ["sa-east-1", "me-south-1", "ap-east-1", "eu-west-3"]
7980

8081
EFS_TEST_ENABLED_REGION = []
8182

tests/integ/auto_ml_utils.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
from __future__ import absolute_import
14+
15+
import os
16+
17+
from sagemaker import AutoML
18+
from tests.integ import DATA_DIR, AUTO_ML_DEFAULT_TIMEMOUT_MINUTES
19+
from tests.integ.timeout import timeout
20+
21+
ROLE = "SageMakerRole"
22+
DATA_DIR = os.path.join(DATA_DIR, "automl", "data")
23+
PREFIX = "sagemaker/beta-automl-xgboost"
24+
TRAINING_DATA = os.path.join(DATA_DIR, "iris_training.csv")
25+
TARGET_ATTRIBUTE_NAME = "virginica"
26+
27+
28+
def create_auto_ml_job_if_not_exist(sagemaker_session):
29+
auto_ml_job_name = "python-sdk-integ-test-base-job"
30+
auto_ml = AutoML(
31+
role=ROLE,
32+
target_attribute_name=TARGET_ATTRIBUTE_NAME,
33+
sagemaker_session=sagemaker_session,
34+
max_candidates=3,
35+
)
36+
37+
try:
38+
auto_ml.describe_auto_ml_job(job_name=auto_ml_job_name)
39+
except Exception as e: # noqa: F841
40+
inputs = sagemaker_session.upload_data(path=TRAINING_DATA, key_prefix=PREFIX + "/input")
41+
with timeout(minutes=AUTO_ML_DEFAULT_TIMEMOUT_MINUTES):
42+
auto_ml.fit(inputs, job_name=auto_ml_job_name)

tests/integ/test_auto_ml.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
import time
1717

1818
import pytest
19+
import tests.integ
1920
from sagemaker import AutoML, CandidateEstimator, AutoMLInput
2021

2122
from sagemaker.exceptions import UnexpectedStatusException
2223
from sagemaker.utils import unique_name_from_base
23-
from tests.integ import DATA_DIR, AUTO_ML_DEFAULT_TIMEMOUT_MINUTES
24+
from tests.integ import DATA_DIR, AUTO_ML_DEFAULT_TIMEMOUT_MINUTES, auto_ml_utils
2425
from tests.integ.timeout import timeout
2526

2627
ROLE = "SageMakerRole"
@@ -37,14 +38,18 @@
3738
JOB_NAME = "auto-ml-{}".format(time.strftime("%y%m%d-%H%M%S"))
3839

3940
# use a succeeded AutoML job to test describe and list candidates method, otherwise tests will run too long
40-
AUTO_ML_JOB_NAME = "sagemaker-auto-gamma-ml-test"
41+
AUTO_ML_JOB_NAME = "python-sdk-integ-test-base-job"
4142

4243
EXPECTED_DEFAULT_JOB_CONFIG = {
4344
"CompletionCriteria": {"MaxCandidates": 3},
4445
"SecurityConfig": {"EnableInterContainerTrafficEncryption": False},
4546
}
4647

4748

49+
@pytest.mark.skipif(
50+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
51+
reason="AutoML is not supported in the region yet.",
52+
)
4853
def test_auto_ml_fit(sagemaker_session):
4954
auto_ml = AutoML(
5055
role=ROLE,
@@ -58,6 +63,10 @@ def test_auto_ml_fit(sagemaker_session):
5863
auto_ml.fit(inputs)
5964

6065

66+
@pytest.mark.skipif(
67+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
68+
reason="AutoML is not supported in the region yet.",
69+
)
6170
def test_auto_ml_fit_local_input(sagemaker_session):
6271
auto_ml = AutoML(
6372
role=ROLE,
@@ -71,6 +80,10 @@ def test_auto_ml_fit_local_input(sagemaker_session):
7180
auto_ml.fit(inputs)
7281

7382

83+
@pytest.mark.skipif(
84+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
85+
reason="AutoML is not supported in the region yet.",
86+
)
7487
def test_auto_ml_input_object_fit(sagemaker_session):
7588
auto_ml = AutoML(
7689
role=ROLE,
@@ -84,6 +97,10 @@ def test_auto_ml_input_object_fit(sagemaker_session):
8497
auto_ml.fit(inputs)
8598

8699

100+
@pytest.mark.skipif(
101+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
102+
reason="AutoML is not supported in the region yet.",
103+
)
87104
def test_auto_ml_fit_optional_args(sagemaker_session):
88105
output_path = "s3://{}/{}".format(sagemaker_session.default_bucket(), "specified_ouput_path")
89106
problem_type = "MulticlassClassification"
@@ -109,6 +126,10 @@ def test_auto_ml_fit_optional_args(sagemaker_session):
109126
assert auto_ml_desc["OutputDataConfig"]["S3OutputPath"] == output_path
110127

111128

129+
@pytest.mark.skipif(
130+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
131+
reason="AutoML is not supported in the region yet.",
132+
)
112133
def test_auto_ml_invalid_target_attribute(sagemaker_session):
113134
auto_ml = AutoML(
114135
role=ROLE, target_attribute_name="y", sagemaker_session=sagemaker_session, max_candidates=1
@@ -120,6 +141,10 @@ def test_auto_ml_invalid_target_attribute(sagemaker_session):
120141
auto_ml.fit(inputs)
121142

122143

144+
@pytest.mark.skipif(
145+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
146+
reason="AutoML is not supported in the region yet.",
147+
)
123148
def test_auto_ml_describe_auto_ml_job(sagemaker_session):
124149
expected_default_input_config = [
125150
{
@@ -138,6 +163,7 @@ def test_auto_ml_describe_auto_ml_job(sagemaker_session):
138163
"S3OutputPath": "s3://{}/".format(sagemaker_session.default_bucket())
139164
}
140165

166+
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)
141167
auto_ml = AutoML(
142168
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
143169
)
@@ -151,7 +177,13 @@ def test_auto_ml_describe_auto_ml_job(sagemaker_session):
151177
assert desc["OutputDataConfig"] == expected_default_output_config
152178

153179

180+
@pytest.mark.skipif(
181+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
182+
reason="AutoML is not supported in the region yet.",
183+
)
154184
def test_list_candidates(sagemaker_session):
185+
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)
186+
155187
auto_ml = AutoML(
156188
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
157189
)
@@ -160,7 +192,13 @@ def test_list_candidates(sagemaker_session):
160192
assert len(candidates) == 3
161193

162194

195+
@pytest.mark.skipif(
196+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
197+
reason="AutoML is not supported in the region yet.",
198+
)
163199
def test_best_candidate(sagemaker_session):
200+
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)
201+
164202
auto_ml = AutoML(
165203
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
166204
)
@@ -170,7 +208,13 @@ def test_best_candidate(sagemaker_session):
170208
assert best_candidate["CandidateStatus"] == "Completed"
171209

172210

211+
@pytest.mark.skipif(
212+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
213+
reason="AutoML is not supported in the region yet.",
214+
)
173215
def test_deploy_best_candidate(sagemaker_session):
216+
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)
217+
174218
auto_ml = AutoML(
175219
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
176220
)
@@ -192,7 +236,13 @@ def test_deploy_best_candidate(sagemaker_session):
192236
sagemaker_session.sagemaker_client.delete_endpoint(EndpointName=endpoint_name)
193237

194238

239+
@pytest.mark.skipif(
240+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
241+
reason="AutoML is not supported in the region yet.",
242+
)
195243
def test_candidate_estimator_default_rerun_and_deploy(sagemaker_session):
244+
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)
245+
196246
auto_ml = AutoML(
197247
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
198248
)
@@ -219,7 +269,13 @@ def test_candidate_estimator_default_rerun_and_deploy(sagemaker_session):
219269
sagemaker_session.sagemaker_client.delete_endpoint(EndpointName=endpoint_name)
220270

221271

272+
@pytest.mark.skipif(
273+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
274+
reason="AutoML is not supported in the region yet.",
275+
)
222276
def test_candidate_estimator_rerun_with_optional_args(sagemaker_session):
277+
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)
278+
223279
auto_ml = AutoML(
224280
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
225281
)
@@ -246,7 +302,13 @@ def test_candidate_estimator_rerun_with_optional_args(sagemaker_session):
246302
sagemaker_session.sagemaker_client.delete_endpoint(EndpointName=endpoint_name)
247303

248304

305+
@pytest.mark.skipif(
306+
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
307+
reason="AutoML is not supported in the region yet.",
308+
)
249309
def test_candidate_estimator_get_steps(sagemaker_session):
310+
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)
311+
250312
auto_ml = AutoML(
251313
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
252314
)

0 commit comments

Comments
 (0)