예제 #1
0
파일: test.py 프로젝트: uniite/pyirc
 def test_double_propagation(self):
     class MiddleMan(SimpleObservable):
         def __init__(self):
             self.children = ObservableList()
     # Create an observable list in an observable in an onbservable list
     parent = ObservableList()
     # Subscribe to the to-level list
     parent.subscribe("__all__", self.callback)
     # Add something to it
     middle_man = MiddleMan()
     parent.append(middle_man)
     # Ensure this tells us the item was added at index 0 of the top-level
     self.assertEqual((0, "add", middle_man), self.callback_result)
     # Add a few things to the inner list
     middle_man.children.append("hi!")
     middle_man.children.append("hello!")
     # Ensure we get told the string was added at parent[0].children[0]
     self.assertEqual(((0, "children", 1), "add", "hello!"), self.callback_result)
예제 #2
0
파일: test.py 프로젝트: uniite/pyirc
 def test_remove(self):
     # Create an observable dict
     observable_list = ObservableList("one", "of", "these", "things")
     # Subscribe to remove events
     subscription = observable_list.subscribe("remove", self.callback)
     # Remove an item from it
     del observable_list[2]
     # Ensure this triggered the callback
     self.assertEqual((2, "these"), self.callback_result)
예제 #3
0
파일: test.py 프로젝트: uniite/pyirc
 def test_change(self):
     # Create an observable dict
     observable_list = ObservableList("something", "might", "change")
     # Subscribe to change events
     subscription = observable_list.subscribe("change", self.callback)
     # Change an item in it
     observable_list[1] = "will"
     # Ensure this triggered the callback
     self.assertEqual((1, "will"), self.callback_result)
예제 #4
0
파일: test.py 프로젝트: uniite/pyirc
 def test_add(self):
     # Create an observable list
     observable_list = ObservableList()
     # Subscribe to add events
     subscription = observable_list.subscribe("add", self.callback)
     # Add an item to it
     observable_list.append("nom")
     # Ensure this triggered the callback
     self.assertEqual((0, "nom"), self.callback_result)
예제 #5
0
파일: test.py 프로젝트: uniite/pyirc
 def test_propagation(self):
     class Alerter(SimpleObservable):
         def alert(self):
             self._notify(None, "alert", "Alert!")
     # Create an observable list that contains other observables
     observable_list = ObservableList(Alerter(), Alerter())
     # Subscribe to all events
     subscription = observable_list.subscribe("__all__", self.callback)
     # Trigger an alert on something in the list
     observable_list[1].alert()
     # Ensure this triggered the callback
     self.assertEqual(((1, None), "alert", "Alert!"), self.callback_result)