Exemplo n.º 1
0
 def test_clear(self):
     observer = Observer()
     observer.clear()
     for obsclass in TestObserver.concreteObservables:
         obs1 = obsclass()
         observer.subscribeTo(obs1)
         obs2 = obsclass()
         observer.subscribeTo(obs2)
         observer.clear()
         self.assertEqual(set(observer.observed()), set())
Exemplo n.º 2
0
 def test_observed(self):
     observer = Observer()
     self.assertEqual(set(observer.observed()), set())
     for obsclass in TestObserver.concreteObservables:
         obs1 = obsclass()
         observer.subscribeTo(obs1)
         self.assertEqual(set(observer.observed()), {obs1})
         obs2 = obsclass()
         observer.subscribeTo(obs2)
         self.assertEqual(set(observer.observed()), {obs1, obs2})
         del obs1
         self.assertEqual(set(observer.observed()), {obs2})
         del obs2
         self.assertEqual(set(observer.observed()), set())
Exemplo n.º 3
0
 def test_subscribeTo(self):
     obs = Observer()
     self.assertRaises(TypeError, obs.subscribeTo, None)
     self.assertRaises(TypeError, obs.subscribeTo, "wrong")
     self.assertRaises(TypeError, obs.subscribeTo, Observer())
     del obs
     for obsclass in TestObserver.concreteObservables:
         observer = Observer()
         ref = weakref.ref(observer)
         obs1 = obsclass()
         ref1 = weakref.ref(obs1)
         self.assertTrue(observer.subscribeTo(obs1))
         self.assertFalse(observer.subscribeTo(obs1))
         obs2 = obsclass()
         self.assertTrue(observer.subscribeTo(obs2))
         del obs1
         self.assertIsNone(ref1())
         del observer
         self.assertIsNone(ref())
Exemplo n.º 4
0
 def test_unsubscribeFrom(self):
     observer = Observer()
     self.assertFalse(observer.unsubscribeFrom(None))
     self.assertFalse(observer.unsubscribeFrom("wrong"))
     self.assertFalse(observer.unsubscribeFrom(Observer()))
     for obsclass in TestObserver.concreteObservables:
         obs1 = obsclass()
         observer.subscribeTo(obs1)
         obs2 = obsclass()
         observer.subscribeTo(obs2)
         self.assertTrue(observer.unsubscribeFrom(obs1))
         self.assertFalse(observer.unsubscribeFrom(obs1))
         self.assertTrue(observer.unsubscribeFrom(obs2))
Exemplo n.º 5
0
 def test_creation_inf(self):
     obs = Observer(hz="inf")
     self.assertEqual(obs.hz(), float("inf"))
     ref = weakref.ref(obs)
     del obs
     self.assertIsNone(ref())
Exemplo n.º 6
0
 def test_creation_hz(self):
     obs = Observer(hz=60)
     self.assertEqual(obs.hz(), 60)
     ref = weakref.ref(obs)
     del obs
     self.assertIsNone(ref())
Exemplo n.º 7
0
 def test_creation_None(self):
     obs = Observer(hz=None)
     self.assertIsNone(obs.hz())
     ref = weakref.ref(obs)
     del obs
     self.assertIsNone(ref())