예제 #1
0
    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
예제 #2
0
파일: test_all.py 프로젝트: jonike/wr-attrs
    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()
예제 #3
0
    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
예제 #4
0
    class C:
        @Attr.init_value
        def x(self, attr):
            attr.value = 5

        y = Attr()

        @y.init_value
        def y(self, attr):
            attr.value = 20
예제 #5
0
파일: test_all.py 프로젝트: jonike/wr-attrs
 class D(C):
     z = Attr()
예제 #6
0
파일: test_all.py 프로젝트: jonike/wr-attrs
 class C:
     x = Attr(safe=True)
예제 #7
0
파일: test_all.py 프로젝트: jonike/wr-attrs
 class C:
     x = Attr(safe=True, cli=True)
     y = Attr(cli='y')
예제 #8
0
파일: test_all.py 프로젝트: jonike/wr-attrs
    class C:
        x = Attr()

        @Attr
        def y(self, attr):
            return attr.value
예제 #9
0
파일: test_all.py 프로젝트: jonike/wr-attrs
 class C:
     w = Attr()
     x = Attr()
     y = Attr()
예제 #10
0
파일: test_all.py 프로젝트: jonike/wr-attrs
 class D(C):
     a = Attr()
     x = 5
     b = Attr()
예제 #11
0
def test_cannot_reset_attr_on_attrs(xy_container_cls):
    with pytest.raises(AttributeError):
        xy_container_cls.attrs.x = Attr('x', default=100)
예제 #12
0
파일: test_all.py 프로젝트: jonike/wr-attrs
 class D(C):
     y = Attr()
예제 #13
0
파일: test_all.py 프로젝트: jonike/wr-attrs
 class E(D):
     z = Attr()
예제 #14
0
def test_repr():
    x = Attr(name='x')
    assert repr(x) == "<Attr 'x'>"
예제 #15
0
def test_cannot_set_default_value_and_required_together():
    with pytest.raises(ValueError):
        Attr(required=True, default=1)
예제 #16
0
def test_cannot_set_nonexistent_attribute_of_attr():
    x = Attr()

    with pytest.raises(AttributeError):
        x.safe = True
예제 #17
0
파일: test_all.py 프로젝트: jonike/wr-attrs
 class C:
     x = Attr()
예제 #18
0
파일: test_all.py 프로젝트: jonike/wr-attrs
    class C:
        attrs_cls = CustomAttrs
        bound_attr_cls = CustomBoundAttr

        x = Attr()
예제 #19
0
파일: test_all.py 프로젝트: jonike/wr-attrs
 class C:
     x = Attr('x')
     y = Attr('y')
     z = Attr('z', required=True)
예제 #20
0
 class C:
     x = Attr()
     y = 10  # non-attr