1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
import boto3
from moto import mock_aws
from moto.core.decorator import MockAWS
@mock_aws
def method_without_parentheses() -> int:
assert boto3.client("s3").list_buckets()["Buckets"] == []
return 123
@mock_aws()
def method_with_parentheses() -> int:
assert boto3.client("s3").list_buckets()["Buckets"] == []
return 456
@mock_aws
def test_no_return() -> None:
assert boto3.client("s3").list_buckets()["Buckets"] == []
def test_with_context_manager() -> None:
with mock_aws():
assert boto3.client("s3").list_buckets()["Buckets"] == []
def test_manual() -> None:
# this has the explicit type not because it's necessary but so that mypy will
# complain if it's wrong
m: MockAWS = mock_aws()
m.start()
assert boto3.client("s3").list_buckets()["Buckets"] == []
m.stop()
def test_mock_aws_decorator_return_types() -> None:
x: int = method_with_parentheses()
assert x == 456
y: int = method_without_parentheses()
assert y == 123
|