Add warnings about deprecated modules (#4527)
This commit is contained in:
parent
20ba80783d
commit
ab531aed9b
@ -1,8 +1,17 @@
|
||||
import importlib
|
||||
|
||||
|
||||
def lazy_load(module_name, element, boto3_name=None, backend=None):
|
||||
def lazy_load(
|
||||
module_name, element, boto3_name=None, backend=None, warn_repurpose=False
|
||||
):
|
||||
def f(*args, **kwargs):
|
||||
if warn_repurpose:
|
||||
import warnings
|
||||
|
||||
warnings.warn(
|
||||
f"Module {element} has been deprecated, and will be repurposed in a later release. "
|
||||
"Please see https://github.com/spulec/moto/issues/4526 for more information."
|
||||
)
|
||||
module = importlib.import_module(module_name, "moto")
|
||||
return getattr(module, element)(*args, **kwargs)
|
||||
|
||||
@ -53,7 +62,7 @@ mock_datapipeline_deprecated = lazy_load(
|
||||
mock_datasync = lazy_load(".datasync", "mock_datasync")
|
||||
mock_dms = lazy_load(".dms", "mock_dms")
|
||||
mock_ds = lazy_load(".ds", "mock_ds", boto3_name="ds")
|
||||
mock_dynamodb = lazy_load(".dynamodb", "mock_dynamodb")
|
||||
mock_dynamodb = lazy_load(".dynamodb", "mock_dynamodb", warn_repurpose=True)
|
||||
mock_dynamodb_deprecated = lazy_load(".dynamodb", "mock_dynamodb_deprecated")
|
||||
mock_dynamodb2 = lazy_load(".dynamodb2", "mock_dynamodb2", backend="dynamodb_backends2")
|
||||
mock_dynamodb2_deprecated = lazy_load(".dynamodb2", "mock_dynamodb2_deprecated")
|
||||
@ -99,7 +108,7 @@ mock_opsworks_deprecated = lazy_load(".opsworks", "mock_opsworks_deprecated")
|
||||
mock_organizations = lazy_load(".organizations", "mock_organizations")
|
||||
mock_polly = lazy_load(".polly", "mock_polly")
|
||||
mock_ram = lazy_load(".ram", "mock_ram")
|
||||
mock_rds = lazy_load(".rds", "mock_rds")
|
||||
mock_rds = lazy_load(".rds", "mock_rds", warn_repurpose=True)
|
||||
mock_rds_deprecated = lazy_load(".rds", "mock_rds_deprecated")
|
||||
mock_rds2 = lazy_load(".rds2", "mock_rds2", boto3_name="rds")
|
||||
mock_rds2_deprecated = lazy_load(".rds2", "mock_rds2_deprecated")
|
||||
|
@ -3,12 +3,20 @@ import boto.dynamodb
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
import pytest
|
||||
|
||||
from moto import mock_dynamodb_deprecated
|
||||
from moto import mock_dynamodb, mock_dynamodb_deprecated
|
||||
from moto.dynamodb import dynamodb_backend
|
||||
|
||||
from boto.exception import DynamoDBResponseError
|
||||
|
||||
|
||||
def test_deprecation_warning():
|
||||
with pytest.warns(None) as record:
|
||||
mock_dynamodb()
|
||||
str(record[0].message).should.contain(
|
||||
"Module mock_dynamodb has been deprecated, and will be repurposed in a later release"
|
||||
)
|
||||
|
||||
|
||||
# Has boto3 equivalent
|
||||
@mock_dynamodb_deprecated
|
||||
def test_list_tables():
|
||||
|
@ -3,10 +3,19 @@ import boto.rds
|
||||
import boto.vpc
|
||||
from boto.exception import BotoServerError
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
import pytest
|
||||
|
||||
from moto import mock_ec2_deprecated, mock_rds_deprecated, mock_rds
|
||||
|
||||
|
||||
def test_deprecation_warning():
|
||||
with pytest.warns(None) as record:
|
||||
mock_rds()
|
||||
str(record[0].message).should.contain(
|
||||
"Module mock_rds has been deprecated, and will be repurposed in a later release"
|
||||
)
|
||||
|
||||
|
||||
@mock_rds_deprecated
|
||||
def test_create_database():
|
||||
conn = boto.rds.connect_to_region("us-west-2")
|
||||
|
Loading…
Reference in New Issue
Block a user