<s> """<STR_LIT>""" <EOL> import inspect <EOL> import unittest <EOL> from pinject import arg_binding_keys <EOL> from pinject import binding_keys <EOL> from pinject import bindings <EOL> from pinject import decorators <EOL> from pinject import errors <EOL> from pinject import injection_contexts <EOL> from pinject import object_providers <EOL> from pinject import scoping <EOL> def new_test_obj_provider ( arg_binding_key , instance , allow_injecting_none = True ) : <EOL> binding_key = arg_binding_key . binding_key <EOL> binding = bindings . new_binding_to_instance ( <EOL> binding_key , instance , '<STR_LIT>' , lambda : '<STR_LIT>' ) <EOL> binding_mapping = bindings . BindingMapping ( { binding_key : binding } , { } ) <EOL> bindable_scopes = scoping . BindableScopes ( <EOL> { '<STR_LIT>' : scoping . PrototypeScope ( ) } ) <EOL> return object_providers . ObjectProvider ( <EOL> binding_mapping , bindable_scopes , allow_injecting_none ) <EOL> def new_injection_context ( ) : <EOL> return injection_contexts . InjectionContextFactory ( lambda _1 , _2 : True ) . new ( <EOL> lambda : None ) <EOL> _UNUSED_INJECTION_SITE_FN = lambda : None <EOL> class ObjectProviderTest ( unittest . TestCase ) : <EOL> def test_provides_from_arg_binding_key_successfully ( self ) : <EOL> arg_binding_key = arg_binding_keys . new ( '<STR_LIT>' ) <EOL> obj_provider = new_test_obj_provider ( arg_binding_key , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> obj_provider . provide_from_arg_binding_key ( <EOL> _UNUSED_INJECTION_SITE_FN , <EOL> arg_binding_key , new_injection_context ( ) ) ) <EOL> def test_provides_provider_fn_from_arg_binding_key_successfully ( self ) : <EOL> arg_binding_key = arg_binding_keys . new ( '<STR_LIT>' ) <EOL> obj_provider = new_test_obj_provider ( arg_binding_key , '<STR_LIT>' ) <EOL> provide_fn = obj_provider . provide_from_arg_binding_key ( <EOL> _UNUSED_INJECTION_SITE_FN , <EOL> arg_binding_key , new_injection_context ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , provide_fn ( ) ) <EOL> def test_can_provide_none_from_arg_binding_key_when_allowed ( self ) : <EOL> arg_binding_key = arg_binding_keys . new ( '<STR_LIT>' ) <EOL> obj_provider = new_test_obj_provider ( arg_binding_key , None ) <EOL> self . assertIsNone ( obj_provider . provide_from_arg_binding_key ( <EOL> _UNUSED_INJECTION_SITE_FN , <EOL> arg_binding_key , new_injection_context ( ) ) ) <EOL> def test_cannot_provide_none_from_binding_key_when_disallowed ( self ) : <EOL> arg_binding_key = arg_binding_keys . new ( '<STR_LIT>' ) <EOL> obj_provider = new_test_obj_provider ( arg_binding_key , None , <EOL> allow_injecting_none = False ) <EOL> self . assertRaises ( errors . InjectingNoneDisallowedError , <EOL> obj_provider . provide_from_arg_binding_key , <EOL> _UNUSED_INJECTION_SITE_FN , <EOL> arg_binding_key , new_injection_context ( ) ) <EOL> def test_provides_class_with_init_as_method_injects_args_successfully ( self ) : <EOL> class Foo ( object ) : <EOL> def __init__ ( self , bar ) : <EOL> self . bar = bar <EOL> arg_binding_key = arg_binding_keys . new ( '<STR_LIT:bar>' ) <EOL> obj_provider = new_test_obj_provider ( arg_binding_key , '<STR_LIT>' ) <EOL> foo = obj_provider . provide_class ( Foo , new_injection_context ( ) , [ ] , { } ) <EOL> self . assertEqual ( '<STR_LIT>' , foo . bar ) <EOL> def test_provides_class_with_direct_pargs_and_kwargs ( self ) : <EOL> class SomeClass ( object ) : <EOL> @ decorators . inject ( [ '<STR_LIT>' ] ) <EOL> def __init__ ( self , foo , bar , baz ) : <EOL> self . foobarbaz = foo + bar + baz <EOL> obj_provider = new_test_obj_provider ( arg_binding_keys . new ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> some_class = obj_provider . provide_class ( <EOL> SomeClass , new_injection_context ( ) , [ '<STR_LIT:foo>' ] , { '<STR_LIT:bar>' : '<STR_LIT:bar>' } ) <EOL> self . assertEqual ( '<STR_LIT>' , some_class . foobarbaz ) <EOL> def test_provides_class_with_init_as_method_wrapper_successfully ( self ) : <EOL> class Foo ( object ) : <EOL> pass <EOL> arg_binding_key = arg_binding_keys . new ( '<STR_LIT>' ) <EOL> obj_provider = new_test_obj_provider ( arg_binding_key , '<STR_LIT>' ) <EOL> self . assertIsInstance ( <EOL> obj_provider . provide_class ( Foo , new_injection_context ( ) , [ ] , { } ) , <EOL> Foo ) <EOL> def test_calls_with_injection_successfully ( self ) : <EOL> def foo ( bar ) : <EOL> return '<STR_LIT>' + bar <EOL> arg_binding_key = arg_binding_keys . new ( '<STR_LIT:bar>' ) <EOL> obj_provider = new_test_obj_provider ( arg_binding_key , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> obj_provider . call_with_injection ( <EOL> foo , new_injection_context ( ) , [ ] , { } ) ) <EOL> def test_gets_injection_kwargs_successfully ( self ) : <EOL> def foo ( bar ) : <EOL> pass <EOL> arg_binding_key = arg_binding_keys . new ( '<STR_LIT:bar>' ) <EOL> obj_provider = new_test_obj_provider ( arg_binding_key , '<STR_LIT>' ) <EOL> pargs , kwargs = obj_provider . get_injection_pargs_kwargs ( <EOL> foo , new_injection_context ( ) , [ ] , { } ) <EOL> self . assertEqual ( [ ] , pargs ) <EOL> self . assertEqual ( { '<STR_LIT:bar>' : '<STR_LIT>' } , kwargs ) </s>
