def testFunction(self): weak_set = WeakSet() def function(): "Never called" # Adding twice, having one. weak_set.add(function) weak_set.add(function) self.CustomAssertEqual(len(weak_set), 1) # Removing function weak_set.remove(function) assert len(weak_set) == 0
def testFunction(self): weak_set = WeakSet() def function(): 'Never called' # Adding twice, having one. weak_set.add(function) weak_set.add(function) self.CustomAssertEqual(len(weak_set), 1) # Removing function weak_set.remove(function) assert len(weak_set) == 0
def testRemove(self): weak_set = WeakSet() s1 = _Stub() self.CustomAssertEqual(len(weak_set), 0) # Trying remove, raises KeyError with pytest.raises(KeyError): weak_set.remove(s1) self.CustomAssertEqual(len(weak_set), 0) # Trying discard, no exception raised weak_set.discard(s1) self.CustomAssertEqual(len(weak_set), 0)
def testRemove(self): weak_set = WeakSet() s1 = _Stub() self.CustomAssertEqual(len(weak_set), 0) # Trying remove, raises KeyError with pytest.raises(KeyError): weak_set.remove(s1) self.CustomAssertEqual(len(weak_set), 0) # Trying discard, no exception raised weak_set.discard(s1) self.CustomAssertEqual(len(weak_set), 0)
def testWeakSet2(self): weak_set = WeakSet() # >>> Removing with DEL s1 = _Stub() weak_set.add(s1.Method) self.CustomAssertEqual(len(weak_set), 1) del s1 self.CustomAssertEqual(len(weak_set), 0) # >>> Removing with REMOVE s2 = _Stub() weak_set.add(s2.Method) self.CustomAssertEqual(len(weak_set), 1) weak_set.remove(s2.Method) self.CustomAssertEqual(len(weak_set), 0)
def testWeakSet2(self): weak_set = WeakSet() # >>> Removing with DEL s1 = _Stub() weak_set.add(s1.Method) self.CustomAssertEqual(len(weak_set), 1) del s1 self.CustomAssertEqual(len(weak_set), 0) # >>> Removing with REMOVE s2 = _Stub() weak_set.add(s2.Method) self.CustomAssertEqual(len(weak_set), 1) weak_set.remove(s2.Method) self.CustomAssertEqual(len(weak_set), 0)