コード例 #1
0
 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'))
コード例 #2
0
 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'))
コード例 #3
0
 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'))
コード例 #4
0
 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'))
コード例 #5
0
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)
コード例 #6
0
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)
コード例 #7
0
 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)
コード例 #8
0
 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)
コード例 #9
0
ファイル: bindings_test.py プロジェクト: CarterTsai/pinject
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')
コード例 #10
0
ファイル: bindings_test.py プロジェクト: winstonewert/pinject
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')
コード例 #11
0
ファイル: scoping_test.py プロジェクト: google/pinject
 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))
コード例 #12
0
 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))