def test_nill_matcher(self): vals = self.vals a1 = BlahModel() obs = MatchObserver() obs.set_model(a1) obs.register(lambda attr: False, self.on_foo) a1.meh__foo = 100 self.assertEqual(vals, []) a1.feh__gah = "coiso" self.assertEqual(vals, [])
def test_all_matcher(self): vals = self.vals a1 = BlahModel() obs = MatchObserver() obs.set_model(a1) obs.register(lambda attr: True, self.on_foo) a1.meh__foo = 100 self.assertEqual(vals, [("meh__foo", 100)]) a1.feh__gah = "coiso" self.assertEqual(vals, [("meh__foo", 100), ("feh__gah", "coiso")])
def test_glob(self): vals = self.vals a1 = BlahModel() obs = MatchObserver() obs.set_model(a1) obs.connect("*", self.on_foo) a1.meh__foo = 100 self.assertEqual(vals, [("meh__foo", 100)]) a1.feh__gah = "coiso" self.assertEqual(vals, [("meh__foo", 100), ("feh__gah", "coiso")])
def test_connection(self): vals = self.vals a1 = BlahModel() obs = MatchObserver() obs.set_model(a1) subs = obs.connect("*", self.on_foo) a1.meh__foo = 100 self.assertEqual(vals, [("meh__foo", 100)]) obs.unregister(subs) a1.feh__gah = "coiso" self.assertEqual(vals, [("meh__foo", 100)])
def test_registration(self): vals = self.vals a1 = BlahModel() obs = MatchObserver() obs.set_model(a1) subs = obs.register(lambda attr: True, self.on_foo) a1.meh__foo = 100 self.assertEqual(vals, [("meh__foo", 100)]) obs.unregister(subs) a1.feh__gah = "coiso" self.assertEqual(vals, [("meh__foo", 100)])