def test_object_1(self): c = C() observe.observe(c, self.listener) observe.scan() assert not self.listened c.x = 1 observe.scan() assert self.listened == (c, object, {"x" : 1}, {})
def test_object_2(self): c = C() observe.observe(c, self.listener) observe.scan() assert not self.listened c.x = 1 c.y = "e" observe.scan() assert self.listened == (c, object, {"x" : 1, "y" : "e"}, {})
def test_tree_2(self): c = C() c2 = C() c.l = (1, 2, c2) observe.observe_tree(c, self.listener) assert observe.isobserved(c) assert observe.isobserved(c2) c.l = 1 observe.scan() assert observe.isobserved(c) assert not observe.isobserved(c2) observe.unobserve_tree(c, self.listener) assert not observe.isobserved(c) assert not observe.isobserved(c2)
def test_tree_4(self): c = C() c2 = C() c.l = [] observe.observe_tree(c, self.listener) c.l.append(c2) observe.scan() assert observe.isobserved(c) assert observe.isobserved(c2) c.l.remove(c2) observe.scan() assert observe.isobserved(c) assert not observe.isobserved(c2) observe.unobserve_tree(c, self.listener) assert not observe.isobserved(c) assert not observe.isobserved(c2)
def test_list_1(self): c = [0] observe.observe(c, self.listener) observe.scan() assert not self.listened c.append(1) observe.scan() assert self.listened == (c, list, [0, 1], [0]) c.remove(0) observe.scan() assert self.listened == (c, list, [1], [0, 1])
def test_set_1(self): c = set([0]) observe.observe(c, self.listener) observe.scan() assert not self.listened c.add(1) observe.scan() assert self.listened == (c, set, set([0, 1]), set([0])) c.remove(0) observe.scan() assert self.listened == (c, set, set([1]), set([0, 1]))
def __init__(self, do_func, undo_func, name = "", stack = stack): _Operation.__init__(self, do_func, undo_func, name, stack) stack.undoables.append(self) if len(self.stack.undoables) > self.stack.limit: del self.stack.undoables[0] observe.scan()
def __init__(self, do_func, undo_func, name = "", stack = stack): _Operation.__init__(self, do_func, undo_func, name, stack) stack.redoables.append(self) observe.scan()