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 wrapped_f(*args, **kwargs): attempt = kwargs.pop('teb_retry_attempt', 0) try: return f(*args, **kwargs) except exc as e: if kwargsql.and_(e, **when): try: retry_after = kwargsql.get(e, delay) except: retry_after = default_retry else: if retry_after is not None: retry_after = int(retry_after) else: retry_after = default_retry countdown = retry_after + truncated_exponential_backoff( retry_after, attempt % max_collisions) raise Retry(kwargs=dict(attempt=attempt + 1), countdown=countdown) else: raise e, None, sys.exc_info()[2] # flake8: noqa.
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_get(self): self.assertEqual(kwargsql.get(self.d, 'nested__val'), 'nested-value')
def test_abc_mappings_navigation(self): d = dict(foo=CaseInsensitiveDict(bar=CaseInsensitiveDict(pika=42))) self.assertEqual(kwargsql.get(d, 'foo__bAr__PiKA'), 42)