Beispiel #1
0
 def __init__(self):
     assert mandalka.is_node(self)
     super().__init__()
     Parent.b = 20
     self.__class__.c = 30
     self.d = 40
     self.override = lambda: 2
Beispiel #2
0
    def __init__(self, a=None, b=None):
        self.a, self.b = a, b


@node
class Another:
    def __init__(self, b=None, a=None):
        pass


class NotANode:
    def __init__(self, a=None, b=None):
        pass


assert is_node(Node())
assert not is_node(NotANode())

assert fails(lambda: Node(NotANode(1, 2), 3))
assert not fails(lambda: NotANode(Node(1, 2), 3))

assert fails(lambda: Node(Node(NotANode(1, 2), 3)))
assert not fails(lambda: Node(Node(Node(3, 4), Node(3))))

modify_args = [1, {2: [3, 4]}]

nodes = [
    Node(*modify_args),
    Node(123, b=[]),
    Node({
        "b": 1,
Beispiel #3
0
 def __enter__(self):
     assert mandalka.is_node(self)
     Resource.opened += 1
     return self
Beispiel #4
0
 def test(self):
     assert mandalka.is_node(self)
     self.increase()
     return [self.__class__.a, Child.b, Child.c, self.d]
Beispiel #5
0
 def __init__(self):
     assert mandalka.is_node(self)
     super().__init__()
Beispiel #6
0
 def increase(self):
     assert mandalka.is_node(self)
     Parent.a += 1
     self.__class__.b += 1
     self.__class__.c += 1
     self.d += 1
Beispiel #7
0
 def override(self):
     assert mandalka.is_node(self)
     return 1
Beispiel #8
0
 def __init__(self):
     assert mandalka.is_node(self)
     self.test_override = lambda: self.override()
Beispiel #9
0
        self.__class__.c += 1
        self.d += 1


@mandalka.node
class Child(Parent):
    def __init__(self):
        assert mandalka.is_node(self)
        super().__init__()

    def test(self):
        assert mandalka.is_node(self)
        self.increase()
        return [self.__class__.a, Child.b, Child.c, self.d]


class GrandChild(Child):
    pass


c = Child()
assert mandalka.is_node(c)
assert c.test() == [11, 21, 31, 41]
assert c.__class__.__name__ == "Child"

c = Child()
assert c.override() == 2
assert c.test_override() == 2

assert fails(lambda: GrandChild())