Exemplo n.º 1
0
def test_send_simple():
    # Python code
    class A(object):
        def f(self):
            return self.x + 1
    obj = A()
    obj.x = 1
    assert obj.f() == 2

    class B(A):
        pass
    obj = B()
    obj.x = 1
    assert obj.f() == 2 # works on subclass too

    # Object model code
    def f(self):
        return self.read_attr("x") + 1
    A = Class("A", OBJECT, {"f": f}, TYPE)
    obj = Instance(A)
    obj.write_attr("x", 1)
    assert obj.send("f") == 2

    B = Class("B", A, {}, TYPE)
    obj = Instance(B)
    obj.write_attr("x", 2)
    assert obj.send("f") == 3
Exemplo n.º 2
0
def test_send_simple():
    # Python code
    class A(object):
        def f(self):
            return self.x + 1

    obj = A()
    obj.x = 1
    assert obj.f() == 2

    class B(A):
        pass

    obj = B()
    obj.x = 1
    assert obj.f() == 2  # works on subclass too

    # Object model code
    def f(self):
        return self.read_attr("x") + 1

    A = Class("A", OBJECT, {"f": f}, TYPE)
    obj = Instance(A)
    obj.write_attr("x", 1)
    assert obj.send("f") == 2

    B = Class("B", A, {}, TYPE)
    obj = Instance(B)
    obj.write_attr("x", 2)
    assert obj.send("f") == 3
Exemplo n.º 3
0
def test_send_subclassing_and_arguments():
    # Python code
    class A(object):
        def g(self, arg):
            return self.x + arg
    obj = A()
    obj.x = 1
    assert obj.g(4) == 5

    class B(A):
        def g(self, arg):
            return self.x + arg * 2
    obj = B()
    obj.x = 4
    assert obj.g(4) == 12

    # Object model code
    def g_A(self, arg):
        return self.read_attr("x") + arg
    A = Class("A", OBJECT, {"g": g_A}, TYPE)
    obj = Instance(A)
    obj.write_attr("x", 1)
    assert obj.send("g", 4) == 5

    def g_B(self, arg):
        return self.read_attr("x") + arg * 2
    B = Class("B", A, {"g": g_B}, TYPE)
    obj = Instance(B)
    obj.write_attr("x", 4)
    assert obj.send("g", 4) == 12
Exemplo n.º 4
0
def test_send_subclassing_and_arguments():
    # Python code
    class A(object):
        def g(self, arg):
            return self.x + arg

    obj = A()
    obj.x = 1
    assert obj.g(4) == 5

    class B(A):
        def g(self, arg):
            return self.x + arg * 2

    obj = B()
    obj.x = 4
    assert obj.g(4) == 12

    # Object model code
    def g_A(self, arg):
        return self.read_attr("x") + arg

    A = Class("A", OBJECT, {"g": g_A}, TYPE)
    obj = Instance(A)
    obj.write_attr("x", 1)
    assert obj.send("g", 4) == 5

    def g_B(self, arg):
        return self.read_attr("x") + arg * 2

    B = Class("B", A, {"g": g_B}, TYPE)
    obj = Instance(B)
    obj.write_attr("x", 4)
    assert obj.send("g", 4) == 12