def test_pop_key_error(self): python_dict = {} with self.assertRaises(KeyError) as python_e: python_dict.pop("a") td = TraitDict() with self.assertRaises(KeyError) as trait_e: td.pop("a") self.assertEqual( str(trait_e.exception), str(python_e.exception), )
def test_pop(self): td = TraitDict({"a": 1, "b": 2}, key_validator=str_validator, value_validator=int_validator, notifiers=[self.notification_handler]) td.pop("b", "X") self.assertEqual(self.removed, {"b": 2}) self.removed = None res = td.pop("x", "X") # Ensure no notification is fired. self.assertIsNone(self.removed) self.assertEqual(res, "X")