Skip to content

Commit

Permalink
Modifies the tests to usse the defaults created in configprovider.py …
Browse files Browse the repository at this point in the history
…and formats the newly addded changes (#3334)
  • Loading branch information
ubaskota authored Jan 14, 2025
1 parent e87c9b7 commit 3d5b6ab
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
35 changes: 17 additions & 18 deletions botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,25 +581,24 @@ def _compute_request_compression_config(self, config_kwargs):
def _validate_min_compression_size(self, min_size):
min_allowed_min_size = 1
max_allowed_min_size = 1048576
if min_size is not None:
error_msg_base = (
f'Invalid value "{min_size}" for '
'request_min_compression_size_bytes.'
error_msg_base = (
f'Invalid value "{min_size}" for '
'request_min_compression_size_bytes.'
)
try:
min_size = int(min_size)
except (ValueError, TypeError):
msg = (
f'{error_msg_base} Value must be an integer. '
f'Received {type(min_size)} instead.'
)
try:
min_size = int(min_size)
except (ValueError, TypeError):
msg = (
f'{error_msg_base} Value must be an integer. '
f'Received {type(min_size)} instead.'
)
raise botocore.exceptions.InvalidConfigError(error_msg=msg)
if not min_allowed_min_size <= min_size <= max_allowed_min_size:
msg = (
f'{error_msg_base} Value must be between '
f'{min_allowed_min_size} and {max_allowed_min_size}.'
)
raise botocore.exceptions.InvalidConfigError(error_msg=msg)
raise botocore.exceptions.InvalidConfigError(error_msg=msg)
if not min_allowed_min_size <= min_size <= max_allowed_min_size:
msg = (
f'{error_msg_base} Value must be between '
f'{min_allowed_min_size} and {max_allowed_min_size}.'
)
raise botocore.exceptions.InvalidConfigError(error_msg=msg)

return min_size

Expand Down
6 changes: 6 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from botocore import credentials, utils
from botocore.awsrequest import AWSResponse
from botocore.compat import HAS_CRT, parse_qs, urlparse
from botocore.configprovider import create_botocore_default_config_mapping
from botocore.stub import Stubber

_LOADER = botocore.loaders.Loader()
Expand Down Expand Up @@ -108,6 +109,11 @@ def create_session(**kwargs):
return session


def get_botocore_default_config_mapping():
session = botocore.session.get_session()
return create_botocore_default_config_mapping(session)


@contextlib.contextmanager
def temporary_file(mode):
"""This is a cross platform temporary file creation.
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from botocore.hooks import HierarchicalEmitter
from botocore.loaders import Loader
from botocore.model import OperationModel, ServiceModel
from tests import mock, unittest
from tests import get_botocore_default_config_mapping, mock, unittest


class BaseDocsTest(unittest.TestCase):
Expand Down Expand Up @@ -109,6 +109,7 @@ def load_service_mock(*args, **kwargs):
'signatureVersions': ['v4'],
}

default_config_mapping = get_botocore_default_config_mapping()
self.creator = ClientCreator(
loader=self.loader,
endpoint_resolver=endpoint_resolver,
Expand All @@ -117,7 +118,7 @@ def load_service_mock(*args, **kwargs):
retry_handler_factory=mock.Mock(),
retry_config_translator=mock.Mock(),
exceptions_factory=mock.Mock(),
config_store=ConfigValueStore(),
config_store=ConfigValueStore(mapping=default_config_mapping),
)

self.client = self.creator.create_client('myservice', 'us-east-1')
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
from botocore.hooks import HierarchicalEmitter
from botocore.model import ServiceModel
from botocore.useragent import UserAgentString
from tests import mock, unittest
from tests import get_botocore_default_config_mapping, mock, unittest


class TestCreateClientArgs(unittest.TestCase):
def setUp(self):
self.event_emitter = mock.Mock(HierarchicalEmitter)
self.config_store = ConfigValueStore()
default_config_mapping = get_botocore_default_config_mapping()
self.config_store = ConfigValueStore(mapping=default_config_mapping)
user_agent_creator = UserAgentString(
platform_name=None,
platform_version=None,
Expand Down
17 changes: 7 additions & 10 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)
from botocore.stub import Stubber
from botocore.useragent import UserAgentString
from tests import mock, unittest
from tests import get_botocore_default_config_mapping, mock, unittest


class TestAutoGeneratedClient(unittest.TestCase):
Expand Down Expand Up @@ -147,7 +147,8 @@ def load_service_mock(*args, **kwargs):
}
self.resolver.construct_endpoint.return_value = self.endpoint_data
self.resolver.get_available_endpoints.return_value = ['us-west-2']
self.config_store = ConfigValueStore()
default_config_mapping = get_botocore_default_config_mapping()
self.config_store = ConfigValueStore(mapping=default_config_mapping)

def tearDown(self):
self.endpoint_creator_patch.stop()
Expand Down Expand Up @@ -1123,15 +1124,11 @@ def test_can_register_standard_retry_mode(self):

def test_can_register_standard_retry_mode_from_config_store(self):
fake_env = {'AWS_RETRY_MODE': 'standard'}
config_store = ConfigValueStore(
mapping={
'retry_mode': ChainProvider(
[
EnvironmentProvider('AWS_RETRY_MODE', fake_env),
]
)
}
default_config_mapping = get_botocore_default_config_mapping()
default_config_mapping['retry_mode'] = ChainProvider(
[EnvironmentProvider('AWS_RETRY_MODE', fake_env)]
)
config_store = ConfigValueStore(mapping=default_config_mapping)
creator = self.create_client_creator(config_store=config_store)
with mock.patch('botocore.client.standard') as standard:
creator.create_client('myservice', 'us-west-2')
Expand Down

0 comments on commit 3d5b6ab

Please sign in to comment.