def test_key_error_on_invalid_keys(self): """Test that trying to set a non-existing key will raise an error.""" record = Record(['name'], ['David']) with self.assertRaises(AttributeError): record.drink = 'Dr. Pepper' with self.assertRaises(KeyError): record['city'] = 'Hamburg'
def test_modification_tracking(self): """Test that record modifications are tracked.""" fake_modifications = {'drink': 'Dr. Pepper', 'city': 'New York'} record = Record(['name', 'drink', 'city'], ['David', 'Coffee', 'Hamburg']) record.name = 'David' # should not be flagged as it is the same value record.drink = 'Dr. Pepper' record.city = 'New York' self.assertEqual(fake_modifications, record.modifications())