| 1775 | @pytest.mark.parametrize("forbid_unknown_fields", [False, True]) |
| 1776 | @mapcls_and_from_attributes |
| 1777 | def test_struct_extra_fields(self, forbid_unknown_fields, mapcls, from_attributes): |
| 1778 | class Ex(Struct, forbid_unknown_fields=forbid_unknown_fields): |
| 1779 | a: int |
| 1780 | b: int |
| 1781 | |
| 1782 | msg = mapcls(x=1, a=2, y=3, b=4, z=5) |
| 1783 | if forbid_unknown_fields and issubclass(mapcls, dict): |
| 1784 | with pytest.raises(ValidationError, match="unknown field `x`"): |
| 1785 | convert(msg, Ex, from_attributes=from_attributes) |
| 1786 | else: |
| 1787 | res = convert(msg, Ex, from_attributes=from_attributes) |
| 1788 | assert res == Ex(2, 4) |
| 1789 | |
| 1790 | @mapcls_and_from_attributes |
| 1791 | def test_struct_defaults_missing_fields(self, mapcls, from_attributes): |