def test_verifying_ok_bindings_passes(self): binding_mapping = bindings_lib.BindingMapping( {'a-binding-key': 'a-binding'}, {}) binding_mapping.verify_requirements([ required_bindings.RequiredBinding('a-binding-key', 'unused-require-loc') ])
def test_verifying_missing_required_binding_raises_error(self): binding_mapping = bindings_lib.BindingMapping({}, {}) self.assertRaises(errors.MissingRequiredBindingError, binding_mapping.verify_requirements, [ required_bindings.RequiredBinding( 'unknown-binding-key', 'a-require-loc') ])
def test_colliding_bindings_raises_error(self): binding_key = binding_keys.new('unused') binding_one = new_in_default_scope(binding_key) binding_two = new_in_default_scope(binding_key) binding_mapping = bindings_lib.BindingMapping( {}, {'colliding-binding-key': [binding_one, binding_two]}) self.assertRaises(errors.AmbiguousArgNameError, binding_mapping.get, 'colliding-binding-key', 'injection-site-desc')
def test_verifying_conflicting_required_binding_raises_error(self): binding_mapping = bindings_lib.BindingMapping( {}, {'conflicting-binding-key': ['a-binding', 'another-binding']}) self.assertRaises( errors.ConflictingRequiredBindingError, binding_mapping.verify_requirements, [ required_bindings.RequiredBinding('conflicting-binding-key', 'unused-require-loc') ])
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 test_unknown_binding_raises_error(self): binding_mapping = bindings_lib.BindingMapping( {'a-binding-key': 'a-binding'}, {}) self.assertRaises(errors.NothingInjectableForArgError, binding_mapping.get, 'unknown-binding-key', 'injection-site-desc')
def test_success(self): binding_mapping = bindings_lib.BindingMapping( {'a-binding-key': 'a-binding'}, {}) self.assertEqual( 'a-binding', binding_mapping.get('a-binding-key', 'injection-site-desc'))