Test TypedDict support
This commit is contained in:
parent
6092c2455f
commit
3a7f1179fa
|
@ -4,11 +4,13 @@ This file is not executed, it is only checked by mypy to ensure that
|
||||||
none of the code triggers any mypy errors.
|
none of the code triggers any mypy errors.
|
||||||
"""
|
"""
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import sys
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from typing_extensions import assert_type
|
from typing_extensions import assert_type
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from _pytest.monkeypatch import MonkeyPatch
|
||||||
|
|
||||||
|
|
||||||
# Issue #7488.
|
# Issue #7488.
|
||||||
|
@ -29,6 +31,16 @@ def check_parametrize_ids_callable(func) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Issue #10999.
|
||||||
|
@pytest.mark.skipif(sys.version_info < (3, 8), reason="TypedDict introduced in Python 3.8")
|
||||||
|
def check_monkeypatch_typeddict(monkeypatch: MonkeyPatch) -> None:
|
||||||
|
from typing import TypedDict
|
||||||
|
|
||||||
|
Foo = TypedDict("Foo", {"x": int, "y": float})
|
||||||
|
a: Foo = {"x": 1, "y": 3.14}
|
||||||
|
monkeypatch.setitem("x", 2)
|
||||||
|
monkeypatch.delitem("y")
|
||||||
|
|
||||||
def check_raises_is_a_context_manager(val: bool) -> None:
|
def check_raises_is_a_context_manager(val: bool) -> None:
|
||||||
with pytest.raises(RuntimeError) if val else contextlib.nullcontext() as excinfo:
|
with pytest.raises(RuntimeError) if val else contextlib.nullcontext() as excinfo:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue