2023-11-21 23:51:03 +00:00
|
|
|
import boto3
|
|
|
|
|
2024-01-14 20:51:55 +00:00
|
|
|
from moto import mock_aws
|
|
|
|
from moto.core.decorator import MockAWS
|
2023-11-21 23:51:03 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2024-02-17 08:39:03 +00:00
|
|
|
def method_without_parentheses() -> int:
|
2023-11-21 23:51:03 +00:00
|
|
|
assert boto3.client("s3").list_buckets()["Buckets"] == []
|
|
|
|
return 123
|
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws()
|
2024-02-17 08:39:03 +00:00
|
|
|
def method_with_parentheses() -> int:
|
2023-11-21 23:51:03 +00:00
|
|
|
assert boto3.client("s3").list_buckets()["Buckets"] == []
|
|
|
|
return 456
|
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2023-11-21 23:51:03 +00:00
|
|
|
def test_no_return() -> None:
|
|
|
|
assert boto3.client("s3").list_buckets()["Buckets"] == []
|
|
|
|
|
|
|
|
|
|
|
|
def test_with_context_manager() -> None:
|
2024-01-07 12:03:33 +00:00
|
|
|
with mock_aws():
|
2023-11-21 23:51:03 +00:00
|
|
|
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
|
2024-01-07 12:03:33 +00:00
|
|
|
m: MockAWS = mock_aws()
|
2023-11-21 23:51:03 +00:00
|
|
|
m.start()
|
|
|
|
assert boto3.client("s3").list_buckets()["Buckets"] == []
|
|
|
|
m.stop()
|
|
|
|
|
|
|
|
|
2024-02-17 08:39:03 +00:00
|
|
|
x: int = method_with_parentheses()
|
2023-11-21 23:51:03 +00:00
|
|
|
assert x == 456
|
|
|
|
|
2024-02-17 08:39:03 +00:00
|
|
|
y: int = method_without_parentheses()
|
2023-11-21 23:51:03 +00:00
|
|
|
assert y == 123
|