| 1955 | |
| 1956 | @pytest.mark.parametrize("forbid_unknown_fields", [False, True]) |
| 1957 | def test_struct_extra_fields(self, forbid_unknown_fields): |
| 1958 | class Ex(Struct, array_like=True, forbid_unknown_fields=forbid_unknown_fields): |
| 1959 | a: int |
| 1960 | b: int |
| 1961 | |
| 1962 | msg = (1, 2, 3, 4) |
| 1963 | if forbid_unknown_fields: |
| 1964 | with pytest.raises( |
| 1965 | ValidationError, match="Expected `array` of at most length 2, got 4" |
| 1966 | ): |
| 1967 | roundtrip(msg, Ex) |
| 1968 | else: |
| 1969 | res = roundtrip(msg, Ex) |
| 1970 | assert res == Ex(1, 2) |
| 1971 | |
| 1972 | def test_struct_defaults_missing_fields(self): |
| 1973 | res = roundtrip(("alice", "munro", 91), self.Account) |