def __init__(self): assert mandalka.is_node(self) super().__init__() Parent.b = 20 self.__class__.c = 30 self.d = 40 self.override = lambda: 2
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,
def __enter__(self): assert mandalka.is_node(self) Resource.opened += 1 return self
def test(self): assert mandalka.is_node(self) self.increase() return [self.__class__.a, Child.b, Child.c, self.d]
def __init__(self): assert mandalka.is_node(self) super().__init__()
def increase(self): assert mandalka.is_node(self) Parent.a += 1 self.__class__.b += 1 self.__class__.c += 1 self.d += 1
def override(self): assert mandalka.is_node(self) return 1
def __init__(self): assert mandalka.is_node(self) self.test_override = lambda: self.override()
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())