File: test_mypy.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (43 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download
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