Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move test helper functions to tests/__init__.py #2986

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 @@ -575,3 +585,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)
15 changes: 1 addition & 14 deletions tests/functional/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/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