diff --git a/objects/providers.py b/objects/providers.py index 093e6f6b..fdf9b880 100644 --- a/objects/providers.py +++ b/objects/providers.py @@ -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): diff --git a/tests/test_providers.py b/tests/test_providers.py index 1f7c7219..d74f2170 100644 --- a/tests/test_providers.py +++ b/tests/test_providers.py @@ -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()