Exemplo n.º 1
0
def test_using_object_method_mode():
    """Test using object_method mode."""
    m = Int()
    m.set_getattr_mode(GetAttr.ObjectMethod, "getter")

    class CustomGetAtom(Atom):
        val = m
        count = Int()

        def getter(self):
            self.count += 1
            return self.count

    a = CustomGetAtom()
    assert a.val == 1
    assert a.val == 2

    with pytest.raises(TypeError):
        m.set_getattr_mode(GetAttr.CallObject_Object, 1)
Exemplo n.º 2
0
def test_using_call_object_object_mode():
    """Test using call_object_object mode."""
    def getter(object):
        object.count += 1
        return object.count

    m = Int()
    m.set_getattr_mode(GetAttr.CallObject_Object, getter)

    class CustomGetAtom(Atom):
        val = m
        count = Int()

    a = CustomGetAtom()
    assert a.val == 1
    assert a.val == 2

    with pytest.raises(TypeError):
        m.set_getattr_mode(GetAttr.CallObject_Object, 1)
Exemplo n.º 3
0
def test_using_object_method_mode():
    """Test using object_method mode.

    """
    m = Int()
    m.set_getattr_mode(GetAttr.ObjectMethod, 'getter')

    class CustomGetAtom(Atom):
        val = m
        count = Int()

        def getter(self):
            self.count += 1
            return self.count

    a = CustomGetAtom()
    assert a.val == 1
    assert a.val == 2

    with pytest.raises(TypeError):
        m.set_getattr_mode(GetAttr.CallObject_Object, 1)
Exemplo n.º 4
0
def test_using_call_object_object_mode():
    """Test using call_object_object mode.

    """

    def getter(object):
        object.count += 1
        return object.count

    m = Int()
    m.set_getattr_mode(GetAttr.CallObject_Object, getter)

    class CustomGetAtom(Atom):
        val = m
        count = Int()

    a = CustomGetAtom()
    assert a.val == 1
    assert a.val == 2

    with pytest.raises(TypeError):
        m.set_getattr_mode(GetAttr.CallObject_Object, 1)