|
12 | 12 | from attrs import Factory, define |
13 | 13 | from pytest import raises |
14 | 14 |
|
15 | | -from cattrs import Converter, transform_error |
| 15 | +from cattrs import Converter, IterableValidationError, transform_error |
16 | 16 | from cattrs._compat import Mapping, TypedDict |
17 | 17 | from cattrs.gen import make_dict_structure_fn |
18 | 18 | from cattrs.v import format_exception |
@@ -321,3 +321,25 @@ class E(TypedDict): |
321 | 321 | assert transform_error(exc.value) == [ |
322 | 322 | f"invalid value for type, expected {tn} (invalid literal for int() with base 10: 'str') @ $.a" |
323 | 323 | ] |
| 324 | + |
| 325 | + |
| 326 | +def test_iterable_val_no_note(): |
| 327 | + """`IterableValidationErrors` require subexceptions with notes.""" |
| 328 | + with raises(AttributeError): |
| 329 | + IterableValidationError("Test", [RuntimeError()], List[str]).group_exceptions() |
| 330 | + |
| 331 | + r = RuntimeError() |
| 332 | + r.__notes__ = ["test"] |
| 333 | + with raises(AttributeError): |
| 334 | + IterableValidationError("Test", [r], List[str]).group_exceptions() |
| 335 | + |
| 336 | + |
| 337 | +def test_typeerror_formatting(): |
| 338 | + """`format_exception` works with non-iteration TypeErrors.""" |
| 339 | + exc = TypeError("exception") |
| 340 | + assert format_exception(exc, None) == "invalid type (exception)" |
| 341 | + |
| 342 | + |
| 343 | +def test_other_formatting(): |
| 344 | + """`format_exception` handles unsupported errors.""" |
| 345 | + assert format_exception(RuntimeError("test"), None) == "unknown error (test)" |
0 commit comments