def test_trait_set_notification_compat(self): events = [] def notifier(*args, **kwargs): event = set_event_factory(*args, **kwargs) events.append(event) trait_set = TraitSet( [1, 2, 3], notifiers=[notifier], ) # when trait_set.add(4) # then event, = events self.assertIs(event.object, trait_set) self.assertEqual(event.added, {4}) self.assertEqual(event.removed, set()) # when events.clear() trait_set.remove(4) # then event, = events self.assertEqual(event.added, set()) self.assertEqual(event.removed, {4})
def test_remove(self): ts = TraitSet({1, 2, 3}, item_validator=int_validator, notifiers=[self.notification_handler]) ts.remove(3) self.assertEqual(ts, {1, 2}) self.assertEqual(self.removed, {3}) self.assertEqual(self.added, set()) with self.assertRaises(KeyError): ts.remove(3)
def test_remove_iterable(self): iterable = (i for i in range(4)) ts = TraitSet() ts.add(iterable) self.assertIn(iterable, ts) # when ts.remove(iterable) # then self.assertEqual(ts, set())
def test_remove_does_not_call_validator(self): # Test validator should not be called with removed # items ts = TraitSet(item_validator=self.validator) ts.add("123") value, = ts # when self.validator_args = None ts.remove(value) # then # validator is not called. self.assertIsNone(self.validator_args)