Skip to content

Commit

Permalink
Port test refactoring for enumerating all services
Browse files Browse the repository at this point in the history
Upstream botocore PR: boto/botocore#2986
  • Loading branch information
kyleknap committed Sep 25, 2023
1 parent b3bb8b5 commit c7a74c1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
7 changes: 4 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@
# Botocore testing utilities that we want to preserve import statements for
# in botocore specific tests.
from tests.utils.botocore import (
assert_url_equal, create_session, random_chars, temporary_file, BaseEnvVar,
BaseSessionTest, BaseClientDriverTest, StubbedSession, ClientHTTPStubber,
SessionHTTPStubber, IntegerRefresher, FreezeTime,
assert_url_equal, create_session, random_chars, temporary_file,
patch_load_service_model, ALL_SERVICES, BaseEnvVar, BaseSessionTest,
BaseClientDriverTest, StubbedSession, ClientHTTPStubber, SessionHTTPStubber,
IntegerRefresher, FreezeTime,
)
# S3transfer testing utilities that we want to preserve import statements for
# in s3transfer specific tests.
Expand Down
15 changes: 1 addition & 14 deletions tests/functional/botocore/test_context_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pytest

from botocore.config import Config
from tests import ClientHTTPStubber, mock
from tests import ClientHTTPStubber, mock, patch_load_service_model

# fake rulesets compatible with all fake service models below
FAKE_RULESET_TEMPLATE = {
Expand Down Expand Up @@ -226,19 +226,6 @@
}


def patch_load_service_model(
session, monkeypatch, service_model_json, ruleset_json
):
def mock_load_service_model(service_name, type_name, api_version=None):
if type_name == 'service-2':
return service_model_json
if type_name == 'endpoint-rule-set-1':
return ruleset_json

loader = session.get_component('data_loader')
monkeypatch.setattr(loader, 'load_service_model', mock_load_service_model)


@pytest.mark.parametrize(
'service_name,service_model,ruleset,call_should_include_ctx_param',
[
Expand Down
12 changes: 1 addition & 11 deletions tests/functional/botocore/test_response_shadowing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@
# language governing permissions and limitations under the License.
import pytest

from botocore.session import Session


def _all_services():
session = Session()
service_names = session.get_available_services()
return [session.get_service_model(name) for name in service_names]


# Only compute our service models once
ALL_SERVICES = _all_services()
from tests import ALL_SERVICES


def _all_service_error_shapes():
Expand Down
23 changes: 23 additions & 0 deletions tests/utils/botocore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
_LOADER = botocore.loaders.Loader()


def _all_services():
session = botocore.session.Session()
service_names = session.get_available_services()
return [session.get_service_model(name) for name in service_names]


# Only compute our service models once
ALL_SERVICES = _all_services()


def skip_unless_has_memory_collection(cls):
"""Class decorator to skip tests that require memory collection.
Expand Down Expand Up @@ -568,3 +578,16 @@ def __enter__(self, *args, **kwargs):

def __exit__(self, *args, **kwargs):
self.datetime_patcher.stop()


def patch_load_service_model(
session, monkeypatch, service_model_json, ruleset_json
):
def mock_load_service_model(service_name, type_name, api_version=None):
if type_name == 'service-2':
return service_model_json
if type_name == 'endpoint-rule-set-1':
return ruleset_json

loader = session.get_component('data_loader')
monkeypatch.setattr(loader, 'load_service_model', mock_load_service_model)

0 comments on commit c7a74c1

Please sign in to comment.