mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-12-01 14:04:01 +03:00
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
"""Objects catalog unittests."""
|
|
|
|
import unittest2 as unittest
|
|
|
|
from objects.catalog import AbstractCatalog
|
|
|
|
from objects.providers import Object
|
|
from objects.providers import Value
|
|
|
|
from objects.errors import Error
|
|
|
|
|
|
class CatalogTests(unittest.TestCase):
|
|
|
|
"""Catalog test cases."""
|
|
|
|
class Catalog(AbstractCatalog):
|
|
|
|
"""Test catalog."""
|
|
|
|
obj = Object(object())
|
|
another_obj = Object(object())
|
|
|
|
def test_get_used(self):
|
|
"""Test retrieving used provider."""
|
|
catalog = self.Catalog(self.Catalog.obj)
|
|
self.assertIsInstance(catalog.obj(), object)
|
|
|
|
def test_get_unused(self):
|
|
"""Test retrieving unused provider."""
|
|
catalog = self.Catalog()
|
|
self.assertRaises(Error, getattr, catalog, 'obj')
|
|
|
|
def test_all_providers(self):
|
|
"""Test getting of all catalog providers."""
|
|
all_providers = self.Catalog.all_providers()
|
|
all_providers_dict = dict(all_providers)
|
|
|
|
self.assertIsInstance(all_providers, set)
|
|
self.assertTrue(len(all_providers) == 2)
|
|
|
|
self.assertIn('obj', all_providers_dict)
|
|
self.assertIn(self.Catalog.obj, all_providers_dict.values())
|
|
|
|
self.assertIn('another_obj', all_providers_dict)
|
|
self.assertIn(self.Catalog.another_obj, all_providers_dict.values())
|
|
|
|
def test_all_providers_by_type(self):
|
|
"""Test getting of all catalog providers of specific type."""
|
|
self.assertTrue(len(self.Catalog.all_providers(Object)) == 2)
|
|
self.assertTrue(len(self.Catalog.all_providers(Value)) == 0)
|