MCPcopy
hub / github.com/msgspec/msgspec / test_init_kw_only_mixed

Method test_init_kw_only_mixed

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

Source from the content-addressed store, hash-verified

611 Test(a=1, e=5)
612
613 def test_init_kw_only_mixed(self):
614 class Base(Struct, kw_only=True):
615 c: int = 3
616 d: float = 4.0
617
618 class Test(Base):
619 a: int
620 b: float = 2.0
621
622 assert as_tuple(Test(1)) == (1, 2.0, 3, 4.0)
623 assert as_tuple(Test(1, 5.0)) == (1, 5.0, 3, 4.0)
624 assert as_tuple(Test(a=1)) == (1, 2.0, 3, 4.0)
625 assert as_tuple(Test(a=1, b=5.0)) == (1, 5.0, 3, 4.0)
626 assert as_tuple(Test(1, c=5)) == (1, 2.0, 5, 4.0)
627
628 with pytest.raises(TypeError, match="Missing required argument 'a'"):
629 Test()
630
631 with pytest.raises(TypeError, match="Argument 'a' given by name and position"):
632 Test(1, b=3.0, c=4, a=3)
633
634 with pytest.raises(TypeError, match="Extra positional arguments provided"):
635 Test(1, 5.0, 3)
636
637 with pytest.raises(TypeError, match="Unexpected keyword argument 'e'"):
638 Test(1, e=5)
639
640
641class TestSignature:

Callers

nothing calls this directly

Calls 2

as_tupleFunction · 0.85
TestClass · 0.70

Tested by

no test coverage detected