Exemple #1
0
def test_using_no_op_handler():
    """Test using the no_op handler."""
    v = Value()
    v.set_getattr_mode(GetAttr.NoOp, None)

    class CustomGetAtom(Atom):
        val = v

    a = CustomGetAtom()
    assert a.val is None
    a.val = 1
    assert a.val is None
Exemple #2
0
def test_using_no_op_handler():
    """Test using the no_op handler.

    """
    v = Value()
    v.set_getattr_mode(GetAttr.NoOp, None)

    class CustomGetAtom(Atom):
        val = v

    a = CustomGetAtom()
    assert a.val is None
    a.val = 1
    assert a.val is None
Exemple #3
0
def test_using_call_object_object_name_mode():
    """Test using call_object_object_name mode."""
    def getter(object, name):
        object.count += 1
        return object.count, name

    m = Value()
    m.set_getattr_mode(GetAttr.CallObject_ObjectName, getter)

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

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

    with pytest.raises(TypeError):
        m.set_getattr_mode(GetAttr.CallObject_ObjectName, 1)
Exemple #4
0
def test_using_object_method_name_mode():
    """Test using object_method mode."""
    m = Value()
    m.set_getattr_mode(GetAttr.ObjectMethod_Name, "getter")

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

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

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

    with pytest.raises(TypeError):
        m.set_getattr_mode(GetAttr.CallObject_Object, 1)
Exemple #5
0
def test_using_call_object_object_name_mode():
    """Test using call_object_object_name mode.

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

    m = Value()
    m.set_getattr_mode(GetAttr.CallObject_ObjectName, getter)

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

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

    with pytest.raises(TypeError):
        m.set_getattr_mode(GetAttr.CallObject_ObjectName, 1)
Exemple #6
0
def test_using_object_method_name_mode():
    """Test using object_method mode.

    """
    m = Value()
    m.set_getattr_mode(GetAttr.ObjectMethod_Name, 'getter')

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

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

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

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