def _tmp(self, attr, klass_value, cleanup_method): if hasattr(klass_value, '__call__'): klass_value = klass_value(self) instance_value = self._init_kwargs.get(attr,None) val = None if attr in kls.ADDITIVE_ATTRS: val = merge({}, getattr(self.fallthrough,attr,{}), klass_value, instance_value) elif attr in kls.TRUTHY_ATTRS: val = instance_value or klass_value or getattr(self.fallthrough,attr,None) else: if instance_value is not None: val=instance_value elif klass_value is not None: val=klass_value else: val = getattr(self.fallthrough,attr,None) return cleanup_method(val)
def _test_additive_attr(self, attr, possibles, add_none=True): if add_none: possibles = [None] + list(possibles) for k in possibles: for l in (True,False): for m in possibles: for n in possibles: class TestExchangeX(TestExchange): pass auth = Auth() setattr(auth,attr,n) if l: if k is not None: setattr(TestExchangeX, attr, k) else: if k is not None: setattr(TestExchangeX, attr, lambda self: k) ex = TestExchangeX(auth, **{attr:m}) self.assertEquals( merge({}, n or {}, k or {}, m or {}), getattr(ex, attr))