mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
Merge branch 'release/4.0.6' into master
This commit is contained in:
commit
3a9e64af8f
|
@ -7,6 +7,10 @@ that were made in every particular version.
|
|||
From version 0.7.6 *Dependency Injector* framework strictly
|
||||
follows `Semantic versioning`_
|
||||
|
||||
4.0.6
|
||||
-----
|
||||
- Fix wiring for top-level package ``__init__.py``.
|
||||
|
||||
4.0.5
|
||||
-----
|
||||
- Move ``.provided`` attribute to ``providers.Provider``.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Top-level package."""
|
||||
|
||||
__version__ = '4.0.5'
|
||||
__version__ = '4.0.6'
|
||||
"""Version number.
|
||||
|
||||
:type: str
|
||||
|
|
|
@ -225,7 +225,7 @@ def _resolve_injections(fn: Callable[..., Any], providers_map: ProvidersMap) ->
|
|||
|
||||
|
||||
def _fetch_modules(package):
|
||||
modules = []
|
||||
modules = [package]
|
||||
for loader, module_name, is_pkg in pkgutil.walk_packages(
|
||||
path=package.__path__,
|
||||
prefix=package.__name__ + '.',
|
||||
|
|
11
tests/unit/samples/wiringsamples/package/__init__.py
Normal file
11
tests/unit/samples/wiringsamples/package/__init__.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
import sys
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
from dependency_injector.wiring import Provide
|
||||
|
||||
from ..container import Container
|
||||
from ..service import Service
|
||||
|
||||
|
||||
def test_package_function(service: Service = Provide[Container.service]):
|
||||
return service
|
|
@ -0,0 +1,11 @@
|
|||
import sys
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
from dependency_injector.wiring import Provide
|
||||
|
||||
from ...container import Container
|
||||
from ...service import Service
|
||||
|
||||
|
||||
def test_package_function(service: Service = Provide[Container.service]):
|
||||
return service
|
|
@ -3,9 +3,20 @@ import unittest
|
|||
|
||||
from dependency_injector.wiring import wire, Provide
|
||||
|
||||
from . import module, package
|
||||
from .service import Service
|
||||
from .container import Container
|
||||
# Runtime import to avoid syntax errors in samples on Python < 3.5
|
||||
import os
|
||||
_SAMPLES_DIR = os.path.abspath(
|
||||
os.path.sep.join((
|
||||
os.path.dirname(__file__),
|
||||
'../samples/',
|
||||
)),
|
||||
)
|
||||
import sys
|
||||
sys.path.append(_SAMPLES_DIR)
|
||||
|
||||
from wiringsamples import module, package
|
||||
from wiringsamples.service import Service
|
||||
from wiringsamples.container import Container
|
||||
|
||||
|
||||
class WiringTest(unittest.TestCase):
|
||||
|
@ -21,7 +32,17 @@ class WiringTest(unittest.TestCase):
|
|||
self.addCleanup(self.container.unwire)
|
||||
|
||||
def test_package_lookup(self):
|
||||
from .package.subpackage.submodule import test_function
|
||||
from wiringsamples.package import test_package_function
|
||||
service = test_package_function()
|
||||
self.assertIsInstance(service, Service)
|
||||
|
||||
def test_package_subpackage_lookup(self):
|
||||
from wiringsamples.package.subpackage import test_package_function
|
||||
service = test_package_function()
|
||||
self.assertIsInstance(service, Service)
|
||||
|
||||
def test_package_submodule_lookup(self):
|
||||
from wiringsamples.package.subpackage.submodule import test_function
|
||||
service = test_function()
|
||||
self.assertIsInstance(service, Service)
|
||||
|
||||
|
@ -125,10 +146,10 @@ class WiringTest(unittest.TestCase):
|
|||
|
||||
def test_unwire_package_function(self):
|
||||
self.container.unwire()
|
||||
from .package.subpackage.submodule import test_function
|
||||
from wiringsamples.package.subpackage.submodule import test_function
|
||||
self.assertIsInstance(test_function(), Provide)
|
||||
|
||||
def test_unwire_package_function_by_reference(self):
|
||||
from .package.subpackage import submodule
|
||||
from wiringsamples.package.subpackage import submodule
|
||||
self.container.unwire()
|
||||
self.assertIsInstance(submodule.test_function(), Provide)
|
||||
|
|
Loading…
Reference in New Issue
Block a user