def test_temporarily_replace_missing_keys(self): context = dict() func = binds(arg="param")(lambda param: param) wrapped = get_from_context(context, func) wrapped = temporarily_replace_context_keys(context, wrapped) assert_that(calling(wrapped), raises(KeyError))
def test_temporarily_replace_context_keys_wrong_order(self): context = dict(arg=123) func = binds(arg="param")(lambda param: param) wrapped = temporarily_replace_context_keys(context, func) wrapped = get_from_context(context, wrapped) assert_that(calling(wrapped), raises(ContextKeyNotFound))
def test_temporarily_replace_context_keys(self): context = dict(arg=123) func = binds(arg="param")(lambda param: param) wrapped = get_from_context(context, func) wrapped = temporarily_replace_context_keys(context, wrapped) assert_that(wrapped(), is_(123))
def test_chain_link_with_multiple_decorators(self): @extracts("param") class Extractor: def __call__(self): return 20 class Transformer: @extracts("res") def transform(self, arg): return arg * 10 chain = Chain( Extractor(), binds(param="arg")(Transformer().transform), lambda res: res, ) assert_that( chain(), is_(equal_to(200)), )