Port test suite from nose to pytest.
This just eliminates all errors on the tests collection. Elimination of failures is left to the next commit.
This commit is contained in:
parent
47dbad291e
commit
77dc60ea97
146 changed files with 1172 additions and 1277 deletions
|
|
@ -8,7 +8,7 @@ import sure # noqa
|
|||
|
||||
from moto import mock_sagemaker
|
||||
from moto.sts.models import ACCOUNT_ID
|
||||
from nose.tools import assert_true, assert_equal, assert_raises
|
||||
import pytest
|
||||
|
||||
TEST_REGION_NAME = "us-east-1"
|
||||
FAKE_SUBNET_ID = "subnet-012345678"
|
||||
|
|
@ -41,26 +41,25 @@ def test_create_notebook_instance_minimal_params():
|
|||
"RoleArn": FAKE_ROLE_ARN,
|
||||
}
|
||||
resp = sagemaker.create_notebook_instance(**args)
|
||||
assert_true(resp["NotebookInstanceArn"].startswith("arn:aws:sagemaker"))
|
||||
assert_true(resp["NotebookInstanceArn"].endswith(args["NotebookInstanceName"]))
|
||||
assert resp["NotebookInstanceArn"].startswith("arn:aws:sagemaker")
|
||||
assert resp["NotebookInstanceArn"].endswith(args["NotebookInstanceName"])
|
||||
|
||||
resp = sagemaker.describe_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
assert_true(resp["NotebookInstanceArn"].startswith("arn:aws:sagemaker"))
|
||||
assert_true(resp["NotebookInstanceArn"].endswith(args["NotebookInstanceName"]))
|
||||
assert_equal(resp["NotebookInstanceName"], NAME_PARAM)
|
||||
assert_equal(resp["NotebookInstanceStatus"], "InService")
|
||||
assert_equal(
|
||||
resp["Url"], "{}.notebook.{}.sagemaker.aws".format(NAME_PARAM, TEST_REGION_NAME)
|
||||
)
|
||||
assert_equal(resp["InstanceType"], INSTANCE_TYPE_PARAM)
|
||||
assert_equal(resp["RoleArn"], FAKE_ROLE_ARN)
|
||||
assert_true(isinstance(resp["LastModifiedTime"], datetime.datetime))
|
||||
assert_true(isinstance(resp["CreationTime"], datetime.datetime))
|
||||
assert_equal(resp["DirectInternetAccess"], "Enabled")
|
||||
assert_equal(resp["VolumeSizeInGB"], 5)
|
||||
assert resp["NotebookInstanceArn"].startswith("arn:aws:sagemaker")
|
||||
assert resp["NotebookInstanceArn"].endswith(args["NotebookInstanceName"])
|
||||
assert resp["NotebookInstanceName"] == NAME_PARAM
|
||||
assert resp["NotebookInstanceStatus"] == "InService"
|
||||
assert resp["Url"] == \
|
||||
"{}.notebook.{}.sagemaker.aws".format(NAME_PARAM, TEST_REGION_NAME)
|
||||
assert resp["InstanceType"] == INSTANCE_TYPE_PARAM
|
||||
assert resp["RoleArn"] == FAKE_ROLE_ARN
|
||||
assert isinstance(resp["LastModifiedTime"], datetime.datetime)
|
||||
assert isinstance(resp["CreationTime"], datetime.datetime)
|
||||
assert resp["DirectInternetAccess"] == "Enabled"
|
||||
assert resp["VolumeSizeInGB"] == 5
|
||||
|
||||
|
||||
# assert_equal(resp["RootAccess"], True) # ToDo: Not sure if this defaults...
|
||||
# assert resp["RootAccess"] == True # ToDo: Not sure if this defaults...
|
||||
|
||||
|
||||
@mock_sagemaker
|
||||
|
|
@ -92,36 +91,34 @@ def test_create_notebook_instance_params():
|
|||
"RootAccess": ROOT_ACCESS_PARAM,
|
||||
}
|
||||
resp = sagemaker.create_notebook_instance(**args)
|
||||
assert_true(resp["NotebookInstanceArn"].startswith("arn:aws:sagemaker"))
|
||||
assert_true(resp["NotebookInstanceArn"].endswith(args["NotebookInstanceName"]))
|
||||
assert resp["NotebookInstanceArn"].startswith("arn:aws:sagemaker")
|
||||
assert resp["NotebookInstanceArn"].endswith(args["NotebookInstanceName"])
|
||||
|
||||
resp = sagemaker.describe_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
assert_true(resp["NotebookInstanceArn"].startswith("arn:aws:sagemaker"))
|
||||
assert_true(resp["NotebookInstanceArn"].endswith(args["NotebookInstanceName"]))
|
||||
assert_equal(resp["NotebookInstanceName"], NAME_PARAM)
|
||||
assert_equal(resp["NotebookInstanceStatus"], "InService")
|
||||
assert_equal(
|
||||
resp["Url"], "{}.notebook.{}.sagemaker.aws".format(NAME_PARAM, TEST_REGION_NAME)
|
||||
)
|
||||
assert_equal(resp["InstanceType"], INSTANCE_TYPE_PARAM)
|
||||
assert_equal(resp["RoleArn"], FAKE_ROLE_ARN)
|
||||
assert_true(isinstance(resp["LastModifiedTime"], datetime.datetime))
|
||||
assert_true(isinstance(resp["CreationTime"], datetime.datetime))
|
||||
assert_equal(resp["DirectInternetAccess"], "Enabled")
|
||||
assert_equal(resp["VolumeSizeInGB"], VOLUME_SIZE_IN_GB_PARAM)
|
||||
# assert_equal(resp["RootAccess"], True) # ToDo: Not sure if this defaults...
|
||||
assert_equal(resp["SubnetId"], FAKE_SUBNET_ID)
|
||||
assert_equal(resp["SecurityGroups"], FAKE_SECURITY_GROUP_IDS)
|
||||
assert_equal(resp["KmsKeyId"], FAKE_KMS_KEY_ID)
|
||||
assert_equal(
|
||||
resp["NotebookInstanceLifecycleConfigName"], FAKE_LIFECYCLE_CONFIG_NAME
|
||||
)
|
||||
assert_equal(resp["AcceleratorTypes"], ACCELERATOR_TYPES_PARAM)
|
||||
assert_equal(resp["DefaultCodeRepository"], FAKE_DEFAULT_CODE_REPO)
|
||||
assert_equal(resp["AdditionalCodeRepositories"], FAKE_ADDL_CODE_REPOS)
|
||||
assert resp["NotebookInstanceArn"].startswith("arn:aws:sagemaker")
|
||||
assert resp["NotebookInstanceArn"].endswith(args["NotebookInstanceName"])
|
||||
assert resp["NotebookInstanceName"] == NAME_PARAM
|
||||
assert resp["NotebookInstanceStatus"] == "InService"
|
||||
assert resp["Url"] == \
|
||||
"{}.notebook.{}.sagemaker.aws".format(NAME_PARAM, TEST_REGION_NAME)
|
||||
assert resp["InstanceType"] == INSTANCE_TYPE_PARAM
|
||||
assert resp["RoleArn"] == FAKE_ROLE_ARN
|
||||
assert isinstance(resp["LastModifiedTime"], datetime.datetime)
|
||||
assert isinstance(resp["CreationTime"], datetime.datetime)
|
||||
assert resp["DirectInternetAccess"] == "Enabled"
|
||||
assert resp["VolumeSizeInGB"] == VOLUME_SIZE_IN_GB_PARAM
|
||||
# assert resp["RootAccess"] == True # ToDo: Not sure if this defaults...
|
||||
assert resp["SubnetId"] == FAKE_SUBNET_ID
|
||||
assert resp["SecurityGroups"] == FAKE_SECURITY_GROUP_IDS
|
||||
assert resp["KmsKeyId"] == FAKE_KMS_KEY_ID
|
||||
assert resp["NotebookInstanceLifecycleConfigName"] == \
|
||||
FAKE_LIFECYCLE_CONFIG_NAME
|
||||
assert resp["AcceleratorTypes"] == ACCELERATOR_TYPES_PARAM
|
||||
assert resp["DefaultCodeRepository"] == FAKE_DEFAULT_CODE_REPO
|
||||
assert resp["AdditionalCodeRepositories"] == FAKE_ADDL_CODE_REPOS
|
||||
|
||||
resp = sagemaker.list_tags(ResourceArn=resp["NotebookInstanceArn"])
|
||||
assert_equal(resp["Tags"], GENERIC_TAGS_PARAM)
|
||||
assert resp["Tags"] == GENERIC_TAGS_PARAM
|
||||
|
||||
|
||||
@mock_sagemaker
|
||||
|
|
@ -136,14 +133,11 @@ def test_create_notebook_instance_bad_volume_size():
|
|||
"RoleArn": FAKE_ROLE_ARN,
|
||||
"VolumeSizeInGB": vol_size,
|
||||
}
|
||||
with assert_raises(ParamValidationError) as ex:
|
||||
resp = sagemaker.create_notebook_instance(**args)
|
||||
assert_equal(
|
||||
ex.exception.args[0],
|
||||
"Parameter validation failed:\nInvalid range for parameter VolumeSizeInGB, value: {}, valid range: 5-inf".format(
|
||||
vol_size
|
||||
),
|
||||
)
|
||||
with pytest.raises(ParamValidationError) as ex:
|
||||
sagemaker.create_notebook_instance(**args)
|
||||
assert \
|
||||
ex.exception.args[0] == \
|
||||
"Parameter validation failed:\nInvalid range for parameter VolumeSizeInGB, value: {}, valid range: 5-inf".format(vol_size)
|
||||
|
||||
|
||||
@mock_sagemaker
|
||||
|
|
@ -157,14 +151,14 @@ def test_create_notebook_instance_invalid_instance_type():
|
|||
"InstanceType": instance_type,
|
||||
"RoleArn": FAKE_ROLE_ARN,
|
||||
}
|
||||
with assert_raises(ClientError) as ex:
|
||||
resp = sagemaker.create_notebook_instance(**args)
|
||||
assert_equal(ex.exception.response["Error"]["Code"], "ValidationException")
|
||||
with pytest.raises(ClientError) as ex:
|
||||
sagemaker.create_notebook_instance(**args)
|
||||
assert ex.exception.response["Error"]["Code"] == "ValidationException"
|
||||
expected_message = "Value '{}' at 'instanceType' failed to satisfy constraint: Member must satisfy enum value set: [".format(
|
||||
instance_type
|
||||
)
|
||||
|
||||
assert_true(expected_message in ex.exception.response["Error"]["Message"])
|
||||
assert expected_message in ex.exception.response["Error"]["Message"]
|
||||
|
||||
|
||||
@mock_sagemaker
|
||||
|
|
@ -180,51 +174,49 @@ def test_notebook_instance_lifecycle():
|
|||
"RoleArn": FAKE_ROLE_ARN,
|
||||
}
|
||||
resp = sagemaker.create_notebook_instance(**args)
|
||||
assert_true(resp["NotebookInstanceArn"].startswith("arn:aws:sagemaker"))
|
||||
assert_true(resp["NotebookInstanceArn"].endswith(args["NotebookInstanceName"]))
|
||||
assert resp["NotebookInstanceArn"].startswith("arn:aws:sagemaker")
|
||||
assert resp["NotebookInstanceArn"].endswith(args["NotebookInstanceName"])
|
||||
|
||||
resp = sagemaker.describe_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
notebook_instance_arn = resp["NotebookInstanceArn"]
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
sagemaker.delete_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
assert_equal(ex.exception.response["Error"]["Code"], "ValidationException")
|
||||
assert ex.exception.response["Error"]["Code"] == "ValidationException"
|
||||
expected_message = "Status (InService) not in ([Stopped, Failed]). Unable to transition to (Deleting) for Notebook Instance ({})".format(
|
||||
notebook_instance_arn
|
||||
)
|
||||
assert_true(expected_message in ex.exception.response["Error"]["Message"])
|
||||
assert expected_message in ex.exception.response["Error"]["Message"]
|
||||
|
||||
sagemaker.stop_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
|
||||
resp = sagemaker.describe_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
assert_equal(resp["NotebookInstanceStatus"], "Stopped")
|
||||
assert resp["NotebookInstanceStatus"] == "Stopped"
|
||||
|
||||
sagemaker.start_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
|
||||
resp = sagemaker.describe_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
assert_equal(resp["NotebookInstanceStatus"], "InService")
|
||||
assert resp["NotebookInstanceStatus"] == "InService"
|
||||
|
||||
sagemaker.stop_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
|
||||
resp = sagemaker.describe_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
assert_equal(resp["NotebookInstanceStatus"], "Stopped")
|
||||
assert resp["NotebookInstanceStatus"] == "Stopped"
|
||||
|
||||
sagemaker.delete_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
sagemaker.describe_notebook_instance(NotebookInstanceName=NAME_PARAM)
|
||||
assert_equal(ex.exception.response["Error"]["Message"], "RecordNotFound")
|
||||
assert ex.exception.response["Error"]["Message"] == "RecordNotFound"
|
||||
|
||||
|
||||
@mock_sagemaker
|
||||
def test_describe_nonexistent_model():
|
||||
sagemaker = boto3.client("sagemaker", region_name=TEST_REGION_NAME)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
resp = sagemaker.describe_model(ModelName="Nonexistent")
|
||||
assert_true(
|
||||
e.exception.response["Error"]["Message"].startswith("Could not find model")
|
||||
)
|
||||
with pytest.raises(ClientError) as e:
|
||||
sagemaker.describe_model(ModelName="Nonexistent")
|
||||
assert e.exception.response["Error"]["Message"].startswith("Could not find model")
|
||||
|
||||
|
||||
@mock_sagemaker
|
||||
|
|
@ -237,56 +229,50 @@ def test_notebook_instance_lifecycle_config():
|
|||
resp = sagemaker.create_notebook_instance_lifecycle_config(
|
||||
NotebookInstanceLifecycleConfigName=name, OnCreate=on_create, OnStart=on_start
|
||||
)
|
||||
assert_true(
|
||||
resp["NotebookInstanceLifecycleConfigArn"].startswith("arn:aws:sagemaker")
|
||||
)
|
||||
assert_true(resp["NotebookInstanceLifecycleConfigArn"].endswith(name))
|
||||
assert resp["NotebookInstanceLifecycleConfigArn"].startswith("arn:aws:sagemaker")
|
||||
assert resp["NotebookInstanceLifecycleConfigArn"].endswith(name)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
resp = sagemaker.create_notebook_instance_lifecycle_config(
|
||||
NotebookInstanceLifecycleConfigName=name,
|
||||
OnCreate=on_create,
|
||||
OnStart=on_start,
|
||||
)
|
||||
assert_true(
|
||||
assert \
|
||||
e.exception.response["Error"]["Message"].endswith(
|
||||
"Notebook Instance Lifecycle Config already exists.)"
|
||||
)
|
||||
)
|
||||
|
||||
resp = sagemaker.describe_notebook_instance_lifecycle_config(
|
||||
NotebookInstanceLifecycleConfigName=name,
|
||||
)
|
||||
assert_equal(resp["NotebookInstanceLifecycleConfigName"], name)
|
||||
assert_true(
|
||||
assert resp["NotebookInstanceLifecycleConfigName"] == name
|
||||
assert \
|
||||
resp["NotebookInstanceLifecycleConfigArn"].startswith("arn:aws:sagemaker")
|
||||
)
|
||||
assert_true(resp["NotebookInstanceLifecycleConfigArn"].endswith(name))
|
||||
assert_equal(resp["OnStart"], on_start)
|
||||
assert_equal(resp["OnCreate"], on_create)
|
||||
assert_true(isinstance(resp["LastModifiedTime"], datetime.datetime))
|
||||
assert_true(isinstance(resp["CreationTime"], datetime.datetime))
|
||||
assert resp["NotebookInstanceLifecycleConfigArn"].endswith(name)
|
||||
assert resp["OnStart"] == on_start
|
||||
assert resp["OnCreate"] == on_create
|
||||
assert isinstance(resp["LastModifiedTime"], datetime.datetime)
|
||||
assert isinstance(resp["CreationTime"], datetime.datetime)
|
||||
|
||||
sagemaker.delete_notebook_instance_lifecycle_config(
|
||||
NotebookInstanceLifecycleConfigName=name,
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
sagemaker.describe_notebook_instance_lifecycle_config(
|
||||
NotebookInstanceLifecycleConfigName=name,
|
||||
)
|
||||
assert_true(
|
||||
assert \
|
||||
e.exception.response["Error"]["Message"].endswith(
|
||||
"Notebook Instance Lifecycle Config does not exist.)"
|
||||
)
|
||||
)
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
with pytest.raises(ClientError) as e:
|
||||
sagemaker.delete_notebook_instance_lifecycle_config(
|
||||
NotebookInstanceLifecycleConfigName=name,
|
||||
)
|
||||
assert_true(
|
||||
assert \
|
||||
e.exception.response["Error"]["Message"].endswith(
|
||||
"Notebook Instance Lifecycle Config does not exist.)"
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue