MCPcopy
hub / github.com/msgspec/msgspec / test_init_kw_only

Method test_init_kw_only

tests/unit/test_struct.py:593–611  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

591 Test(1, 2, e=5)
592
593 def test_init_kw_only(self):
594 class Test(Struct, kw_only=True):
595 a: int
596 b: float = 2.0
597 c: int = 3
598
599 assert as_tuple(Test(a=1)) == (1, 2.0, 3)
600 assert as_tuple(Test(a=1, b=4.0)) == (1, 4.0, 3)
601 assert as_tuple(Test(a=1, c=4)) == (1, 2.0, 4)
602 assert as_tuple(Test(a=1, b=4.0, c=5)) == (1, 4.0, 5)
603
604 with pytest.raises(TypeError, match="Missing required argument 'a'"):
605 Test()
606
607 with pytest.raises(TypeError, match="Extra positional arguments provided"):
608 Test(1)
609
610 with pytest.raises(TypeError, match="Unexpected keyword argument 'e'"):
611 Test(a=1, e=5)
612
613 def test_init_kw_only_mixed(self):
614 class Base(Struct, kw_only=True):

Callers

nothing calls this directly

Calls 2

as_tupleFunction · 0.85
TestClass · 0.70

Tested by

no test coverage detected