示例#1
0
def test_function_property():
    class Ob:
        pass

    def set_foo(inst, val):
        inst.foo = val

    def get_foo(inst):
        return inst.foo

    prop = FunctionProperty("foobar", get_foo, set_foo)
    ob = Ob()
    prop.__set__(ob, "foobar")
    assert prop.__get__(ob, Ob) == "foobar"
def test_function_property():
    class Ob:
        pass

    def set_foo(inst, val):
        inst.foo = val

    def get_foo(inst):
        return inst.foo

    prop = FunctionProperty('foobar', get_foo, set_foo)
    ob = Ob()
    prop.__set__(ob, 'foobar')
    assert prop.__get__(ob, Ob) == 'foobar'
示例#3
0
class Following(AnnotationBehavior):
    __local__properties__ = ('favorite', )

    def get_favorite(self):
        user = get_authenticated_user_id()
        return user in (self.favorites or [])

    def set_favorite(self, value):
        pass

    favorite = FunctionProperty('favorite', get_favorite, set_favorite)