mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Refactor tests imports
This commit is contained in:
parent
99b9a5648a
commit
3c0c3b3abc
|
@ -1,21 +1,24 @@
|
|||
"""Dependency injector catalogs unittests."""
|
||||
|
||||
import unittest2 as unittest
|
||||
import dependency_injector as di
|
||||
|
||||
from dependency_injector import catalogs
|
||||
from dependency_injector import providers
|
||||
from dependency_injector import errors
|
||||
|
||||
|
||||
class CatalogA(di.DeclarativeCatalog):
|
||||
class CatalogA(catalogs.DeclarativeCatalog):
|
||||
"""Test catalog A."""
|
||||
|
||||
p11 = di.Provider()
|
||||
p12 = di.Provider()
|
||||
p11 = providers.Provider()
|
||||
p12 = providers.Provider()
|
||||
|
||||
|
||||
class CatalogB(CatalogA):
|
||||
"""Test catalog B."""
|
||||
|
||||
p21 = di.Provider()
|
||||
p22 = di.Provider()
|
||||
p21 = providers.Provider()
|
||||
p22 = providers.Provider()
|
||||
|
||||
|
||||
class CatalogBundleTests(unittest.TestCase):
|
||||
|
@ -33,8 +36,8 @@ class CatalogBundleTests(unittest.TestCase):
|
|||
|
||||
def test_get_attr_not_from_bundle(self):
|
||||
"""Test get providers (attribute) that are not in bundle."""
|
||||
self.assertRaises(di.Error, getattr, self.bundle, 'p21')
|
||||
self.assertRaises(di.Error, getattr, self.bundle, 'p22')
|
||||
self.assertRaises(errors.Error, getattr, self.bundle, 'p21')
|
||||
self.assertRaises(errors.Error, getattr, self.bundle, 'p22')
|
||||
|
||||
def test_get_method_from_bundle(self):
|
||||
"""Test get providers (get() method) from bundle."""
|
||||
|
@ -43,8 +46,8 @@ class CatalogBundleTests(unittest.TestCase):
|
|||
|
||||
def test_get_method_not_from_bundle(self):
|
||||
"""Test get providers (get() method) that are not in bundle."""
|
||||
self.assertRaises(di.Error, self.bundle.get_provider, 'p21')
|
||||
self.assertRaises(di.Error, self.bundle.get_provider, 'p22')
|
||||
self.assertRaises(errors.Error, self.bundle.get_provider, 'p21')
|
||||
self.assertRaises(errors.Error, self.bundle.get_provider, 'p22')
|
||||
|
||||
def test_has(self):
|
||||
"""Test checks of providers availability in bundle."""
|
||||
|
@ -64,26 +67,26 @@ class CatalogBundleTests(unittest.TestCase):
|
|||
|
||||
def test_create_bundle_with_unbound_provider(self):
|
||||
"""Test that bundle is not created with unbound provider."""
|
||||
self.assertRaises(di.Error, CatalogB.Bundle, di.Provider())
|
||||
self.assertRaises(errors.Error, CatalogB.Bundle, providers.Provider())
|
||||
|
||||
def test_create_bundle_with_another_catalog_provider(self):
|
||||
"""Test that bundle can not contain another catalog's provider."""
|
||||
class TestCatalog(di.DeclarativeCatalog):
|
||||
class TestCatalog(catalogs.DeclarativeCatalog):
|
||||
"""Test catalog."""
|
||||
|
||||
provider = di.Provider()
|
||||
provider = providers.Provider()
|
||||
|
||||
self.assertRaises(di.Error,
|
||||
self.assertRaises(errors.Error,
|
||||
CatalogB.Bundle, CatalogB.p21, TestCatalog.provider)
|
||||
|
||||
def test_create_bundle_with_another_catalog_provider_with_same_name(self):
|
||||
"""Test that bundle can not contain another catalog's provider."""
|
||||
class TestCatalog(di.DeclarativeCatalog):
|
||||
class TestCatalog(catalogs.DeclarativeCatalog):
|
||||
"""Test catalog."""
|
||||
|
||||
p21 = di.Provider()
|
||||
p21 = providers.Provider()
|
||||
|
||||
self.assertRaises(di.Error,
|
||||
self.assertRaises(errors.Error,
|
||||
CatalogB.Bundle, CatalogB.p21, TestCatalog.p21)
|
||||
|
||||
def test_is_bundle_owner(self):
|
||||
|
@ -93,7 +96,7 @@ class CatalogBundleTests(unittest.TestCase):
|
|||
|
||||
def test_is_bundle_owner_with_not_bundle_instance(self):
|
||||
"""Test that check of bundle ownership raises error with not bundle."""
|
||||
self.assertRaises(di.Error, CatalogB.is_bundle_owner, object())
|
||||
self.assertRaises(errors.Error, CatalogB.is_bundle_owner, object())
|
||||
|
||||
|
||||
class DynamicCatalogTests(unittest.TestCase):
|
||||
|
@ -104,8 +107,8 @@ class DynamicCatalogTests(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""Set test environment up."""
|
||||
self.catalog = di.DynamicCatalog(p1=di.Provider(),
|
||||
p2=di.Provider())
|
||||
self.catalog = catalogs.DynamicCatalog(p1=providers.Provider(),
|
||||
p2=providers.Provider())
|
||||
self.catalog.name = 'TestCatalog'
|
||||
|
||||
def test_providers(self):
|
||||
|
@ -116,8 +119,8 @@ class DynamicCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_bind_provider(self):
|
||||
"""Test setting of provider via bind_provider() to catalog."""
|
||||
px = di.Provider()
|
||||
py = di.Provider()
|
||||
px = providers.Provider()
|
||||
py = providers.Provider()
|
||||
|
||||
self.catalog.bind_provider('px', px)
|
||||
self.catalog.bind_provider('py', py)
|
||||
|
@ -130,8 +133,8 @@ class DynamicCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_bind_providers(self):
|
||||
"""Test setting of provider via bind_providers() to catalog."""
|
||||
px = di.Provider()
|
||||
py = di.Provider()
|
||||
px = providers.Provider()
|
||||
py = providers.Provider()
|
||||
|
||||
self.catalog.bind_providers(dict(px=px, py=py))
|
||||
|
||||
|
@ -143,8 +146,8 @@ class DynamicCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_setattr(self):
|
||||
"""Test setting of providers via attributes to catalog."""
|
||||
px = di.Provider()
|
||||
py = di.Provider()
|
||||
px = providers.Provider()
|
||||
py = providers.Provider()
|
||||
|
||||
self.catalog.px = px
|
||||
self.catalog.py = py
|
||||
|
@ -157,13 +160,13 @@ class DynamicCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_unbind_provider(self):
|
||||
"""Test that catalog unbinds provider correct."""
|
||||
self.catalog.px = di.Provider()
|
||||
self.catalog.px = providers.Provider()
|
||||
self.catalog.unbind_provider('px')
|
||||
self.assertFalse(self.catalog.has_provider('px'))
|
||||
|
||||
def test_unbind_via_delattr(self):
|
||||
"""Test that catalog unbinds provider correct."""
|
||||
self.catalog.px = di.Provider()
|
||||
self.catalog.px = providers.Provider()
|
||||
del self.catalog.px
|
||||
self.assertFalse(self.catalog.has_provider('px'))
|
||||
|
||||
|
@ -181,8 +184,8 @@ class DynamicCatalogTests(unittest.TestCase):
|
|||
p1 = self.catalog.p1
|
||||
p2 = self.catalog.p2
|
||||
|
||||
catalog_a = di.DynamicCatalog(pa1=p1, pa2=p2)
|
||||
catalog_b = di.DynamicCatalog(pb1=p1, pb2=p2)
|
||||
catalog_a = catalogs.DynamicCatalog(pa1=p1, pa2=p2)
|
||||
catalog_b = catalogs.DynamicCatalog(pb1=p1, pb2=p2)
|
||||
|
||||
self.assertTrue(self.catalog.is_provider_bound(p1))
|
||||
self.assertTrue(catalog_a.is_provider_bound(p1))
|
||||
|
@ -200,13 +203,13 @@ class DynamicCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_provider_rebinding_to_the_same_catalog(self):
|
||||
"""Test provider rebinding to the same catalog."""
|
||||
with self.assertRaises(di.Error):
|
||||
with self.assertRaises(errors.Error):
|
||||
self.catalog.p3 = self.catalog.p1
|
||||
|
||||
def test_provider_binding_with_the_same_name(self):
|
||||
"""Test binding of provider with the same name."""
|
||||
with self.assertRaises(di.Error):
|
||||
self.catalog.bind_provider('p1', di.Provider())
|
||||
with self.assertRaises(errors.Error):
|
||||
self.catalog.bind_provider('p1', providers.Provider())
|
||||
|
||||
def test_get(self):
|
||||
"""Test getting of providers using get() method."""
|
||||
|
@ -215,10 +218,10 @@ class DynamicCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_get_undefined(self):
|
||||
"""Test getting of undefined providers using get() method."""
|
||||
with self.assertRaises(di.UndefinedProviderError):
|
||||
with self.assertRaises(errors.UndefinedProviderError):
|
||||
self.catalog.get_provider('undefined')
|
||||
|
||||
with self.assertRaises(di.UndefinedProviderError):
|
||||
with self.assertRaises(errors.UndefinedProviderError):
|
||||
self.catalog.undefined
|
||||
|
||||
def test_has_provider(self):
|
||||
|
@ -229,8 +232,8 @@ class DynamicCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_filter_all_providers_by_type(self):
|
||||
"""Test getting of all catalog providers of specific type."""
|
||||
self.assertTrue(len(self.catalog.filter(di.Provider)) == 2)
|
||||
self.assertTrue(len(self.catalog.filter(di.Value)) == 0)
|
||||
self.assertTrue(len(self.catalog.filter(providers.Provider)) == 2)
|
||||
self.assertTrue(len(self.catalog.filter(providers.Value)) == 0)
|
||||
|
||||
def test_repr(self):
|
||||
"""Test catalog representation."""
|
||||
|
@ -271,8 +274,8 @@ class DeclarativeCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_bind_provider(self):
|
||||
"""Test setting of provider via bind_provider() to catalog."""
|
||||
px = di.Provider()
|
||||
py = di.Provider()
|
||||
px = providers.Provider()
|
||||
py = providers.Provider()
|
||||
|
||||
CatalogA.bind_provider('px', px)
|
||||
CatalogA.bind_provider('py', py)
|
||||
|
@ -290,8 +293,8 @@ class DeclarativeCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_bind_providers(self):
|
||||
"""Test setting of provider via bind_providers() to catalog."""
|
||||
px = di.Provider()
|
||||
py = di.Provider()
|
||||
px = providers.Provider()
|
||||
py = providers.Provider()
|
||||
|
||||
CatalogB.bind_providers(dict(px=px, py=py))
|
||||
|
||||
|
@ -308,8 +311,8 @@ class DeclarativeCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_setattr(self):
|
||||
"""Test setting of providers via attributes to catalog."""
|
||||
px = di.Provider()
|
||||
py = di.Provider()
|
||||
px = providers.Provider()
|
||||
py = providers.Provider()
|
||||
|
||||
CatalogB.px = px
|
||||
CatalogB.py = py
|
||||
|
@ -327,13 +330,13 @@ class DeclarativeCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_unbind_provider(self):
|
||||
"""Test that catalog unbinds provider correct."""
|
||||
CatalogB.px = di.Provider()
|
||||
CatalogB.px = providers.Provider()
|
||||
CatalogB.unbind_provider('px')
|
||||
self.assertFalse(CatalogB.has_provider('px'))
|
||||
|
||||
def test_unbind_via_delattr(self):
|
||||
"""Test that catalog unbinds provider correct."""
|
||||
CatalogB.px = di.Provider()
|
||||
CatalogB.px = providers.Provider()
|
||||
del CatalogB.px
|
||||
self.assertFalse(CatalogB.has_provider('px'))
|
||||
|
||||
|
@ -350,13 +353,13 @@ class DeclarativeCatalogTests(unittest.TestCase):
|
|||
p11 = CatalogA.p11
|
||||
p12 = CatalogA.p12
|
||||
|
||||
class CatalogD(di.DeclarativeCatalog):
|
||||
class CatalogD(catalogs.DeclarativeCatalog):
|
||||
"""Test catalog."""
|
||||
|
||||
pd1 = p11
|
||||
pd2 = p12
|
||||
|
||||
class CatalogE(di.DeclarativeCatalog):
|
||||
class CatalogE(catalogs.DeclarativeCatalog):
|
||||
"""Test catalog."""
|
||||
|
||||
pe1 = p11
|
||||
|
@ -378,21 +381,21 @@ class DeclarativeCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_provider_rebinding_to_the_same_catalog(self):
|
||||
"""Test provider rebinding to the same catalog."""
|
||||
with self.assertRaises(di.Error):
|
||||
class TestCatalog(di.DeclarativeCatalog):
|
||||
with self.assertRaises(errors.Error):
|
||||
class TestCatalog(catalogs.DeclarativeCatalog):
|
||||
"""Test catalog."""
|
||||
|
||||
p1 = di.Provider()
|
||||
p1 = providers.Provider()
|
||||
p2 = p1
|
||||
|
||||
def test_provider_rebinding_to_the_same_catalogs_hierarchy(self):
|
||||
"""Test provider rebinding to the same catalogs hierarchy."""
|
||||
class TestCatalog1(di.DeclarativeCatalog):
|
||||
class TestCatalog1(catalogs.DeclarativeCatalog):
|
||||
"""Test catalog."""
|
||||
|
||||
p1 = di.Provider()
|
||||
p1 = providers.Provider()
|
||||
|
||||
with self.assertRaises(di.Error):
|
||||
with self.assertRaises(errors.Error):
|
||||
class TestCatalog2(TestCatalog1):
|
||||
"""Test catalog."""
|
||||
|
||||
|
@ -412,13 +415,13 @@ class DeclarativeCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_get_undefined(self):
|
||||
"""Test getting of undefined providers using get() method."""
|
||||
with self.assertRaises(di.UndefinedProviderError):
|
||||
with self.assertRaises(errors.UndefinedProviderError):
|
||||
CatalogB.get('undefined')
|
||||
|
||||
with self.assertRaises(di.UndefinedProviderError):
|
||||
with self.assertRaises(errors.UndefinedProviderError):
|
||||
CatalogB.get_provider('undefined')
|
||||
|
||||
with self.assertRaises(di.UndefinedProviderError):
|
||||
with self.assertRaises(errors.UndefinedProviderError):
|
||||
CatalogB.undefined
|
||||
|
||||
def test_has(self):
|
||||
|
@ -437,8 +440,8 @@ class DeclarativeCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_filter_all_providers_by_type(self):
|
||||
"""Test getting of all catalog providers of specific type."""
|
||||
self.assertTrue(len(CatalogB.filter(di.Provider)) == 4)
|
||||
self.assertTrue(len(CatalogB.filter(di.Value)) == 0)
|
||||
self.assertTrue(len(CatalogB.filter(providers.Provider)) == 4)
|
||||
self.assertTrue(len(CatalogB.filter(providers.Value)) == 0)
|
||||
|
||||
def test_repr(self):
|
||||
"""Test catalog representation."""
|
||||
|
@ -454,7 +457,7 @@ class DeclarativeCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_abstract_catalog_backward_compatibility(self):
|
||||
"""Test that di.AbstractCatalog is available."""
|
||||
self.assertIs(di.DeclarativeCatalog, di.AbstractCatalog)
|
||||
self.assertIs(catalogs.DeclarativeCatalog, catalogs.AbstractCatalog)
|
||||
|
||||
|
||||
class OverrideTests(unittest.TestCase):
|
||||
|
@ -466,12 +469,12 @@ class OverrideTests(unittest.TestCase):
|
|||
|
||||
def test_overriding(self):
|
||||
"""Test catalog overriding with another catalog."""
|
||||
@di.override(CatalogA)
|
||||
class OverridingCatalog(di.DeclarativeCatalog):
|
||||
@catalogs.override(CatalogA)
|
||||
class OverridingCatalog(catalogs.DeclarativeCatalog):
|
||||
"""Overriding catalog."""
|
||||
|
||||
p11 = di.Value(1)
|
||||
p12 = di.Value(2)
|
||||
p11 = providers.Value(1)
|
||||
p12 = providers.Value(2)
|
||||
|
||||
self.assertEqual(CatalogA.p11(), 1)
|
||||
self.assertEqual(CatalogA.p12(), 2)
|
||||
|
@ -479,8 +482,8 @@ class OverrideTests(unittest.TestCase):
|
|||
|
||||
def test_overriding_with_dynamic_catalog(self):
|
||||
"""Test catalog overriding with another dynamic catalog."""
|
||||
CatalogA.override(di.DynamicCatalog(p11=di.Value(1),
|
||||
p12=di.Value(2)))
|
||||
CatalogA.override(catalogs.DynamicCatalog(p11=providers.Value(1),
|
||||
p12=providers.Value(2)))
|
||||
self.assertEqual(CatalogA.p11(), 1)
|
||||
self.assertEqual(CatalogA.p12(), 2)
|
||||
self.assertEqual(len(CatalogA.overridden_by), 1)
|
||||
|
@ -489,44 +492,44 @@ class OverrideTests(unittest.TestCase):
|
|||
"""Test catalog is_overridden property."""
|
||||
self.assertFalse(CatalogA.is_overridden)
|
||||
|
||||
@di.override(CatalogA)
|
||||
class OverridingCatalog(di.DeclarativeCatalog):
|
||||
@catalogs.override(CatalogA)
|
||||
class OverridingCatalog(catalogs.DeclarativeCatalog):
|
||||
"""Overriding catalog."""
|
||||
|
||||
self.assertTrue(CatalogA.is_overridden)
|
||||
|
||||
def test_last_overriding(self):
|
||||
"""Test catalog last_overriding property."""
|
||||
@di.override(CatalogA)
|
||||
class OverridingCatalog1(di.DeclarativeCatalog):
|
||||
@catalogs.override(CatalogA)
|
||||
class OverridingCatalog1(catalogs.DeclarativeCatalog):
|
||||
"""Overriding catalog."""
|
||||
|
||||
@di.override(CatalogA)
|
||||
class OverridingCatalog2(di.DeclarativeCatalog):
|
||||
@catalogs.override(CatalogA)
|
||||
class OverridingCatalog2(catalogs.DeclarativeCatalog):
|
||||
"""Overriding catalog."""
|
||||
|
||||
self.assertIs(CatalogA.last_overriding, OverridingCatalog2)
|
||||
|
||||
def test_last_overriding_on_not_overridden(self):
|
||||
"""Test catalog last_overriding property on not overridden catalog."""
|
||||
with self.assertRaises(di.Error):
|
||||
with self.assertRaises(errors.Error):
|
||||
CatalogA.last_overriding
|
||||
|
||||
def test_reset_last_overriding(self):
|
||||
"""Test resetting last overriding catalog."""
|
||||
@di.override(CatalogA)
|
||||
class OverridingCatalog1(di.DeclarativeCatalog):
|
||||
@catalogs.override(CatalogA)
|
||||
class OverridingCatalog1(catalogs.DeclarativeCatalog):
|
||||
"""Overriding catalog."""
|
||||
|
||||
p11 = di.Value(1)
|
||||
p12 = di.Value(2)
|
||||
p11 = providers.Value(1)
|
||||
p12 = providers.Value(2)
|
||||
|
||||
@di.override(CatalogA)
|
||||
class OverridingCatalog2(di.DeclarativeCatalog):
|
||||
@catalogs.override(CatalogA)
|
||||
class OverridingCatalog2(catalogs.DeclarativeCatalog):
|
||||
"""Overriding catalog."""
|
||||
|
||||
p11 = di.Value(3)
|
||||
p12 = di.Value(4)
|
||||
p11 = providers.Value(3)
|
||||
p12 = providers.Value(4)
|
||||
|
||||
CatalogA.reset_last_overriding()
|
||||
|
||||
|
@ -535,24 +538,24 @@ class OverrideTests(unittest.TestCase):
|
|||
|
||||
def test_reset_last_overriding_when_not_overridden(self):
|
||||
"""Test resetting last overriding catalog when it is not overridden."""
|
||||
with self.assertRaises(di.Error):
|
||||
with self.assertRaises(errors.Error):
|
||||
CatalogA.reset_last_overriding()
|
||||
|
||||
def test_reset_override(self):
|
||||
"""Test resetting all catalog overrides."""
|
||||
@di.override(CatalogA)
|
||||
class OverridingCatalog1(di.DeclarativeCatalog):
|
||||
@catalogs.override(CatalogA)
|
||||
class OverridingCatalog1(catalogs.DeclarativeCatalog):
|
||||
"""Overriding catalog."""
|
||||
|
||||
p11 = di.Value(1)
|
||||
p12 = di.Value(2)
|
||||
p11 = providers.Value(1)
|
||||
p12 = providers.Value(2)
|
||||
|
||||
@di.override(CatalogA)
|
||||
class OverridingCatalog2(di.DeclarativeCatalog):
|
||||
@catalogs.override(CatalogA)
|
||||
class OverridingCatalog2(catalogs.DeclarativeCatalog):
|
||||
"""Overriding catalog."""
|
||||
|
||||
p11 = di.Value(3)
|
||||
p12 = di.Value(4)
|
||||
p11 = providers.Value(3)
|
||||
p12 = providers.Value(4)
|
||||
|
||||
CatalogA.reset_override()
|
||||
|
||||
|
|
13
tests/test_common.py
Normal file
13
tests/test_common.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
"""Common unittests."""
|
||||
|
||||
import unittest2 as unittest
|
||||
|
||||
from dependency_injector import VERSION
|
||||
|
||||
|
||||
class VersionTest(unittest.TestCase):
|
||||
"""Version constant tests."""
|
||||
|
||||
def test_version_follows_semantic_versioning(self):
|
||||
"""Test that version follows semantic versioning."""
|
||||
self.assertEquals(len(VERSION.split('.')), 3)
|
|
@ -1,7 +1,11 @@
|
|||
"""Dependency injector injections unittests."""
|
||||
|
||||
import unittest2 as unittest
|
||||
import dependency_injector as di
|
||||
|
||||
from dependency_injector import injections
|
||||
from dependency_injector import catalogs
|
||||
from dependency_injector import providers
|
||||
from dependency_injector import errors
|
||||
|
||||
|
||||
class InjectionTests(unittest.TestCase):
|
||||
|
@ -9,26 +13,27 @@ class InjectionTests(unittest.TestCase):
|
|||
|
||||
def test_init(self):
|
||||
"""Test Injection creation and initialization."""
|
||||
injection = di.Injection('some_value')
|
||||
injection = injections.Injection('some_value')
|
||||
self.assertEqual(injection.injectable, 'some_value')
|
||||
|
||||
def test_value_with_scalar_injectable(self):
|
||||
"""Test Injection value property with scalar value."""
|
||||
injection = di.Injection('some_value')
|
||||
injection = injections.Injection('some_value')
|
||||
self.assertEqual(injection.value, 'some_value')
|
||||
|
||||
def test_value_with_provider_injectable(self):
|
||||
"""Test Injection value property with provider."""
|
||||
injection = di.Injection(di.Factory(object))
|
||||
injection = injections.Injection(providers.Factory(object))
|
||||
self.assertIsInstance(injection.value, object)
|
||||
|
||||
def test_value_with_catalog_bundle_injectable(self):
|
||||
"""Test Injection value property with catalog bundle."""
|
||||
class TestCatalog(di.AbstractCatalog):
|
||||
class TestCatalog(catalogs.DeclarativeCatalog):
|
||||
"""Test catalog."""
|
||||
|
||||
provider = di.Provider()
|
||||
injection = di.Injection(TestCatalog.Bundle(TestCatalog.provider))
|
||||
provider = providers.Provider()
|
||||
injection = injections.Injection(
|
||||
TestCatalog.Bundle(TestCatalog.provider))
|
||||
|
||||
self.assertIsInstance(injection.value, TestCatalog.Bundle)
|
||||
|
||||
|
@ -38,7 +43,7 @@ class ArgTests(unittest.TestCase):
|
|||
|
||||
def test_init(self):
|
||||
"""Test Arg creation and initialization."""
|
||||
injection = di.Arg('some_value')
|
||||
injection = injections.Arg('some_value')
|
||||
self.assertEqual(injection.injectable, 'some_value')
|
||||
|
||||
|
||||
|
@ -47,7 +52,7 @@ class KwArgTests(unittest.TestCase):
|
|||
|
||||
def test_init(self):
|
||||
"""Test KwArg creation and initialization."""
|
||||
injection = di.KwArg('some_arg_name', 'some_value')
|
||||
injection = injections.KwArg('some_arg_name', 'some_value')
|
||||
self.assertEqual(injection.name, 'some_arg_name')
|
||||
self.assertEqual(injection.injectable, 'some_value')
|
||||
|
||||
|
@ -57,7 +62,7 @@ class AttributeTests(unittest.TestCase):
|
|||
|
||||
def test_init(self):
|
||||
"""Test Attribute creation and initialization."""
|
||||
injection = di.Attribute('some_arg_name', 'some_value')
|
||||
injection = injections.Attribute('some_arg_name', 'some_value')
|
||||
self.assertEqual(injection.name, 'some_arg_name')
|
||||
self.assertEqual(injection.injectable, 'some_value')
|
||||
|
||||
|
@ -67,7 +72,7 @@ class MethodTests(unittest.TestCase):
|
|||
|
||||
def test_init(self):
|
||||
"""Test Method creation and initialization."""
|
||||
injection = di.Method('some_arg_name', 'some_value')
|
||||
injection = injections.Method('some_arg_name', 'some_value')
|
||||
self.assertEqual(injection.name, 'some_arg_name')
|
||||
self.assertEqual(injection.injectable, 'some_value')
|
||||
|
||||
|
@ -77,10 +82,10 @@ class InjectTests(unittest.TestCase):
|
|||
|
||||
def test_decorated_args(self):
|
||||
"""Test `inject()` decoration with args."""
|
||||
provider1 = di.Factory(object)
|
||||
provider2 = di.Factory(list)
|
||||
provider1 = providers.Factory(object)
|
||||
provider2 = providers.Factory(list)
|
||||
|
||||
@di.inject(provider1, provider2)
|
||||
@injections.inject(provider1, provider2)
|
||||
def test(a, b):
|
||||
return a, b
|
||||
|
||||
|
@ -97,10 +102,11 @@ class InjectTests(unittest.TestCase):
|
|||
|
||||
def test_decorated_args_extended_syntax(self):
|
||||
"""Test `inject()` decoration with args."""
|
||||
provider1 = di.Factory(object)
|
||||
provider2 = di.Factory(list)
|
||||
provider1 = providers.Factory(object)
|
||||
provider2 = providers.Factory(list)
|
||||
|
||||
@di.inject(di.Arg(provider1), di.Arg(provider2))
|
||||
@injections.inject(injections.Arg(provider1),
|
||||
injections.Arg(provider2))
|
||||
def test(a, b):
|
||||
return a, b
|
||||
|
||||
|
@ -117,11 +123,11 @@ class InjectTests(unittest.TestCase):
|
|||
|
||||
def test_decorated_args_several_times(self):
|
||||
"""Test `inject()` decoration with args several times."""
|
||||
provider1 = di.Factory(object)
|
||||
provider2 = di.Factory(list)
|
||||
provider1 = providers.Factory(object)
|
||||
provider2 = providers.Factory(list)
|
||||
|
||||
@di.inject(provider2)
|
||||
@di.inject(provider1)
|
||||
@injections.inject(provider2)
|
||||
@injections.inject(provider1)
|
||||
def test(a, b):
|
||||
return a, b
|
||||
|
||||
|
@ -138,10 +144,10 @@ class InjectTests(unittest.TestCase):
|
|||
|
||||
def test_decorated_context_args(self):
|
||||
"""Test `inject()` decoration with context args."""
|
||||
provider1 = di.Factory(object)
|
||||
provider2 = di.Factory(list)
|
||||
provider1 = providers.Factory(object)
|
||||
provider2 = providers.Factory(list)
|
||||
|
||||
@di.inject(provider1)
|
||||
@injections.inject(provider1)
|
||||
def test(a, b):
|
||||
return a, b
|
||||
|
||||
|
@ -158,11 +164,11 @@ class InjectTests(unittest.TestCase):
|
|||
|
||||
def test_decorated_kwargs(self):
|
||||
"""Test `inject()` decoration with kwargs."""
|
||||
provider1 = di.Factory(object)
|
||||
provider2 = di.Factory(list)
|
||||
provider1 = providers.Factory(object)
|
||||
provider2 = providers.Factory(list)
|
||||
|
||||
@di.inject(a=provider1)
|
||||
@di.inject(b=provider2)
|
||||
@injections.inject(a=provider1)
|
||||
@injections.inject(b=provider2)
|
||||
def test(a, b):
|
||||
return a, b
|
||||
|
||||
|
@ -179,12 +185,12 @@ class InjectTests(unittest.TestCase):
|
|||
|
||||
def test_decorated_kwargs_priority(self):
|
||||
"""Test `inject()` decorated callback kwargs priority."""
|
||||
provider1 = di.Factory(object)
|
||||
provider2 = di.Factory(list)
|
||||
provider1 = providers.Factory(object)
|
||||
provider2 = providers.Factory(list)
|
||||
object_a = object()
|
||||
|
||||
@di.inject(a=provider1)
|
||||
@di.inject(b=provider2)
|
||||
@injections.inject(a=provider1)
|
||||
@injections.inject(b=provider2)
|
||||
def test(a, b):
|
||||
return a, b
|
||||
|
||||
|
@ -202,10 +208,10 @@ class InjectTests(unittest.TestCase):
|
|||
|
||||
def test_decorated_with_args(self):
|
||||
"""Test `inject()` decorated callback with args."""
|
||||
provider = di.Factory(list)
|
||||
provider = providers.Factory(list)
|
||||
object_a = object()
|
||||
|
||||
@di.inject(b=provider)
|
||||
@injections.inject(b=provider)
|
||||
def test(a, b):
|
||||
return a, b
|
||||
|
||||
|
@ -223,10 +229,10 @@ class InjectTests(unittest.TestCase):
|
|||
|
||||
def test_injection_kwarg_syntax(self):
|
||||
"""Test `inject()` decorated callback with "old" style using KwArg."""
|
||||
provider = di.Factory(list)
|
||||
provider = providers.Factory(list)
|
||||
object_a = object()
|
||||
|
||||
@di.inject(di.KwArg('b', provider))
|
||||
@injections.inject(injections.KwArg('b', provider))
|
||||
def test(a, b):
|
||||
return a, b
|
||||
|
||||
|
@ -247,8 +253,8 @@ class InjectTests(unittest.TestCase):
|
|||
class Test(object):
|
||||
"""Test class."""
|
||||
|
||||
@di.inject(arg1=123)
|
||||
@di.inject(arg2=456)
|
||||
@injections.inject(arg1=123)
|
||||
@injections.inject(arg2=456)
|
||||
def some_method(self, arg1, arg2):
|
||||
"""Some test method."""
|
||||
return arg1, arg2
|
||||
|
@ -261,8 +267,8 @@ class InjectTests(unittest.TestCase):
|
|||
|
||||
def test_decorate_class_with_init(self):
|
||||
"""Test `inject()` decorator that decorate class with __init__."""
|
||||
@di.inject(arg1=123)
|
||||
@di.inject(arg2=456)
|
||||
@injections.inject(arg1=123)
|
||||
@injections.inject(arg2=456)
|
||||
class Test(object):
|
||||
"""Test class."""
|
||||
|
||||
|
@ -278,7 +284,7 @@ class InjectTests(unittest.TestCase):
|
|||
|
||||
def test_decorate_class_without_init(self):
|
||||
"""Test `inject()` decorator that decorate class without __init__."""
|
||||
with self.assertRaises(di.Error):
|
||||
@di.inject(arg1=123)
|
||||
with self.assertRaises(errors.Error):
|
||||
@injections.inject(arg1=123)
|
||||
class Test(object):
|
||||
"""Test class."""
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
"""Dependency injector providers unittests."""
|
||||
|
||||
import unittest2 as unittest
|
||||
import dependency_injector as di
|
||||
|
||||
from dependency_injector import providers
|
||||
from dependency_injector import injections
|
||||
from dependency_injector import errors
|
||||
from dependency_injector import utils
|
||||
|
||||
|
||||
class Example(object):
|
||||
|
@ -35,11 +39,11 @@ class ProviderTests(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""Set test cases environment up."""
|
||||
self.provider = di.Provider()
|
||||
self.provider = providers.Provider()
|
||||
|
||||
def test_is_provider(self):
|
||||
"""Test `is_provider` check."""
|
||||
self.assertTrue(di.is_provider(self.provider))
|
||||
self.assertTrue(utils.is_provider(self.provider))
|
||||
|
||||
def test_call(self):
|
||||
"""Test call."""
|
||||
|
@ -49,34 +53,34 @@ class ProviderTests(unittest.TestCase):
|
|||
"""Test creating of provider delegation."""
|
||||
delegate1 = self.provider.delegate()
|
||||
|
||||
self.assertIsInstance(delegate1, di.Delegate)
|
||||
self.assertIsInstance(delegate1, providers.Delegate)
|
||||
self.assertIs(delegate1(), self.provider)
|
||||
|
||||
delegate2 = self.provider.delegate()
|
||||
|
||||
self.assertIsInstance(delegate2, di.Delegate)
|
||||
self.assertIsInstance(delegate2, providers.Delegate)
|
||||
self.assertIs(delegate2(), self.provider)
|
||||
|
||||
self.assertIsNot(delegate1, delegate2)
|
||||
|
||||
def test_override(self):
|
||||
"""Test provider overriding."""
|
||||
overriding_provider = di.Provider()
|
||||
overriding_provider = providers.Provider()
|
||||
self.provider.override(overriding_provider)
|
||||
self.assertTrue(self.provider.is_overridden)
|
||||
|
||||
def test_override_with_itself(self):
|
||||
"""Test provider overriding with itself."""
|
||||
self.assertRaises(di.Error, self.provider.override, self.provider)
|
||||
self.assertRaises(errors.Error, self.provider.override, self.provider)
|
||||
|
||||
def test_override_with_not_provider(self):
|
||||
"""Test provider overriding with not provider instance."""
|
||||
self.assertRaises(di.Error, self.provider.override, object())
|
||||
self.assertRaises(errors.Error, self.provider.override, object())
|
||||
|
||||
def test_last_overriding(self):
|
||||
"""Test getting last overriding provider."""
|
||||
overriding_provider1 = di.Provider()
|
||||
overriding_provider2 = di.Provider()
|
||||
overriding_provider1 = providers.Provider()
|
||||
overriding_provider2 = providers.Provider()
|
||||
|
||||
self.provider.override(overriding_provider1)
|
||||
self.assertIs(self.provider.last_overriding, overriding_provider1)
|
||||
|
@ -88,7 +92,7 @@ class ProviderTests(unittest.TestCase):
|
|||
"""Test getting last overriding from not overridden provider."""
|
||||
try:
|
||||
self.provider.last_overriding
|
||||
except di.Error:
|
||||
except errors.Error:
|
||||
pass
|
||||
else:
|
||||
self.fail('Got en error in {}'.format(
|
||||
|
@ -96,8 +100,8 @@ class ProviderTests(unittest.TestCase):
|
|||
|
||||
def test_reset_last_overriding(self):
|
||||
"""Test reseting of last overriding provider."""
|
||||
overriding_provider1 = di.Provider()
|
||||
overriding_provider2 = di.Provider()
|
||||
overriding_provider1 = providers.Provider()
|
||||
overriding_provider2 = providers.Provider()
|
||||
|
||||
self.provider.override(overriding_provider1)
|
||||
self.provider.override(overriding_provider2)
|
||||
|
@ -112,11 +116,11 @@ class ProviderTests(unittest.TestCase):
|
|||
|
||||
def test_reset_last_overriding_of_not_overridden_provider(self):
|
||||
"""Test resetting of last overriding on not overridden provier."""
|
||||
self.assertRaises(di.Error, self.provider.reset_last_overriding)
|
||||
self.assertRaises(errors.Error, self.provider.reset_last_overriding)
|
||||
|
||||
def test_reset_override(self):
|
||||
"""Test reset of provider's override."""
|
||||
overriding_provider = di.Provider()
|
||||
overriding_provider = providers.Provider()
|
||||
self.provider.override(overriding_provider)
|
||||
|
||||
self.assertTrue(self.provider.is_overridden)
|
||||
|
@ -127,7 +131,7 @@ class ProviderTests(unittest.TestCase):
|
|||
self.assertFalse(self.provider.is_overridden)
|
||||
try:
|
||||
self.provider.last_overriding
|
||||
except di.Error:
|
||||
except errors.Error:
|
||||
pass
|
||||
else:
|
||||
self.fail('Got en error in {}'.format(
|
||||
|
@ -139,16 +143,16 @@ class DelegateTests(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""Set test cases environment up."""
|
||||
self.delegated = di.Provider()
|
||||
self.delegate = di.Delegate(delegated=self.delegated)
|
||||
self.delegated = providers.Provider()
|
||||
self.delegate = providers.Delegate(delegated=self.delegated)
|
||||
|
||||
def test_is_provider(self):
|
||||
"""Test `is_provider` check."""
|
||||
self.assertTrue(di.is_provider(self.delegate))
|
||||
self.assertTrue(utils.is_provider(self.delegate))
|
||||
|
||||
def test_init_with_not_provider(self):
|
||||
"""Test that delegate accepts only another provider as delegated."""
|
||||
self.assertRaises(di.Error, di.Delegate, delegated=object())
|
||||
self.assertRaises(errors.Error, providers.Delegate, delegated=object())
|
||||
|
||||
def test_call(self):
|
||||
"""Test returning of delegated provider."""
|
||||
|
@ -164,19 +168,19 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
def test_is_provider(self):
|
||||
"""Test `is_provider` check."""
|
||||
self.assertTrue(di.is_provider(di.Factory(Example)))
|
||||
self.assertTrue(utils.is_provider(providers.Factory(Example)))
|
||||
|
||||
def test_init_with_callable(self):
|
||||
"""Test creation of provider with a callable."""
|
||||
self.assertTrue(di.Factory(credits))
|
||||
self.assertTrue(providers.Factory(credits))
|
||||
|
||||
def test_init_with_not_callable(self):
|
||||
"""Test creation of provider with not a callable."""
|
||||
self.assertRaises(di.Error, di.Factory, 123)
|
||||
self.assertRaises(errors.Error, providers.Factory, 123)
|
||||
|
||||
def test_call(self):
|
||||
"""Test creation of new instances."""
|
||||
provider = di.Factory(Example)
|
||||
provider = providers.Factory(Example)
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
||||
|
@ -189,7 +193,7 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
New simplified syntax.
|
||||
"""
|
||||
provider = di.Factory(Example, 'i1', 'i2')
|
||||
provider = providers.Factory(Example, 'i1', 'i2')
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -209,7 +213,7 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
New simplified syntax.
|
||||
"""
|
||||
provider = di.Factory(Example, init_arg1='i1', init_arg2='i2')
|
||||
provider = providers.Factory(Example, init_arg1='i1', init_arg2='i2')
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -229,7 +233,7 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
Simplified syntax of positional and keyword arg injections.
|
||||
"""
|
||||
provider = di.Factory(Example, 'i1', init_arg2='i2')
|
||||
provider = providers.Factory(Example, 'i1', init_arg2='i2')
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -249,9 +253,9 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
Extended syntax of positional and keyword arg injections.
|
||||
"""
|
||||
provider = di.Factory(Example,
|
||||
di.Arg('i1'),
|
||||
di.KwArg('init_arg2', 'i2'))
|
||||
provider = providers.Factory(Example,
|
||||
injections.Arg('i1'),
|
||||
injections.KwArg('init_arg2', 'i2'))
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -268,9 +272,9 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
def test_call_with_attributes(self):
|
||||
"""Test creation of new instances with attribute injections."""
|
||||
provider = di.Factory(Example,
|
||||
di.Attribute('attribute1', 'a1'),
|
||||
di.Attribute('attribute2', 'a2'))
|
||||
provider = providers.Factory(Example,
|
||||
injections.Attribute('attribute1', 'a1'),
|
||||
injections.Attribute('attribute2', 'a2'))
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -287,9 +291,9 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
def test_call_with_methods(self):
|
||||
"""Test creation of new instances with method injections."""
|
||||
provider = di.Factory(Example,
|
||||
di.Method('method1', 'm1'),
|
||||
di.Method('method2', 'm2'))
|
||||
provider = providers.Factory(Example,
|
||||
injections.Method('method1', 'm1'),
|
||||
injections.Method('method2', 'm2'))
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -306,7 +310,7 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
def test_call_with_context_args(self):
|
||||
"""Test creation of new instances with context args."""
|
||||
provider = di.Factory(Example, 11, 22)
|
||||
provider = providers.Factory(Example, 11, 22)
|
||||
instance = provider(33, 44)
|
||||
|
||||
self.assertEqual(instance.init_arg1, 11)
|
||||
|
@ -316,8 +320,8 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
def test_call_with_context_kwargs(self):
|
||||
"""Test creation of new instances with context kwargs."""
|
||||
provider = di.Factory(Example,
|
||||
di.KwArg('init_arg1', 1))
|
||||
provider = providers.Factory(Example,
|
||||
injections.KwArg('init_arg1', 1))
|
||||
|
||||
instance1 = provider(init_arg2=22)
|
||||
self.assertEqual(instance1.init_arg1, 1)
|
||||
|
@ -329,7 +333,7 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
def test_call_with_context_args_and_kwargs(self):
|
||||
"""Test creation of new instances with context args and kwargs."""
|
||||
provider = di.Factory(Example, 11)
|
||||
provider = providers.Factory(Example, 11)
|
||||
instance = provider(22, init_arg3=33, init_arg4=44)
|
||||
|
||||
self.assertEqual(instance.init_arg1, 11)
|
||||
|
@ -339,9 +343,9 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
def test_call_overridden(self):
|
||||
"""Test creation of new instances on overridden provider."""
|
||||
provider = di.Factory(Example)
|
||||
overriding_provider1 = di.Factory(dict)
|
||||
overriding_provider2 = di.Factory(list)
|
||||
provider = providers.Factory(Example)
|
||||
overriding_provider1 = providers.Factory(dict)
|
||||
overriding_provider2 = providers.Factory(list)
|
||||
|
||||
provider.override(overriding_provider1)
|
||||
provider.override(overriding_provider2)
|
||||
|
@ -355,17 +359,14 @@ class FactoryTests(unittest.TestCase):
|
|||
|
||||
def test_injections(self):
|
||||
"""Test getting a full list of injections using injections property."""
|
||||
provider = di.Factory(Example,
|
||||
di.Arg(1),
|
||||
di.KwArg('init_arg2', 2),
|
||||
di.Attribute('attribute1', 3),
|
||||
di.Attribute('attribute2', 4),
|
||||
di.Method('method1', 5),
|
||||
di.Method('method2', 6))
|
||||
|
||||
injections = provider.injections
|
||||
|
||||
self.assertEquals(len(injections), 6)
|
||||
provider = providers.Factory(Example,
|
||||
injections.Arg(1),
|
||||
injections.KwArg('init_arg2', 2),
|
||||
injections.Attribute('attribute1', 3),
|
||||
injections.Attribute('attribute2', 4),
|
||||
injections.Method('method1', 5),
|
||||
injections.Method('method2', 6))
|
||||
self.assertEquals(len(provider.injections), 6)
|
||||
|
||||
|
||||
class SingletonTests(unittest.TestCase):
|
||||
|
@ -373,19 +374,19 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
def test_is_provider(self):
|
||||
"""Test `is_provider` check."""
|
||||
self.assertTrue(di.is_provider(di.Singleton(Example)))
|
||||
self.assertTrue(utils.is_provider(providers.Singleton(Example)))
|
||||
|
||||
def test_init_with_callable(self):
|
||||
"""Test creation of provider with a callable."""
|
||||
self.assertTrue(di.Singleton(credits))
|
||||
self.assertTrue(providers.Singleton(credits))
|
||||
|
||||
def test_init_with_not_callable(self):
|
||||
"""Test creation of provider with not a callable."""
|
||||
self.assertRaises(di.Error, di.Singleton, 123)
|
||||
self.assertRaises(errors.Error, providers.Singleton, 123)
|
||||
|
||||
def test_call(self):
|
||||
"""Test getting of instances."""
|
||||
provider = di.Singleton(Example)
|
||||
provider = providers.Singleton(Example)
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
||||
|
@ -398,7 +399,7 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
New simplified syntax.
|
||||
"""
|
||||
provider = di.Singleton(Example, 'i1', 'i2')
|
||||
provider = providers.Singleton(Example, 'i1', 'i2')
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -418,7 +419,7 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
New simplified syntax.
|
||||
"""
|
||||
provider = di.Singleton(Example, init_arg1='i1', init_arg2='i2')
|
||||
provider = providers.Singleton(Example, init_arg1='i1', init_arg2='i2')
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -438,7 +439,7 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
Simplified syntax of positional and keyword arg injections.
|
||||
"""
|
||||
provider = di.Singleton(Example, 'i1', init_arg2='i2')
|
||||
provider = providers.Singleton(Example, 'i1', init_arg2='i2')
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -458,9 +459,9 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
Extended syntax of positional and keyword arg injections.
|
||||
"""
|
||||
provider = di.Singleton(Example,
|
||||
di.Arg('i1'),
|
||||
di.KwArg('init_arg2', 'i2'))
|
||||
provider = providers.Singleton(Example,
|
||||
injections.Arg('i1'),
|
||||
injections.KwArg('init_arg2', 'i2'))
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -477,9 +478,11 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
def test_call_with_attributes(self):
|
||||
"""Test getting of instances with attribute injections."""
|
||||
provider = di.Singleton(Example,
|
||||
di.Attribute('attribute1', 'a1'),
|
||||
di.Attribute('attribute2', 'a2'))
|
||||
provider = providers.Singleton(Example,
|
||||
injections.Attribute('attribute1',
|
||||
'a1'),
|
||||
injections.Attribute('attribute2',
|
||||
'a2'))
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -496,9 +499,9 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
def test_call_with_methods(self):
|
||||
"""Test getting of instances with method injections."""
|
||||
provider = di.Singleton(Example,
|
||||
di.Method('method1', 'm1'),
|
||||
di.Method('method2', 'm2'))
|
||||
provider = providers.Singleton(Example,
|
||||
injections.Method('method1', 'm1'),
|
||||
injections.Method('method2', 'm2'))
|
||||
|
||||
instance1 = provider()
|
||||
instance2 = provider()
|
||||
|
@ -515,7 +518,7 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
def test_call_with_context_args(self):
|
||||
"""Test getting of instances with context args."""
|
||||
provider = di.Singleton(Example)
|
||||
provider = providers.Singleton(Example)
|
||||
instance = provider(11, 22)
|
||||
|
||||
self.assertEqual(instance.init_arg1, 11)
|
||||
|
@ -523,8 +526,8 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
def test_call_with_context_kwargs(self):
|
||||
"""Test getting of instances with context kwargs."""
|
||||
provider = di.Singleton(Example,
|
||||
di.KwArg('init_arg1', 1))
|
||||
provider = providers.Singleton(Example,
|
||||
injections.KwArg('init_arg1', 1))
|
||||
|
||||
instance1 = provider(init_arg2=22)
|
||||
self.assertEqual(instance1.init_arg1, 1)
|
||||
|
@ -537,7 +540,7 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
def test_call_with_context_args_and_kwargs(self):
|
||||
"""Test getting of instances with context args and kwargs."""
|
||||
provider = di.Singleton(Example, 11)
|
||||
provider = providers.Singleton(Example, 11)
|
||||
instance = provider(22, init_arg3=33, init_arg4=44)
|
||||
|
||||
self.assertEqual(instance.init_arg1, 11)
|
||||
|
@ -547,9 +550,9 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
def test_call_overridden(self):
|
||||
"""Test getting of instances on overridden provider."""
|
||||
provider = di.Singleton(Example)
|
||||
overriding_provider1 = di.Singleton(dict)
|
||||
overriding_provider2 = di.Singleton(object)
|
||||
provider = providers.Singleton(Example)
|
||||
overriding_provider1 = providers.Singleton(dict)
|
||||
overriding_provider2 = providers.Singleton(object)
|
||||
|
||||
provider.override(overriding_provider1)
|
||||
provider.override(overriding_provider2)
|
||||
|
@ -563,21 +566,18 @@ class SingletonTests(unittest.TestCase):
|
|||
|
||||
def test_injections(self):
|
||||
"""Test getting a full list of injections using injections property."""
|
||||
provider = di.Singleton(Example,
|
||||
di.Arg(1),
|
||||
di.KwArg('init_arg2', 2),
|
||||
di.Attribute('attribute1', 3),
|
||||
di.Attribute('attribute2', 4),
|
||||
di.Method('method1', 5),
|
||||
di.Method('method2', 6))
|
||||
|
||||
injections = provider.injections
|
||||
|
||||
self.assertEquals(len(injections), 6)
|
||||
provider = providers.Singleton(Example,
|
||||
injections.Arg(1),
|
||||
injections.KwArg('init_arg2', 2),
|
||||
injections.Attribute('attribute1', 3),
|
||||
injections.Attribute('attribute2', 4),
|
||||
injections.Method('method1', 5),
|
||||
injections.Method('method2', 6))
|
||||
self.assertEquals(len(provider.injections), 6)
|
||||
|
||||
def test_reset(self):
|
||||
"""Test creation and reset of single object."""
|
||||
provider = di.Singleton(object)
|
||||
provider = providers.Singleton(object)
|
||||
|
||||
instance1 = provider()
|
||||
self.assertIsInstance(instance1, object)
|
||||
|
@ -595,29 +595,29 @@ class ExternalDependencyTests(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""Set test cases environment up."""
|
||||
self.provider = di.ExternalDependency(instance_of=list)
|
||||
self.provider = providers.ExternalDependency(instance_of=list)
|
||||
|
||||
def test_init_with_not_class(self):
|
||||
"""Test creation with not a class."""
|
||||
self.assertRaises(di.Error, di.ExternalDependency, object())
|
||||
self.assertRaises(errors.Error, providers.ExternalDependency, object())
|
||||
|
||||
def test_is_provider(self):
|
||||
"""Test `is_provider` check."""
|
||||
self.assertTrue(di.is_provider(self.provider))
|
||||
self.assertTrue(utils.is_provider(self.provider))
|
||||
|
||||
def test_call_overridden(self):
|
||||
"""Test call of overridden external dependency."""
|
||||
self.provider.provided_by(di.Factory(list))
|
||||
self.provider.provided_by(providers.Factory(list))
|
||||
self.assertIsInstance(self.provider(), list)
|
||||
|
||||
def test_call_overridden_but_not_instance_of(self):
|
||||
"""Test call of overridden external dependency, but not instance of."""
|
||||
self.provider.provided_by(di.Factory(dict))
|
||||
self.assertRaises(di.Error, self.provider)
|
||||
self.provider.provided_by(providers.Factory(dict))
|
||||
self.assertRaises(errors.Error, self.provider)
|
||||
|
||||
def test_call_not_overridden(self):
|
||||
"""Test call of not satisfied external dependency."""
|
||||
self.assertRaises(di.Error, self.provider)
|
||||
self.assertRaises(errors.Error, self.provider)
|
||||
|
||||
|
||||
class StaticProvidersTests(unittest.TestCase):
|
||||
|
@ -625,52 +625,52 @@ class StaticProvidersTests(unittest.TestCase):
|
|||
|
||||
def test_is_provider(self):
|
||||
"""Test `is_provider` check."""
|
||||
self.assertTrue(di.is_provider(di.Class(object)))
|
||||
self.assertTrue(di.is_provider(di.Object(object())))
|
||||
self.assertTrue(di.is_provider(di.Function(map)))
|
||||
self.assertTrue(di.is_provider(di.Value(123)))
|
||||
self.assertTrue(utils.is_provider(providers.Class(object)))
|
||||
self.assertTrue(utils.is_provider(providers.Object(object())))
|
||||
self.assertTrue(utils.is_provider(providers.Function(map)))
|
||||
self.assertTrue(utils.is_provider(providers.Value(123)))
|
||||
|
||||
def test_call_class_provider(self):
|
||||
"""Test Class provider call."""
|
||||
self.assertIs(di.Class(dict)(), dict)
|
||||
self.assertIs(providers.Class(dict)(), dict)
|
||||
|
||||
def test_call_object_provider(self):
|
||||
"""Test Object provider call."""
|
||||
obj = object()
|
||||
self.assertIs(di.Object(obj)(), obj)
|
||||
self.assertIs(providers.Object(obj)(), obj)
|
||||
|
||||
def test_call_function_provider(self):
|
||||
"""Test Function provider call."""
|
||||
self.assertIs(di.Function(map)(), map)
|
||||
self.assertIs(providers.Function(map)(), map)
|
||||
|
||||
def test_call_value_provider(self):
|
||||
"""Test Value provider call."""
|
||||
self.assertEqual(di.Value(123)(), 123)
|
||||
self.assertEqual(providers.Value(123)(), 123)
|
||||
|
||||
def test_call_overridden_class_provider(self):
|
||||
"""Test overridden Class provider call."""
|
||||
cls_provider = di.Class(dict)
|
||||
cls_provider.override(di.Object(list))
|
||||
cls_provider = providers.Class(dict)
|
||||
cls_provider.override(providers.Object(list))
|
||||
self.assertIs(cls_provider(), list)
|
||||
|
||||
def test_call_overridden_object_provider(self):
|
||||
"""Test overridden Object provider call."""
|
||||
obj1 = object()
|
||||
obj2 = object()
|
||||
obj_provider = di.Object(obj1)
|
||||
obj_provider.override(di.Object(obj2))
|
||||
obj_provider = providers.Object(obj1)
|
||||
obj_provider.override(providers.Object(obj2))
|
||||
self.assertIs(obj_provider(), obj2)
|
||||
|
||||
def test_call_overridden_function_provider(self):
|
||||
"""Test overridden Function provider call."""
|
||||
function_provider = di.Function(len)
|
||||
function_provider.override(di.Function(sum))
|
||||
function_provider = providers.Function(len)
|
||||
function_provider.override(providers.Function(sum))
|
||||
self.assertIs(function_provider(), sum)
|
||||
|
||||
def test_call_overridden_value_provider(self):
|
||||
"""Test overridden Value provider call."""
|
||||
value_provider = di.Value(123)
|
||||
value_provider.override(di.Value(321))
|
||||
value_provider = providers.Value(123)
|
||||
value_provider.override(providers.Value(321))
|
||||
self.assertEqual(value_provider(), 321)
|
||||
|
||||
|
||||
|
@ -683,15 +683,15 @@ class CallableTests(unittest.TestCase):
|
|||
|
||||
def test_init_with_callable(self):
|
||||
"""Test creation of provider with a callable."""
|
||||
self.assertTrue(di.Callable(self.example))
|
||||
self.assertTrue(providers.Callable(self.example))
|
||||
|
||||
def test_init_with_not_callable(self):
|
||||
"""Test creation of provider with not a callable."""
|
||||
self.assertRaises(di.Error, di.Callable, 123)
|
||||
self.assertRaises(errors.Error, providers.Callable, 123)
|
||||
|
||||
def test_call(self):
|
||||
"""Test call."""
|
||||
provider = di.Callable(lambda: True)
|
||||
provider = providers.Callable(lambda: True)
|
||||
self.assertTrue(provider())
|
||||
|
||||
def test_call_with_positional_args(self):
|
||||
|
@ -699,7 +699,7 @@ class CallableTests(unittest.TestCase):
|
|||
|
||||
New simplified syntax.
|
||||
"""
|
||||
provider = di.Callable(self.example, 1, 2, 3, 4)
|
||||
provider = providers.Callable(self.example, 1, 2, 3, 4)
|
||||
self.assertTupleEqual(provider(), (1, 2, 3, 4))
|
||||
|
||||
def test_call_with_keyword_args(self):
|
||||
|
@ -707,7 +707,11 @@ class CallableTests(unittest.TestCase):
|
|||
|
||||
New simplified syntax.
|
||||
"""
|
||||
provider = di.Callable(self.example, arg1=1, arg2=2, arg3=3, arg4=4)
|
||||
provider = providers.Callable(self.example,
|
||||
arg1=1,
|
||||
arg2=2,
|
||||
arg3=3,
|
||||
arg4=4)
|
||||
self.assertTupleEqual(provider(), (1, 2, 3, 4))
|
||||
|
||||
def test_call_with_positional_and_keyword_args(self):
|
||||
|
@ -715,7 +719,7 @@ class CallableTests(unittest.TestCase):
|
|||
|
||||
Simplified syntax of positional and keyword arg injections.
|
||||
"""
|
||||
provider = di.Callable(self.example, 1, 2, arg3=3, arg4=4)
|
||||
provider = providers.Callable(self.example, 1, 2, arg3=3, arg4=4)
|
||||
self.assertTupleEqual(provider(), (1, 2, 3, 4))
|
||||
|
||||
def test_call_with_positional_and_keyword_args_extended_syntax(self):
|
||||
|
@ -723,40 +727,40 @@ class CallableTests(unittest.TestCase):
|
|||
|
||||
Extended syntax of positional and keyword arg injections.
|
||||
"""
|
||||
provider = di.Callable(self.example,
|
||||
di.Arg(1),
|
||||
di.Arg(2),
|
||||
di.KwArg('arg3', 3),
|
||||
di.KwArg('arg4', 4))
|
||||
provider = providers.Callable(self.example,
|
||||
injections.Arg(1),
|
||||
injections.Arg(2),
|
||||
injections.KwArg('arg3', 3),
|
||||
injections.KwArg('arg4', 4))
|
||||
self.assertTupleEqual(provider(), (1, 2, 3, 4))
|
||||
|
||||
def test_call_with_context_args(self):
|
||||
"""Test call with context args."""
|
||||
provider = di.Callable(self.example, 1, 2)
|
||||
provider = providers.Callable(self.example, 1, 2)
|
||||
self.assertTupleEqual(provider(3, 4), (1, 2, 3, 4))
|
||||
|
||||
def test_call_with_context_kwargs(self):
|
||||
"""Test call with context kwargs."""
|
||||
provider = di.Callable(self.example,
|
||||
di.KwArg('arg1', 1))
|
||||
provider = providers.Callable(self.example,
|
||||
injections.KwArg('arg1', 1))
|
||||
self.assertTupleEqual(provider(arg2=2, arg3=3, arg4=4), (1, 2, 3, 4))
|
||||
|
||||
def test_call_with_context_args_and_kwargs(self):
|
||||
"""Test call with context args and kwargs."""
|
||||
provider = di.Callable(self.example, 1)
|
||||
provider = providers.Callable(self.example, 1)
|
||||
self.assertTupleEqual(provider(2, arg3=3, arg4=4), (1, 2, 3, 4))
|
||||
|
||||
def test_call_overridden(self):
|
||||
"""Test creation of new instances on overridden provider."""
|
||||
provider = di.Callable(self.example)
|
||||
provider.override(di.Value((4, 3, 2, 1)))
|
||||
provider.override(di.Value((1, 2, 3, 4)))
|
||||
provider = providers.Callable(self.example)
|
||||
provider.override(providers.Value((4, 3, 2, 1)))
|
||||
provider.override(providers.Value((1, 2, 3, 4)))
|
||||
|
||||
self.assertTupleEqual(provider(), (1, 2, 3, 4))
|
||||
|
||||
def test_injections(self):
|
||||
"""Test getting a full list of injections using injections property."""
|
||||
provider = di.Callable(self.example, 1, 2, arg3=3, arg4=4)
|
||||
provider = providers.Callable(self.example, 1, 2, arg3=3, arg4=4)
|
||||
self.assertEquals(len(provider.injections), 4)
|
||||
|
||||
|
||||
|
@ -767,15 +771,15 @@ class ConfigTests(unittest.TestCase):
|
|||
"""Set test cases environment up."""
|
||||
self.initial_data = dict(key='value',
|
||||
category=dict(setting='setting_value'))
|
||||
self.provider = di.Config(self.initial_data)
|
||||
self.provider = providers.Config(self.initial_data)
|
||||
|
||||
def test_is_provider(self):
|
||||
"""Test `is_provider` check."""
|
||||
self.assertTrue(di.is_provider(self.provider))
|
||||
self.assertTrue(utils.is_provider(self.provider))
|
||||
|
||||
def test_init_without_initial_value(self):
|
||||
"""Test provider's creation with no initial value."""
|
||||
self.assertEqual(di.Config()(), dict())
|
||||
self.assertEqual(providers.Config()(), dict())
|
||||
|
||||
def test_call(self):
|
||||
"""Test returning of config value."""
|
||||
|
@ -794,8 +798,8 @@ class ConfigTests(unittest.TestCase):
|
|||
category = self.provider.category
|
||||
category_setting = self.provider.category.setting
|
||||
|
||||
self.assertTrue(di.is_provider(category))
|
||||
self.assertTrue(di.is_provider(category_setting))
|
||||
self.assertTrue(utils.is_provider(category))
|
||||
self.assertTrue(utils.is_provider(category_setting))
|
||||
|
||||
self.assertEqual(category(), self.initial_data['category'])
|
||||
self.assertEqual(category_setting(),
|
||||
|
@ -803,12 +807,12 @@ class ConfigTests(unittest.TestCase):
|
|||
|
||||
def test_call_deferred_child_and_update_from(self):
|
||||
"""Test returning of deferred child config values."""
|
||||
self.provider = di.Config()
|
||||
self.provider = providers.Config()
|
||||
category = self.provider.category
|
||||
category_setting = self.provider.category.setting
|
||||
|
||||
self.assertTrue(di.is_provider(category))
|
||||
self.assertTrue(di.is_provider(category_setting))
|
||||
self.assertTrue(utils.is_provider(category))
|
||||
self.assertTrue(utils.is_provider(category_setting))
|
||||
|
||||
self.provider.update_from(self.initial_data)
|
||||
|
||||
|
@ -818,6 +822,6 @@ class ConfigTests(unittest.TestCase):
|
|||
|
||||
def test_call_deferred_child_with_empty_value(self):
|
||||
"""Test returning of deferred child config values."""
|
||||
self.provider = di.Config()
|
||||
self.provider = providers.Config()
|
||||
category_setting = self.provider.category.setting
|
||||
self.assertRaises(di.Error, category_setting)
|
||||
self.assertRaises(errors.Error, category_setting)
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
"""Dependency injector utils unittests."""
|
||||
|
||||
import unittest2 as unittest
|
||||
import dependency_injector as di
|
||||
|
||||
from dependency_injector import utils
|
||||
from dependency_injector import providers
|
||||
from dependency_injector import injections
|
||||
from dependency_injector import catalogs
|
||||
from dependency_injector import errors
|
||||
|
||||
|
||||
class IsProviderTests(unittest.TestCase):
|
||||
|
@ -9,26 +14,26 @@ class IsProviderTests(unittest.TestCase):
|
|||
|
||||
def test_with_instance(self):
|
||||
"""Test with instance."""
|
||||
self.assertTrue(di.is_provider(di.Provider()))
|
||||
self.assertTrue(utils.is_provider(providers.Provider()))
|
||||
|
||||
def test_with_class(self):
|
||||
"""Test with class."""
|
||||
self.assertFalse(di.is_provider(di.Provider))
|
||||
self.assertFalse(utils.is_provider(providers.Provider))
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertFalse(di.is_provider('some_string'))
|
||||
self.assertFalse(utils.is_provider('some_string'))
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertFalse(di.is_provider(object()))
|
||||
self.assertFalse(utils.is_provider(object()))
|
||||
|
||||
def test_with_subclass_instance(self):
|
||||
"""Test with subclass of provider instance."""
|
||||
class SomeProvider(di.Provider):
|
||||
class SomeProvider(providers.Provider):
|
||||
"""Some provider for test."""
|
||||
|
||||
self.assertTrue(di.is_provider(SomeProvider()))
|
||||
self.assertTrue(utils.is_provider(SomeProvider()))
|
||||
|
||||
def test_with_class_with_getattr(self):
|
||||
"""Test with class that has __getattr__() method implementation."""
|
||||
|
@ -39,7 +44,7 @@ class IsProviderTests(unittest.TestCase):
|
|||
"""Test implementation that just returns False."""
|
||||
return False
|
||||
|
||||
self.assertFalse(di.is_provider(SomeClass()))
|
||||
self.assertFalse(utils.is_provider(SomeClass()))
|
||||
|
||||
|
||||
class EnsureIsProviderTests(unittest.TestCase):
|
||||
|
@ -47,20 +52,24 @@ class EnsureIsProviderTests(unittest.TestCase):
|
|||
|
||||
def test_with_instance(self):
|
||||
"""Test with instance."""
|
||||
provider = di.Provider()
|
||||
self.assertIs(di.ensure_is_provider(provider), provider)
|
||||
provider = providers.Provider()
|
||||
self.assertIs(utils.ensure_is_provider(provider), provider)
|
||||
|
||||
def test_with_class(self):
|
||||
"""Test with class."""
|
||||
self.assertRaises(di.Error, di.ensure_is_provider, di.Provider)
|
||||
self.assertRaises(errors.Error,
|
||||
utils.ensure_is_provider,
|
||||
providers.Provider)
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertRaises(di.Error, di.ensure_is_provider, 'some_string')
|
||||
self.assertRaises(errors.Error,
|
||||
utils.ensure_is_provider,
|
||||
'some_string')
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertRaises(di.Error, di.ensure_is_provider, object())
|
||||
self.assertRaises(errors.Error, utils.ensure_is_provider, object())
|
||||
|
||||
|
||||
class IsInjectionTests(unittest.TestCase):
|
||||
|
@ -68,26 +77,29 @@ class IsInjectionTests(unittest.TestCase):
|
|||
|
||||
def test_with_instance(self):
|
||||
"""Test with instance."""
|
||||
self.assertTrue(di.is_injection(di.Injection('value')))
|
||||
self.assertTrue(utils.is_injection(injections.Injection('value')))
|
||||
|
||||
def test_with_subclass_instances(self):
|
||||
"""Test with subclass instances."""
|
||||
self.assertTrue(di.is_injection(di.Arg('value')))
|
||||
self.assertTrue(di.is_injection(di.KwArg('name', 'value')))
|
||||
self.assertTrue(di.is_injection(di.Attribute('name', 'value')))
|
||||
self.assertTrue(di.is_injection(di.Method('name', 'value')))
|
||||
self.assertTrue(utils.is_injection(injections.Arg('value')))
|
||||
self.assertTrue(utils.is_injection(injections.KwArg('name',
|
||||
'value')))
|
||||
self.assertTrue(utils.is_injection(injections.Attribute('name',
|
||||
'value')))
|
||||
self.assertTrue(utils.is_injection(injections.Method('name',
|
||||
'value')))
|
||||
|
||||
def test_with_class(self):
|
||||
"""Test with class."""
|
||||
self.assertFalse(di.is_injection(di.Injection))
|
||||
self.assertFalse(utils.is_injection(injections.Injection))
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertFalse(di.is_injection('some_string'))
|
||||
self.assertFalse(utils.is_injection('some_string'))
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertFalse(di.is_injection(object()))
|
||||
self.assertFalse(utils.is_injection(object()))
|
||||
|
||||
|
||||
class EnsureIsInjectionTests(unittest.TestCase):
|
||||
|
@ -95,20 +107,26 @@ class EnsureIsInjectionTests(unittest.TestCase):
|
|||
|
||||
def test_with_instance(self):
|
||||
"""Test with instance."""
|
||||
injection = di.Injection('value')
|
||||
self.assertIs(di.ensure_is_injection(injection), injection)
|
||||
injection = injections.Injection('value')
|
||||
self.assertIs(utils.ensure_is_injection(injection), injection)
|
||||
|
||||
def test_with_class(self):
|
||||
"""Test with class."""
|
||||
self.assertRaises(di.Error, di.ensure_is_injection, di.Injection)
|
||||
self.assertRaises(errors.Error,
|
||||
utils.ensure_is_injection,
|
||||
injections.Injection)
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertRaises(di.Error, di.ensure_is_injection, 'some_string')
|
||||
self.assertRaises(errors.Error,
|
||||
utils.ensure_is_injection,
|
||||
'some_string')
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertRaises(di.Error, di.ensure_is_injection, object())
|
||||
self.assertRaises(errors.Error,
|
||||
utils.ensure_is_injection,
|
||||
object())
|
||||
|
||||
|
||||
class IsArgInjectionTests(unittest.TestCase):
|
||||
|
@ -116,23 +134,23 @@ class IsArgInjectionTests(unittest.TestCase):
|
|||
|
||||
def test_with_instance(self):
|
||||
"""Test with instance."""
|
||||
self.assertTrue(di.is_arg_injection(di.Arg('value')))
|
||||
self.assertTrue(utils.is_arg_injection(injections.Arg('value')))
|
||||
|
||||
def test_with_class(self):
|
||||
"""Test with class."""
|
||||
self.assertFalse(di.is_arg_injection(di.Arg))
|
||||
self.assertFalse(utils.is_arg_injection(injections.Arg))
|
||||
|
||||
def test_with_parent_class(self):
|
||||
"""Test with parent class."""
|
||||
self.assertFalse(di.is_arg_injection(di.Injection))
|
||||
self.assertFalse(utils.is_arg_injection(injections.Injection))
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertFalse(di.is_arg_injection('some_string'))
|
||||
self.assertFalse(utils.is_arg_injection('some_string'))
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertFalse(di.is_arg_injection(object()))
|
||||
self.assertFalse(utils.is_arg_injection(object()))
|
||||
|
||||
|
||||
class IsKwArgInjectionTests(unittest.TestCase):
|
||||
|
@ -140,23 +158,24 @@ class IsKwArgInjectionTests(unittest.TestCase):
|
|||
|
||||
def test_with_instance(self):
|
||||
"""Test with instance."""
|
||||
self.assertTrue(di.is_kwarg_injection(di.KwArg('name', 'value')))
|
||||
self.assertTrue(utils.is_kwarg_injection(injections.KwArg('name',
|
||||
'value')))
|
||||
|
||||
def test_with_class(self):
|
||||
"""Test with class."""
|
||||
self.assertFalse(di.is_kwarg_injection(di.KwArg))
|
||||
self.assertFalse(utils.is_kwarg_injection(injections.KwArg))
|
||||
|
||||
def test_with_parent_class(self):
|
||||
"""Test with parent class."""
|
||||
self.assertFalse(di.is_kwarg_injection(di.Injection))
|
||||
self.assertFalse(utils.is_kwarg_injection(injections.Injection))
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertFalse(di.is_kwarg_injection('some_string'))
|
||||
self.assertFalse(utils.is_kwarg_injection('some_string'))
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertFalse(di.is_kwarg_injection(object()))
|
||||
self.assertFalse(utils.is_kwarg_injection(object()))
|
||||
|
||||
|
||||
class IsAttributeInjectionTests(unittest.TestCase):
|
||||
|
@ -164,24 +183,24 @@ class IsAttributeInjectionTests(unittest.TestCase):
|
|||
|
||||
def test_with_instance(self):
|
||||
"""Test with instance."""
|
||||
self.assertTrue(di.is_attribute_injection(di.Attribute('name',
|
||||
'value')))
|
||||
self.assertTrue(utils.is_attribute_injection(
|
||||
injections.Attribute('name', 'value')))
|
||||
|
||||
def test_with_class(self):
|
||||
"""Test with class."""
|
||||
self.assertFalse(di.is_attribute_injection(di.Attribute))
|
||||
self.assertFalse(utils.is_attribute_injection(injections.Attribute))
|
||||
|
||||
def test_with_parent_class(self):
|
||||
"""Test with parent class."""
|
||||
self.assertFalse(di.is_attribute_injection(di.Injection))
|
||||
self.assertFalse(utils.is_attribute_injection(injections.Injection))
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertFalse(di.is_attribute_injection('some_string'))
|
||||
self.assertFalse(utils.is_attribute_injection('some_string'))
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertFalse(di.is_attribute_injection(object()))
|
||||
self.assertFalse(utils.is_attribute_injection(object()))
|
||||
|
||||
|
||||
class IsMethodInjectionTests(unittest.TestCase):
|
||||
|
@ -189,23 +208,24 @@ class IsMethodInjectionTests(unittest.TestCase):
|
|||
|
||||
def test_with_instance(self):
|
||||
"""Test with instance."""
|
||||
self.assertTrue(di.is_method_injection(di.Method('name', 'value')))
|
||||
self.assertTrue(utils.is_method_injection(
|
||||
injections.Method('name', 'value')))
|
||||
|
||||
def test_with_class(self):
|
||||
"""Test with class."""
|
||||
self.assertFalse(di.is_method_injection(di.Method))
|
||||
self.assertFalse(utils.is_method_injection(injections.Method))
|
||||
|
||||
def test_with_parent_class(self):
|
||||
"""Test with parent class."""
|
||||
self.assertFalse(di.is_method_injection(di.Injection))
|
||||
self.assertFalse(utils.is_method_injection(injections.Injection))
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertFalse(di.is_method_injection('some_string'))
|
||||
self.assertFalse(utils.is_method_injection('some_string'))
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertFalse(di.is_method_injection(object()))
|
||||
self.assertFalse(utils.is_method_injection(object()))
|
||||
|
||||
|
||||
class IsCatalogTests(unittest.TestCase):
|
||||
|
@ -213,26 +233,26 @@ class IsCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_with_declarative_catalog(self):
|
||||
"""Test with class."""
|
||||
self.assertTrue(di.is_catalog(di.DeclarativeCatalog))
|
||||
self.assertTrue(utils.is_catalog(catalogs.DeclarativeCatalog))
|
||||
|
||||
def test_with_dynamic_catalog(self):
|
||||
"""Test with class."""
|
||||
self.assertTrue(di.is_catalog(di.DynamicCatalog()))
|
||||
self.assertTrue(utils.is_catalog(catalogs.DynamicCatalog()))
|
||||
|
||||
def test_with_child_class(self):
|
||||
"""Test with parent class."""
|
||||
class Catalog(di.AbstractCatalog):
|
||||
class Catalog(catalogs.DeclarativeCatalog):
|
||||
"""Example catalog child class."""
|
||||
|
||||
self.assertTrue(di.is_catalog(Catalog))
|
||||
self.assertTrue(utils.is_catalog(Catalog))
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertFalse(di.is_catalog('some_string'))
|
||||
self.assertFalse(utils.is_catalog('some_string'))
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertFalse(di.is_catalog(object()))
|
||||
self.assertFalse(utils.is_catalog(object()))
|
||||
|
||||
|
||||
class IsDynamicCatalogTests(unittest.TestCase):
|
||||
|
@ -240,11 +260,11 @@ class IsDynamicCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_with_declarative_catalog(self):
|
||||
"""Test with declarative catalog."""
|
||||
self.assertFalse(di.is_dynamic_catalog(di.DeclarativeCatalog))
|
||||
self.assertFalse(utils.is_dynamic_catalog(catalogs.DeclarativeCatalog))
|
||||
|
||||
def test_with_dynamic_catalog(self):
|
||||
"""Test with dynamic catalog."""
|
||||
self.assertTrue(di.is_dynamic_catalog(di.DynamicCatalog()))
|
||||
self.assertTrue(utils.is_dynamic_catalog(catalogs.DynamicCatalog()))
|
||||
|
||||
|
||||
class IsDeclarativeCatalogTests(unittest.TestCase):
|
||||
|
@ -252,11 +272,13 @@ class IsDeclarativeCatalogTests(unittest.TestCase):
|
|||
|
||||
def test_with_declarative_catalog(self):
|
||||
"""Test with declarative catalog."""
|
||||
self.assertTrue(di.is_declarative_catalog(di.DeclarativeCatalog))
|
||||
self.assertTrue(utils.is_declarative_catalog(
|
||||
catalogs.DeclarativeCatalog))
|
||||
|
||||
def test_with_dynamic_catalog(self):
|
||||
"""Test with dynamic catalog."""
|
||||
self.assertFalse(di.is_declarative_catalog(di.DynamicCatalog()))
|
||||
self.assertFalse(utils.is_declarative_catalog(
|
||||
catalogs.DynamicCatalog()))
|
||||
|
||||
|
||||
class IsCatalogBundleTests(unittest.TestCase):
|
||||
|
@ -264,19 +286,19 @@ class IsCatalogBundleTests(unittest.TestCase):
|
|||
|
||||
def test_with_instance(self):
|
||||
"""Test with instance."""
|
||||
self.assertTrue(di.is_catalog_bundle(di.CatalogBundle()))
|
||||
self.assertTrue(utils.is_catalog_bundle(catalogs.CatalogBundle()))
|
||||
|
||||
def test_with_cls(self):
|
||||
"""Test with class."""
|
||||
self.assertFalse(di.is_catalog_bundle(di.CatalogBundle))
|
||||
self.assertFalse(utils.is_catalog_bundle(catalogs.CatalogBundle))
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertFalse(di.is_catalog_bundle('some_string'))
|
||||
self.assertFalse(utils.is_catalog_bundle('some_string'))
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertFalse(di.is_catalog_bundle(object()))
|
||||
self.assertFalse(utils.is_catalog_bundle(object()))
|
||||
|
||||
|
||||
class EnsureIsCatalogBundleTests(unittest.TestCase):
|
||||
|
@ -284,18 +306,23 @@ class EnsureIsCatalogBundleTests(unittest.TestCase):
|
|||
|
||||
def test_with_instance(self):
|
||||
"""Test with instance."""
|
||||
bundle = di.CatalogBundle()
|
||||
self.assertIs(di.ensure_is_catalog_bundle(bundle), bundle)
|
||||
bundle = catalogs.CatalogBundle()
|
||||
self.assertIs(utils.ensure_is_catalog_bundle(bundle), bundle)
|
||||
|
||||
def test_with_class(self):
|
||||
"""Test with class."""
|
||||
self.assertRaises(di.Error, di.ensure_is_catalog_bundle,
|
||||
di.CatalogBundle)
|
||||
self.assertRaises(errors.Error,
|
||||
utils.ensure_is_catalog_bundle,
|
||||
catalogs.CatalogBundle)
|
||||
|
||||
def test_with_string(self):
|
||||
"""Test with string."""
|
||||
self.assertRaises(di.Error, di.ensure_is_catalog_bundle, 'some_string')
|
||||
self.assertRaises(errors.Error,
|
||||
utils.ensure_is_catalog_bundle,
|
||||
'some_string')
|
||||
|
||||
def test_with_object(self):
|
||||
"""Test with object."""
|
||||
self.assertRaises(di.Error, di.ensure_is_catalog_bundle, object())
|
||||
self.assertRaises(errors.Error,
|
||||
utils.ensure_is_catalog_bundle,
|
||||
object())
|
||||
|
|
Loading…
Reference in New Issue
Block a user