|
5 | 5 | from attrs import Factory, define |
6 | 6 | from pytest import raises |
7 | 7 |
|
| 8 | +from cattrs import Converter |
8 | 9 | from cattrs.cols import ( |
9 | 10 | is_namedtuple, |
10 | 11 | namedtuple_dict_structure_factory, |
11 | 12 | namedtuple_dict_unstructure_factory, |
12 | 13 | ) |
13 | | -from cattrs.converters import Converter |
14 | | -from cattrs.errors import ClassValidationError, ForbiddenExtraKeysError |
| 14 | +from cattrs.converters import BaseConverter |
| 15 | +from cattrs.errors import ( |
| 16 | + ClassValidationError, |
| 17 | + ForbiddenExtraKeysError, |
| 18 | + IterableValidationError, |
| 19 | +) |
| 20 | + |
| 21 | + |
| 22 | +def test_structuring_invalid_tuples(converter: BaseConverter): |
| 23 | + """Structuring (hetero) tuples raises properly.""" |
| 24 | + |
| 25 | + if converter.detailed_validation: |
| 26 | + with raises(IterableValidationError) as exc_info: |
| 27 | + converter.structure(["1", 2, "c"], tuple[int, int, int]) |
| 28 | + assert isinstance(exc_info.value.exceptions[0], ValueError) |
| 29 | + else: |
| 30 | + # `int("c")` raises a ValueError |
| 31 | + with raises(ValueError): |
| 32 | + converter.structure(["1", 2, "c"], tuple[int, int, int]) |
15 | 33 |
|
16 | 34 |
|
17 | 35 | def test_simple_hetero_tuples(genconverter: Converter): |
|
0 commit comments