コード例 #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)
コード例 #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)
コード例 #3
0
ファイル: test_get_behaviors.py プロジェクト: nucleic/atom
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)
コード例 #4
0
ファイル: test_get_behaviors.py プロジェクト: nucleic/atom
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)