MCPcopy
hub / github.com/python-attrs/attrs / test_no_init_default

Method test_no_init_default

tests/test_dunders.py:765–786  ·  view source on GitHub ↗

If `init` is False but a Factory is specified, don't allow passing that argument but initialize it anyway.

(self, slots, frozen)

Source from the content-addressed store, hash-verified

763
764 @given(booleans(), booleans())
765 def test_no_init_default(self, slots, frozen):
766 """
767 If `init` is False but a Factory is specified, don't allow passing that
768 argument but initialize it anyway.
769 """
770 C = make_class(
771 "C",
772 {
773 "_a": attr.ib(init=False, default=42),
774 "_b": attr.ib(init=False, default=Factory(list)),
775 "c": attr.ib(),
776 },
777 slots=slots,
778 frozen=frozen,
779 )
780 with pytest.raises(TypeError):
781 C(a=1, c=2)
782 with pytest.raises(TypeError):
783 C(b=1, c=2)
784
785 i = C(23)
786 assert (42, [], 23) == (i._a, i._b, i.c)
787
788 @given(booleans(), booleans())
789 def test_no_init_order(self, slots, frozen):

Callers

nothing calls this directly

Calls 3

make_classFunction · 0.90
FactoryClass · 0.90
CClass · 0.70

Tested by

no test coverage detected