def test_get_structured_config_data_illegal_value(test_cls: Any) -> None: with raises(UnsupportedValueType): _utils.get_structured_config_data(test_cls, allow_objects=None) with raises(UnsupportedValueType): _utils.get_structured_config_data(test_cls, allow_objects=False) d = _utils.get_structured_config_data(test_cls, allow_objects=True) assert d["x"] == IllegalType()
def test_get_structured_config_data(self, test_cls_or_obj: Any) -> None: d = _utils.get_structured_config_data(test_cls_or_obj) assert d["x"] == 10 assert d["s"] == "foo" assert d["b"] == bool(True) assert d["f"] == 3.14 assert d["e"] == _TestEnum.A assert d["list1"] == [] assert d["dict1"] == {}
def test_resolve_types() -> None: # simulate `from __future__ import annotations` by using strings for the types @dataclass class Foo: a: "int" = "2" # type: ignore b: "float" = "0.0" # type: ignore c: "str" = 2 # type: ignore assert _utils.get_structured_config_data(Foo) == { "a": 2, "b": 0.0, "c": "2" } assert _utils.get_structured_config_data(Foo()) == { "a": 2, "b": 0.0, "c": "2" }
def test_get_structured_config_data_throws_ValueError(self) -> None: with raises(ValueError): _utils.get_structured_config_data("invalid")