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
|
from __future__ import annotations
from collections.abc import Mapping
from typing import Any, Callable
import pytest
from anyio import TypedAttributeProvider
class DummyAttributeProvider(TypedAttributeProvider):
def get_dummyattr(self) -> str:
raise KeyError("foo")
@property
def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]:
return {str: self.get_dummyattr}
def test_typedattr_keyerror() -> None:
"""
Test that if the extra attribute getter raises KeyError, it won't be confused for a
missing attribute.
"""
with pytest.raises(KeyError, match="^'foo'$"):
DummyAttributeProvider().extra(str)
|