def _search_in_dict(keys, dico, serie, with_kwargsql=False): for name in keys: if not with_kwargsql: value = dico.get(name) else: value = kwargsql.get(dico, name) if value is not None: serie.setdefault(name, []).append(value)
def test_abc_sequence_select(self): class DumbSequence(Sequence): def __len__(self): return 2 def __getitem__(self, key): return key + 1 self.assertEqual(kwargsql.get(DumbSequence(), '1'), 2)
def test_sequence_get(self): self.assertEquals(list(kwargsql.get(self.d, 'nestedl__any__foo')), [1, 2]) # nested elements that produce an error are discarded from the result. self.assertEquals(list(kwargsql.get(self.d, 'nestedl__any__bar')), [3]) self.assertEquals(list(kwargsql.get(self.d, 'nestedl__any__unknown')), []) # It makes not difference to call `any` or `each` is `kwargsql.get` # because it matters when there is an operation to perform on the # result data. self.assertEquals(list(kwargsql.get(self.d, 'nestedl__each__foo')), [1, 2]) self.assertEquals(list(kwargsql.get(self.d, 'nestedl__each__bar')), [3]) self.assertEquals(list(kwargsql.get(self.d, 'nestedl__any__unknown')), [])
def test_abc_mappings_navigation(self): d = dict(foo=CaseInsensitiveDict(bar=CaseInsensitiveDict(pika=42))) self.assertEqual(kwargsql.get(d, 'foo__bAr__PiKA'), 42)
def test_get(self): self.assertEqual(kwargsql.get(self.d, 'nested__val'), 'nested-value')