def test_key_is_popped(self): obj_list = [ dict(compound_key_one=0, compound_key_two=0), dict(compound_key_one=0, compound_key_two=0) ] index_by_pop_keys(obj_list, ('compound_key_one', 'compound_key_two')) for obj in obj_list: self.assertNotIn('compound_key_one', obj) self.assertNotIn('compound_key_two', obj)
def test_key_latest_persists(self): obj_list = [ dict(compound_key_one=0, compound_key_two=0), dict(compound_key_one=0, compound_key_two=0), dict(compound_key_one=0, compound_key_two=0) ] index = index_by_pop_keys(obj_list, ('compound_key_one', 'compound_key_two')) self.assertIs(index[(0, 0)], obj_list[-1])
def test_key_found(self): obj_list = [ dict(compound_key_one=0, compound_key_two=0), dict(compound_key_one=0, compound_key_two=1), dict(compound_key_one=1, compound_key_two=0), dict(compound_key_one=1, compound_key_two=1) ] index = index_by_pop_keys(obj_list, ('compound_key_one', 'compound_key_two')) self.assertIs(index[(0, 0)], obj_list[0]) self.assertIs(index[(0, 1)], obj_list[1]) self.assertIs(index[(1, 0)], obj_list[2]) self.assertIs(index[(1, 1)], obj_list[3])
def test_key_not_found_partial(self): obj_list = [dict(compound_key_one=0, compound_key_two=0)] with self.assertRaises(KeyError): index_by_pop_keys(obj_list, ('compound_key_one', 'non_existing_key_two'))