2016-11-04 17:13:21 +03:00
|
|
|
"""Dependency injector static providers unit tests."""
|
2016-04-03 17:27:53 +03:00
|
|
|
|
|
|
|
import unittest2 as unittest
|
|
|
|
|
2016-11-04 16:48:26 +03:00
|
|
|
from dependency_injector import providers
|
2016-05-18 01:17:39 +03:00
|
|
|
|
2016-04-03 17:27:53 +03:00
|
|
|
|
2016-05-17 21:28:22 +03:00
|
|
|
class ObjectProviderTests(unittest.TestCase):
|
2016-04-03 17:27:53 +03:00
|
|
|
|
|
|
|
def test_is_provider(self):
|
2016-11-04 16:48:26 +03:00
|
|
|
self.assertTrue(providers.is_provider(providers.Object(object())))
|
2016-04-03 17:27:53 +03:00
|
|
|
|
|
|
|
def test_call_object_provider(self):
|
|
|
|
obj = object()
|
|
|
|
self.assertIs(providers.Object(obj)(), obj)
|
|
|
|
|
|
|
|
def test_call_overridden_object_provider(self):
|
|
|
|
obj1 = object()
|
|
|
|
obj2 = object()
|
2016-05-17 21:28:22 +03:00
|
|
|
provider = providers.Object(obj1)
|
|
|
|
provider.override(providers.Object(obj2))
|
|
|
|
self.assertIs(provider(), obj2)
|
2016-04-03 17:27:53 +03:00
|
|
|
|
|
|
|
def test_repr(self):
|
|
|
|
some_object = object()
|
2016-05-17 21:28:22 +03:00
|
|
|
provider = providers.Object(some_object)
|
|
|
|
self.assertEqual(repr(provider),
|
|
|
|
'<dependency_injector.providers.base.'
|
2016-04-03 17:27:53 +03:00
|
|
|
'Object({0}) at {1}>'.format(
|
|
|
|
repr(some_object),
|
2016-05-17 21:28:22 +03:00
|
|
|
hex(id(provider))))
|