class C: @Attr.set_value def x(self, attr, value): attr.value = value * 5 y = Attr() @y.set_value def y(self, attr, value): attr.value = value * 2
class C: x = Attr() @x.init_value def x(self, attr, value): attr.value = value.upper() @Attr.init_value def y(self, attr, value): attr.value = value.lower()
class C: @Attr.get_value def x(self, attr): return attr.value * 5 if attr.value else attr.value y = Attr() @y.get_value def y(self, attr): return attr.value * 2 if attr.value else attr.value
class C: @Attr.init_value def x(self, attr): attr.value = 5 y = Attr() @y.init_value def y(self, attr): attr.value = 20
class D(C): z = Attr()
class C: x = Attr(safe=True)
class C: x = Attr(safe=True, cli=True) y = Attr(cli='y')
class C: x = Attr() @Attr def y(self, attr): return attr.value
class C: w = Attr() x = Attr() y = Attr()
class D(C): a = Attr() x = 5 b = Attr()
def test_cannot_reset_attr_on_attrs(xy_container_cls): with pytest.raises(AttributeError): xy_container_cls.attrs.x = Attr('x', default=100)
class D(C): y = Attr()
class E(D): z = Attr()
def test_repr(): x = Attr(name='x') assert repr(x) == "<Attr 'x'>"
def test_cannot_set_default_value_and_required_together(): with pytest.raises(ValueError): Attr(required=True, default=1)
def test_cannot_set_nonexistent_attribute_of_attr(): x = Attr() with pytest.raises(AttributeError): x.safe = True
class C: x = Attr()
class C: attrs_cls = CustomAttrs bound_attr_cls = CustomBoundAttr x = Attr()
class C: x = Attr('x') y = Attr('y') z = Attr('z', required=True)
class C: x = Attr() y = 10 # non-attr