2016-04-03 14:27:53 +00:00
|
|
|
"""Dependency injector static providers unittests."""
|
|
|
|
|
|
|
|
import unittest2 as unittest
|
|
|
|
|
2016-04-03 20:47:34 +00:00
|
|
|
from dependency_injector import (
|
|
|
|
providers,
|
|
|
|
utils,
|
|
|
|
)
|
2016-04-03 14:27:53 +00:00
|
|
|
|
2016-05-17 22:17:39 +00:00
|
|
|
# TODO: move to test_base
|
|
|
|
|
2016-04-03 14:27:53 +00:00
|
|
|
|
2016-05-17 18:28:22 +00:00
|
|
|
class ObjectProviderTests(unittest.TestCase):
|
|
|
|
"""Object provider tests."""
|
2016-04-03 14:27:53 +00:00
|
|
|
|
|
|
|
def test_is_provider(self):
|
|
|
|
"""Test `is_provider` check."""
|
|
|
|
self.assertTrue(utils.is_provider(providers.Object(object())))
|
|
|
|
|
|
|
|
def test_call_object_provider(self):
|
2016-05-17 18:28:22 +00:00
|
|
|
"""Test provider call."""
|
2016-04-03 14:27:53 +00:00
|
|
|
obj = object()
|
|
|
|
self.assertIs(providers.Object(obj)(), obj)
|
|
|
|
|
|
|
|
def test_call_overridden_object_provider(self):
|
2016-05-17 18:28:22 +00:00
|
|
|
"""Test overridden provider call."""
|
2016-04-03 14:27:53 +00:00
|
|
|
obj1 = object()
|
|
|
|
obj2 = object()
|
2016-05-17 18:28:22 +00:00
|
|
|
provider = providers.Object(obj1)
|
|
|
|
provider.override(providers.Object(obj2))
|
|
|
|
self.assertIs(provider(), obj2)
|
2016-04-03 14:27:53 +00:00
|
|
|
|
|
|
|
def test_repr(self):
|
|
|
|
"""Test representation of provider."""
|
|
|
|
some_object = object()
|
2016-05-17 18:28:22 +00:00
|
|
|
provider = providers.Object(some_object)
|
|
|
|
self.assertEqual(repr(provider),
|
|
|
|
'<dependency_injector.providers.base.'
|
2016-04-03 14:27:53 +00:00
|
|
|
'Object({0}) at {1}>'.format(
|
|
|
|
repr(some_object),
|
2016-05-17 18:28:22 +00:00
|
|
|
hex(id(provider))))
|