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

Method test_struct_array_like

tests/unit/test_convert.py:1929–1954  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1927 verified: bool = False
1928
1929 def test_struct_array_like(self):
1930 msg = self.Account("alice", "munro", 91, True)
1931 res = roundtrip(msg, self.Account)
1932 assert res == msg
1933
1934 with pytest.raises(ValidationError, match="Expected `array`, got `int`"):
1935 roundtrip(1, self.Account)
1936
1937 # Wrong field type
1938 with pytest.raises(
1939 ValidationError, match=r"Expected `int`, got `str` - at `\$\[2\]`"
1940 ):
1941 roundtrip(("alice", "munro", "bad"), self.Account)
1942
1943 # Missing fields
1944 with pytest.raises(
1945 ValidationError,
1946 match="Expected `array` of at least length 3, got 2",
1947 ):
1948 roundtrip(("alice", "munro"), self.Account)
1949
1950 with pytest.raises(
1951 ValidationError,
1952 match="Expected `array` of at least length 3, got 0",
1953 ):
1954 roundtrip((), self.Account)
1955
1956 @pytest.mark.parametrize("forbid_unknown_fields", [False, True])
1957 def test_struct_extra_fields(self, forbid_unknown_fields):

Callers

nothing calls this directly

Calls 1

roundtripFunction · 0.85

Tested by

no test coverage detected