mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Add some tests for catalog
This commit is contained in:
parent
654e7f05c8
commit
d93abe8554
51
tests/test_catalog.py
Normal file
51
tests/test_catalog.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
"""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)
|
Loading…
Reference in New Issue
Block a user