mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-04 12:23:14 +03:00
Add tests for module and class
This commit is contained in:
parent
1d28e62a93
commit
aec662a7b7
|
@ -9,8 +9,15 @@ from .container import Container, SubContainer
|
||||||
from .service import Service
|
from .service import Service
|
||||||
|
|
||||||
|
|
||||||
|
service = Provide[Container.service]
|
||||||
|
service_provider = Provider[Container.service]
|
||||||
|
|
||||||
|
|
||||||
class TestClass:
|
class TestClass:
|
||||||
|
|
||||||
|
service = Provide[Container.service]
|
||||||
|
service_provider = Provider[Container.service]
|
||||||
|
|
||||||
@inject
|
@inject
|
||||||
def __init__(self, service: Service = Provide[Container.service]):
|
def __init__(self, service: Service = Provide[Container.service]):
|
||||||
self.service = service
|
self.service = service
|
||||||
|
|
|
@ -6,6 +6,7 @@ import unittest
|
||||||
from dependency_injector.wiring import (
|
from dependency_injector.wiring import (
|
||||||
wire,
|
wire,
|
||||||
Provide,
|
Provide,
|
||||||
|
Provider,
|
||||||
Closing,
|
Closing,
|
||||||
register_loader_containers,
|
register_loader_containers,
|
||||||
unregister_loader_containers,
|
unregister_loader_containers,
|
||||||
|
@ -64,6 +65,10 @@ 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)
|
||||||
|
|
||||||
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)
|
||||||
|
@ -97,6 +102,10 @@ 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)
|
||||||
|
|
||||||
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)
|
||||||
|
@ -215,6 +224,16 @@ 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)
|
||||||
|
|
||||||
|
def test_unwire_class_attributes(self):
|
||||||
|
self.container.unwire()
|
||||||
|
self.assertIsInstance(module.TestClass.service, Provide)
|
||||||
|
self.assertIsInstance(module.TestClass.service_provider, Provider)
|
||||||
|
|
||||||
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