2020-07-14 19:36:41 +08:00
|
|
|
"""File for checking typing issues.
|
|
|
|
|
|
|
|
This file is not executed, it is only checked by mypy to ensure that
|
|
|
|
none of the code triggers any mypy errors.
|
|
|
|
"""
|
2023-01-13 22:29:38 +08:00
|
|
|
import contextlib
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from typing_extensions import assert_type
|
|
|
|
|
2020-07-14 19:36:41 +08:00
|
|
|
import pytest
|
2023-05-15 03:17:00 +08:00
|
|
|
from pytest import MonkeyPatch
|
2020-07-14 19:36:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Issue #7488.
|
|
|
|
@pytest.mark.xfail(raises=RuntimeError)
|
|
|
|
def check_mark_xfail_raises() -> None:
|
|
|
|
pass
|
2020-07-14 18:05:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Issue #7494.
|
|
|
|
@pytest.fixture(params=[(0, 0), (1, 1)], ids=lambda x: str(x[0]))
|
|
|
|
def check_fixture_ids_callable() -> None:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# Issue #7494.
|
|
|
|
@pytest.mark.parametrize("func", [str, int], ids=lambda x: str(x.__name__))
|
|
|
|
def check_parametrize_ids_callable(func) -> None:
|
|
|
|
pass
|
2023-01-13 22:29:38 +08:00
|
|
|
|
|
|
|
|
2023-05-15 03:17:00 +08:00
|
|
|
# Issue #10999.
|
|
|
|
def check_monkeypatch_typeddict(monkeypatch: MonkeyPatch) -> None:
|
|
|
|
from typing import TypedDict
|
|
|
|
|
|
|
|
class Foo(TypedDict):
|
|
|
|
x: int
|
|
|
|
y: float
|
|
|
|
|
|
|
|
a: Foo = {"x": 1, "y": 3.14}
|
|
|
|
monkeypatch.setitem(a, "x", 2)
|
|
|
|
monkeypatch.delitem(a, "y")
|
|
|
|
|
|
|
|
|
2023-01-13 22:29:38 +08:00
|
|
|
def check_raises_is_a_context_manager(val: bool) -> None:
|
|
|
|
with pytest.raises(RuntimeError) if val else contextlib.nullcontext() as excinfo:
|
|
|
|
pass
|
|
|
|
assert_type(excinfo, Optional[pytest.ExceptionInfo[RuntimeError]])
|