def test___init__(self): """check WeakBoundMethod.__init__() """ self.assertTrue(self.w.fallback is _fallback_example) wf = weak_ref(self.f._flush) self.assertTrue(None is wf.fallback) return
def addObserver(self, callable): """ Add callable to the set of observers """ f = weak_ref(callable, holder=self._observers) self._observers.add(f) return
def removeObserver(self, callable): """ Remove callable from the set of observers """ f = weak_ref(callable) self._observers.remove(f) return
def hasObserver(self, callable): """ True if `callable` is present in the set of observers. """ f = weak_ref(callable) rv = f in self._observers return rv
def addObserver(self, callable): """ Add callable to the set of observers """ f = weak_ref(callable, fallback=_fbRemoveObserver) self._observers.add(f) return
def test___init__(self): """check WeakBoundMethod.__init__() """ # make sure there is no 'weak object has gone away' warning. wf = weak_ref(self.f._flush, holder=self.holder) del wf return
def test___eq__(self): """check WeakBoundMethod.__eq__() """ f1 = FitContribution('f1') w1 = weak_ref(f1._flush) w2 = weak_ref(f1._flush) self.assertEqual(w1, w2) w1c = pickle.loads(pickle.dumps(w1)) # pickle-copied objects should have empty reference self.assertTrue(None is w1c._wref()) self.assertNotEqual(w1, w1c) del f1 self.assertTrue(None is w1._wref()) self.assertEqual(w1, w1c) w1cc = pickle.loads(pickle.dumps(w1c)) self.assertTrue(None is w1cc._wref()) self.assertEqual(w1c, w1cc) self.assertEqual(w1, w1cc) return
def test___hash__(self): """check WeakBoundMethod.__hash__() """ f1 = FitContribution('f1') w1 = weak_ref(f1._flush) h0 = hash(w1) del f1 self.assertTrue(None is w1._wref()) self.assertEqual(h0, hash(w1)) w1c1 = pickle.loads(pickle.dumps(w1)) w1c2 = pickle.loads(pickle.dumps(w1)) self.assertEqual(hash(w1c1), hash(w1c2)) return
def test___call__(self): """check WeakBoundMethod.__call__() """ f = self.f self.assertEqual(7, f.evaluate()) self.assertEqual(7, f._eq._value) # verify f has the same effect as f._eq._flush self.w(()) self.assertTrue(None is f._eq._value) # check WeakBoundMethod behavior with no fallback x = Parameter('x', value=3) wgetx = weak_ref(x.getValue) self.assertEqual(3, wgetx()) del x self.assertRaises(ReferenceError, wgetx) return
def test___call__(self): """check WeakBoundMethod.__call__() """ f = self.f f.newParameter('x', 5) f.setEquation('3 * x') wx = weak_ref(f._eq._flush, holder=self.holder) self.holder.add(wx) self.assertEqual(15, f.evaluate()) self.assertEqual(15, f._eq._value) wx(()) self.assertTrue(None is f._eq._value) self.assertEqual(15, f.evaluate()) self.assertTrue(wx in self.holder) f.setEquation('2 * t') self.assertFalse(wx in self.holder) return
def setUp(self): self.f = FitContribution('f') self.holder = set() self.w = weak_ref(self.f._flush, holder=self.holder) self.holder.add(self.w) return
def setUp(self): self.f = FitContribution('f') self.f.setEquation('7') self.w = weak_ref(self.f._eq._flush, fallback=_fallback_example) return