class TestMutableDict(BaseUnitTest): def setUp(self): self.standard = {'1': 1} self.mutable_dict = MutableDict() self.mutable_dict.update(self.standard) def test_pop_existing(self, m_changed): self.assertEqual(self.mutable_dict.pop('1'), self.standard.pop('1')) m_changed.assert_called_once_with() def test_pop_existing_with_default(self, m_changed): self.assertEqual(self.mutable_dict.pop('1', None), self.standard.pop('1', None)) m_changed.assert_called_once_with() def test_pop_not_existing(self, m_changed): self.assertRaises(KeyError, self.mutable_dict.pop, '2') self.assertFalse(m_changed.called) def test_pop_not_existing_with_default(self, m_changed): self.assertEqual(self.mutable_dict.pop('2', {}), self.standard.pop('2', {})) m_changed.assert_called_once_with() def test_popitem(self, m_changed): self.assertItemsEqual(self.mutable_dict.popitem(), self.standard.popitem()) m_changed.assert_called_once_with() m_changed.reset_mock() self.assertRaises(KeyError, self.mutable_dict.popitem) self.assertFalse(m_changed.called)
class TestMutableDictBase(TestMutableBase): def setUp(self): super(TestMutableDictBase, self).setUp() self.standard = {'1': 1} self.mutable_obj = MutableDict() self.mutable_obj.update(self.standard)