mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 01:26:51 +03:00
Add check for callable in providers.Callable.__init__
This commit is contained in:
parent
b1f6963fbe
commit
1736a6e008
|
@ -256,11 +256,13 @@ class Callable(Provider):
|
|||
with some predefined dependency injections.
|
||||
"""
|
||||
|
||||
__slots__ = ('calls', 'injections')
|
||||
__slots__ = ('callback', 'injections')
|
||||
|
||||
def __init__(self, calls, *injections):
|
||||
def __init__(self, callback, *injections):
|
||||
"""Initializer."""
|
||||
self.calls = calls
|
||||
if not callable(callback):
|
||||
raise Error('Callable expected, got {}'.format(str(callback)))
|
||||
self.callback = callback
|
||||
self.injections = tuple((injection
|
||||
for injection in injections
|
||||
if is_injection(injection)))
|
||||
|
@ -275,7 +277,7 @@ class Callable(Provider):
|
|||
for injection in self.injections))
|
||||
injections.update(kwargs)
|
||||
|
||||
return self.calls(*args, **injections)
|
||||
return self.callback(*args, **injections)
|
||||
|
||||
|
||||
class Config(Provider):
|
||||
|
|
|
@ -474,6 +474,10 @@ class CallableTests(unittest.TestCase):
|
|||
Injection('arg2', 'a2'),
|
||||
Injection('arg3', 'a3'))
|
||||
|
||||
def test_init_with_not_callable(self):
|
||||
"""Test creation of provider with not callable."""
|
||||
self.assertRaises(Error, Callable, 123)
|
||||
|
||||
def test_is_provider(self):
|
||||
"""Test `is_provider` check."""
|
||||
self.assertTrue(is_provider(Callable(map)))
|
||||
|
@ -505,3 +509,12 @@ class CallableTests(unittest.TestCase):
|
|||
|
||||
self.assertEqual(result1, (3, 2, 1))
|
||||
self.assertEqual(result2, (3, 2, 1))
|
||||
|
||||
|
||||
class ConfigTests(unittest.TestCase):
|
||||
|
||||
"""Config test cases."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set test cases environment up."""
|
||||
self.provider = Config()
|
||||
|
|
Loading…
Reference in New Issue
Block a user