def test_get_child_successfully(self): other_binding_key = binding_keys.new('bar') new_injection_context = self.injection_context.get_child( _UNUSED_INJECTION_SITE_FN, bindings.new_binding_to_instance( other_binding_key, 'unused-instance', 'new-scope', lambda: 'unused-desc'))
def test_get_child_successfully(self): other_binding_key = binding_keys.new('bar') new_injection_context = self.injection_context.get_child( _UNUSED_INJECTION_SITE_FN, bindings.new_binding_to_instance(other_binding_key, 'unused-instance', 'new-scope', lambda: 'unused-desc'))
def test_get_child_raises_error_when_scope_not_usable(self): other_binding_key = binding_keys.new('bar') self.assertRaises( errors.BadDependencyScopeError, self.injection_context.get_child, _UNUSED_INJECTION_SITE_FN, bindings.new_binding_to_instance( other_binding_key, 'unused-instance', 'unusable-scope', lambda: 'unused-desc'))
def test_get_child_raises_error_when_scope_not_usable(self): other_binding_key = binding_keys.new('bar') self.assertRaises( errors.BadDependencyScopeError, self.injection_context.get_child, _UNUSED_INJECTION_SITE_FN, bindings.new_binding_to_instance(other_binding_key, 'unused-instance', 'unusable-scope', lambda: 'unused-desc'))
def new_obj_provider(arg_binding_key, instance, allow_injecting_none=True): binding_key = arg_binding_key.binding_key binding = bindings.new_binding_to_instance( binding_key, instance, 'a-scope', lambda: 'unused-desc') binding_mapping = bindings.BindingMapping({binding_key: binding}, {}) bindable_scopes = scoping.BindableScopes( {'a-scope': scoping.PrototypeScope()}) return object_providers.ObjectProvider( binding_mapping, bindable_scopes, allow_injecting_none)
def new_test_obj_provider(arg_binding_key, instance, allow_injecting_none=True): binding_key = arg_binding_key.binding_key binding = bindings.new_binding_to_instance( binding_key, instance, 'a-scope', lambda: 'unused-desc') binding_mapping = bindings.BindingMapping({binding_key: binding}, {}) bindable_scopes = scoping.BindableScopes( {'a-scope': scoping.PrototypeScope()}) return object_providers.ObjectProvider( binding_mapping, bindable_scopes, allow_injecting_none)
def setUp(self): self.binding_key = binding_keys.new('foo') self.binding = bindings.new_binding_to_instance( self.binding_key, 'an-instance', 'curr-scope', lambda: 'unused-desc') injection_context_factory = injection_contexts.InjectionContextFactory( lambda to_scope, from_scope: to_scope != 'unusable-scope') top_injection_context = injection_context_factory.new( _UNUSED_INJECTION_SITE_FN) self.injection_context = top_injection_context.get_child( _UNUSED_INJECTION_SITE_FN, self.binding)
def new_in_default_scope(binding_key): """Returns a new Binding in the default scope. Args: binding_key: a BindingKey proviser_fn: a function taking a InjectionContext and ObjectGraph and returning an instance of the bound value Returns: a Binding """ return bindings_lib.new_binding_to_instance( binding_key, 'unused', scoping.DEFAULT_SCOPE, get_binding_loc_fn=lambda: 'unknown')
def test_get_sub_scope_successfully(self): usable_binding = bindings.new_binding_to_instance( binding_keys.new('foo'), 'unused-instance', 'usable-scope-id', lambda: 'unused-desc') self.assertEqual( 'usable-scope', self.bindable_scopes.get_sub_scope(usable_binding))
def test_get_sub_scope_successfully(self): usable_binding = bindings.new_binding_to_instance( binding_keys.new('foo'), 'unused-instance', 'usable-scope-id', lambda: 'unused-desc') self.assertEqual('usable-scope', self.bindable_scopes.get_sub_scope(usable_binding))