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

Method test_struct_extra_fields

tests/unit/test_convert.py:1777–1788  ·  view source on GitHub ↗
(self, forbid_unknown_fields, mapcls, from_attributes)

Source from the content-addressed store, hash-verified

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):

Callers

nothing calls this directly

Calls 1

ExClass · 0.70

Tested by

no test coverage detected