-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
291 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
codecov: | ||
branch: master | ||
|
||
coverage: | ||
range: "95..100" | ||
|
||
status: | ||
project: no | ||
|
||
flags: | ||
library: | ||
paths: | ||
- aiobotocore/ | ||
configs: | ||
paths: | ||
- requirements/ | ||
- ".git*" | ||
- "*.toml" | ||
- "*.yml" | ||
changelog: | ||
paths: | ||
- CHANGES/ | ||
- CHANGES.rst | ||
docs: | ||
paths: | ||
- docs/ | ||
- "*.md" | ||
- "*.rst" | ||
- "*.txt" | ||
tests: | ||
paths: | ||
- tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from contextlib import asynccontextmanager, AsyncExitStack | ||
|
||
import aiobotocore.session | ||
from botocore.stub import Stubber | ||
|
||
|
||
class StubbedSession(aiobotocore.session.AioSession): | ||
def __init__(self, *args, **kwargs): | ||
super(StubbedSession, self).__init__(*args, **kwargs) | ||
self._cached_clients = {} | ||
self._client_stubs = {} | ||
|
||
@asynccontextmanager | ||
async def create_client(self, service_name, *args, **kwargs): | ||
async with AsyncExitStack() as es: | ||
es: AsyncExitStack | ||
if service_name not in self._cached_clients: | ||
client = await es.enter_async_context( | ||
self._create_stubbed_client(service_name, *args, **kwargs)) | ||
self._cached_clients[service_name] = client | ||
yield self._cached_clients[service_name] | ||
|
||
@asynccontextmanager | ||
async def _create_stubbed_client(self, service_name, *args, **kwargs): | ||
async with AsyncExitStack() as es: | ||
es: AsyncExitStack | ||
client = await es.enter_async_context( | ||
super(StubbedSession, self).create_client( | ||
service_name, *args, **kwargs)) | ||
stubber = Stubber(client) | ||
self._client_stubs[service_name] = stubber | ||
yield client | ||
|
||
@asynccontextmanager | ||
async def stub(self, service_name, *args, **kwargs): | ||
async with AsyncExitStack() as es: | ||
es: AsyncExitStack | ||
if service_name not in self._client_stubs: | ||
await es.enter_async_context( | ||
self.create_client(service_name, *args, **kwargs)) | ||
yield self._client_stubs[service_name] | ||
|
||
def activate_stubs(self): | ||
for stub in self._client_stubs.values(): | ||
stub.activate() | ||
|
||
def verify_stubs(self): | ||
for stub in self._client_stubs.values(): | ||
stub.assert_no_pending_responses() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters