MCPcopy Index your code
hub / github.com/msgspec/msgspec / test_struct_extra_fields

Method test_struct_extra_fields

tests/unit/test_convert.py:1957–1970  ·  view source on GitHub ↗
(self, forbid_unknown_fields)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 2

roundtripFunction · 0.85
ExClass · 0.70

Tested by

no test coverage detected