mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-04 20:33:13 +03:00
Add tests for module and class for string ids
This commit is contained in:
parent
aec662a7b7
commit
1df2f60aa7
|
@ -19,8 +19,17 @@ from .container import Container
|
||||||
from .service import Service
|
from .service import Service
|
||||||
|
|
||||||
|
|
||||||
|
service = Provide['service']
|
||||||
|
service_provider = Provider['service']
|
||||||
|
undefined = Provide['undefined']
|
||||||
|
|
||||||
|
|
||||||
class TestClass:
|
class TestClass:
|
||||||
|
|
||||||
|
service = Provide['service']
|
||||||
|
service_provider = Provider['service']
|
||||||
|
undefined = Provide['undefined']
|
||||||
|
|
||||||
@inject
|
@inject
|
||||||
def __init__(self, service: Service = Provide['service']):
|
def __init__(self, service: Service = Provide['service']):
|
||||||
self.service = service
|
self.service = service
|
||||||
|
|
|
@ -4,7 +4,9 @@ import unittest
|
||||||
from dependency_injector.wiring import (
|
from dependency_injector.wiring import (
|
||||||
wire,
|
wire,
|
||||||
Provide,
|
Provide,
|
||||||
Closing)
|
Provider,
|
||||||
|
Closing,
|
||||||
|
)
|
||||||
from dependency_injector import errors
|
from dependency_injector import errors
|
||||||
|
|
||||||
# Runtime import to avoid syntax errors in samples on Python < 3.5
|
# Runtime import to avoid syntax errors in samples on Python < 3.5
|
||||||
|
@ -59,6 +61,11 @@ class WiringTest(unittest.TestCase):
|
||||||
service = test_function()
|
service = test_function()
|
||||||
self.assertIsInstance(service, Service)
|
self.assertIsInstance(service, Service)
|
||||||
|
|
||||||
|
def test_module_attributes_wiring(self):
|
||||||
|
self.assertIsInstance(module.service, Service)
|
||||||
|
self.assertIsInstance(module.service_provider(), Service)
|
||||||
|
self.assertIsInstance(module.undefined, Provide)
|
||||||
|
|
||||||
def test_class_wiring(self):
|
def test_class_wiring(self):
|
||||||
test_class_object = module.TestClass()
|
test_class_object = module.TestClass()
|
||||||
self.assertIsInstance(test_class_object.service, Service)
|
self.assertIsInstance(test_class_object.service, Service)
|
||||||
|
@ -92,6 +99,11 @@ class WiringTest(unittest.TestCase):
|
||||||
service = instance.static_method()
|
service = instance.static_method()
|
||||||
self.assertIsInstance(service, Service)
|
self.assertIsInstance(service, Service)
|
||||||
|
|
||||||
|
def test_class_attribute_wiring(self):
|
||||||
|
self.assertIsInstance(module.TestClass.service, Service)
|
||||||
|
self.assertIsInstance(module.TestClass.service_provider(), Service)
|
||||||
|
self.assertIsInstance(module.TestClass.undefined, Provide)
|
||||||
|
|
||||||
def test_function_wiring(self):
|
def test_function_wiring(self):
|
||||||
service = module.test_function()
|
service = module.test_function()
|
||||||
self.assertIsInstance(service, Service)
|
self.assertIsInstance(service, Service)
|
||||||
|
@ -210,6 +222,18 @@ class WiringTest(unittest.TestCase):
|
||||||
self.container.unwire()
|
self.container.unwire()
|
||||||
self.assertIsInstance(submodule.test_function(), Provide)
|
self.assertIsInstance(submodule.test_function(), Provide)
|
||||||
|
|
||||||
|
def test_unwire_module_attributes(self):
|
||||||
|
self.container.unwire()
|
||||||
|
self.assertIsInstance(module.service, Provide)
|
||||||
|
self.assertIsInstance(module.service_provider, Provider)
|
||||||
|
self.assertIsInstance(module.undefined, Provide)
|
||||||
|
|
||||||
|
def test_unwire_class_attributes(self):
|
||||||
|
self.container.unwire()
|
||||||
|
self.assertIsInstance(module.TestClass.service, Provide)
|
||||||
|
self.assertIsInstance(module.TestClass.service_provider, Provider)
|
||||||
|
self.assertIsInstance(module.TestClass.undefined, Provide)
|
||||||
|
|
||||||
def test_wire_multiple_containers(self):
|
def test_wire_multiple_containers(self):
|
||||||
sub_container = SubContainer()
|
sub_container = SubContainer()
|
||||||
sub_container.wire(
|
sub_container.wire(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user