mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Add tests for `.as_float()
` modifier usage with wiring
This commit is contained in:
parent
d3720bd6dd
commit
5f6777db19
|
@ -7,6 +7,10 @@ that were made in every particular version.
|
||||||
From version 0.7.6 *Dependency Injector* framework strictly
|
From version 0.7.6 *Dependency Injector* framework strictly
|
||||||
follows `Semantic versioning`_
|
follows `Semantic versioning`_
|
||||||
|
|
||||||
|
Development version
|
||||||
|
-------------------
|
||||||
|
- Add tests for ``.as_float()`` modifier usage with wiring.
|
||||||
|
|
||||||
4.26.0
|
4.26.0
|
||||||
------
|
------
|
||||||
- Add wiring by string id.
|
- Add wiring by string id.
|
||||||
|
|
|
@ -44,19 +44,23 @@ def test_function_provider(service_provider: Callable[..., Service] = Provider[C
|
||||||
@inject
|
@inject
|
||||||
def test_config_value(
|
def test_config_value(
|
||||||
value_int: int = Provide[Container.config.a.b.c.as_int()],
|
value_int: int = Provide[Container.config.a.b.c.as_int()],
|
||||||
|
value_float: float = Provide[Container.config.a.b.c.as_float()],
|
||||||
value_str: str = Provide[Container.config.a.b.c.as_(str)],
|
value_str: str = Provide[Container.config.a.b.c.as_(str)],
|
||||||
value_decimal: Decimal = Provide[Container.config.a.b.c.as_(Decimal)],
|
value_decimal: Decimal = Provide[Container.config.a.b.c.as_(Decimal)],
|
||||||
value_required: str = Provide[Container.config.a.b.c.required()],
|
value_required: str = Provide[Container.config.a.b.c.required()],
|
||||||
value_required_int: int = Provide[Container.config.a.b.c.required().as_int()],
|
value_required_int: int = Provide[Container.config.a.b.c.required().as_int()],
|
||||||
|
value_required_float: float = Provide[Container.config.a.b.c.required().as_float()],
|
||||||
value_required_str: str = Provide[Container.config.a.b.c.required().as_(str)],
|
value_required_str: str = Provide[Container.config.a.b.c.required().as_(str)],
|
||||||
value_required_decimal: str = Provide[Container.config.a.b.c.required().as_(Decimal)],
|
value_required_decimal: str = Provide[Container.config.a.b.c.required().as_(Decimal)],
|
||||||
):
|
):
|
||||||
return (
|
return (
|
||||||
value_int,
|
value_int,
|
||||||
|
value_float,
|
||||||
value_str,
|
value_str,
|
||||||
value_decimal,
|
value_decimal,
|
||||||
value_required,
|
value_required,
|
||||||
value_required_int,
|
value_required_int,
|
||||||
|
value_required_float,
|
||||||
value_required_str,
|
value_required_str,
|
||||||
value_required_decimal,
|
value_required_decimal,
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,17 @@
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from dependency_injector.wiring import inject, Provide, Provider, as_int, as_, required, invariant, provided
|
from dependency_injector.wiring import (
|
||||||
|
inject,
|
||||||
|
Provide,
|
||||||
|
Provider,
|
||||||
|
as_int,
|
||||||
|
as_float,
|
||||||
|
as_,
|
||||||
|
required,
|
||||||
|
invariant,
|
||||||
|
provided,
|
||||||
|
)
|
||||||
|
|
||||||
from .container import Container
|
from .container import Container
|
||||||
from .service import Service
|
from .service import Service
|
||||||
|
@ -44,19 +54,23 @@ def test_function_provider(service_provider: Callable[..., Service] = Provider['
|
||||||
@inject
|
@inject
|
||||||
def test_config_value(
|
def test_config_value(
|
||||||
value_int: int = Provide['config.a.b.c', as_int()],
|
value_int: int = Provide['config.a.b.c', as_int()],
|
||||||
|
value_float: float = Provide['config.a.b.c', as_float()],
|
||||||
value_str: str = Provide['config.a.b.c', as_(str)],
|
value_str: str = Provide['config.a.b.c', as_(str)],
|
||||||
value_decimal: Decimal = Provide['config.a.b.c', as_(Decimal)],
|
value_decimal: Decimal = Provide['config.a.b.c', as_(Decimal)],
|
||||||
value_required: str = Provide['config.a.b.c', required()],
|
value_required: str = Provide['config.a.b.c', required()],
|
||||||
value_required_int: int = Provide['config.a.b.c', required().as_int()],
|
value_required_int: int = Provide['config.a.b.c', required().as_int()],
|
||||||
|
value_required_float: float = Provide['config.a.b.c', required().as_float()],
|
||||||
value_required_str: str = Provide['config.a.b.c', required().as_(str)],
|
value_required_str: str = Provide['config.a.b.c', required().as_(str)],
|
||||||
value_required_decimal: str = Provide['config.a.b.c', required().as_(Decimal)],
|
value_required_decimal: str = Provide['config.a.b.c', required().as_(Decimal)],
|
||||||
):
|
):
|
||||||
return (
|
return (
|
||||||
value_int,
|
value_int,
|
||||||
|
value_float,
|
||||||
value_str,
|
value_str,
|
||||||
value_decimal,
|
value_decimal,
|
||||||
value_required,
|
value_required,
|
||||||
value_required_int,
|
value_required_int,
|
||||||
|
value_required_float,
|
||||||
value_required_str,
|
value_required_str,
|
||||||
value_required_decimal,
|
value_required_decimal,
|
||||||
)
|
)
|
||||||
|
|
|
@ -120,19 +120,23 @@ class WiringTest(unittest.TestCase):
|
||||||
def test_configuration_option(self):
|
def test_configuration_option(self):
|
||||||
(
|
(
|
||||||
value_int,
|
value_int,
|
||||||
|
value_float,
|
||||||
value_str,
|
value_str,
|
||||||
value_decimal,
|
value_decimal,
|
||||||
value_required,
|
value_required,
|
||||||
value_required_int,
|
value_required_int,
|
||||||
|
value_required_float,
|
||||||
value_required_str,
|
value_required_str,
|
||||||
value_required_decimal,
|
value_required_decimal,
|
||||||
) = module.test_config_value()
|
) = module.test_config_value()
|
||||||
|
|
||||||
self.assertEqual(value_int, 10)
|
self.assertEqual(value_int, 10)
|
||||||
|
self.assertEqual(value_float, 10.0)
|
||||||
self.assertEqual(value_str, '10')
|
self.assertEqual(value_str, '10')
|
||||||
self.assertEqual(value_decimal, Decimal(10))
|
self.assertEqual(value_decimal, Decimal(10))
|
||||||
self.assertEqual(value_required, 10)
|
self.assertEqual(value_required, 10)
|
||||||
self.assertEqual(value_required_int, 10)
|
self.assertEqual(value_required_int, 10)
|
||||||
|
self.assertEqual(value_required_float, 10.0)
|
||||||
self.assertEqual(value_required_str, '10')
|
self.assertEqual(value_required_str, '10')
|
||||||
self.assertEqual(value_required_decimal, Decimal(10))
|
self.assertEqual(value_required_decimal, Decimal(10))
|
||||||
|
|
||||||
|
|
|
@ -120,19 +120,23 @@ class WiringTest(unittest.TestCase):
|
||||||
def test_configuration_option(self):
|
def test_configuration_option(self):
|
||||||
(
|
(
|
||||||
value_int,
|
value_int,
|
||||||
|
value_float,
|
||||||
value_str,
|
value_str,
|
||||||
value_decimal,
|
value_decimal,
|
||||||
value_required,
|
value_required,
|
||||||
value_required_int,
|
value_required_int,
|
||||||
|
value_required_float,
|
||||||
value_required_str,
|
value_required_str,
|
||||||
value_required_decimal,
|
value_required_decimal,
|
||||||
) = module.test_config_value()
|
) = module.test_config_value()
|
||||||
|
|
||||||
self.assertEqual(value_int, 10)
|
self.assertEqual(value_int, 10)
|
||||||
|
self.assertEqual(value_float, 10.0)
|
||||||
self.assertEqual(value_str, '10')
|
self.assertEqual(value_str, '10')
|
||||||
self.assertEqual(value_decimal, Decimal(10))
|
self.assertEqual(value_decimal, Decimal(10))
|
||||||
self.assertEqual(value_required, 10)
|
self.assertEqual(value_required, 10)
|
||||||
self.assertEqual(value_required_int, 10)
|
self.assertEqual(value_required_int, 10)
|
||||||
|
self.assertEqual(value_required_float, 10.0)
|
||||||
self.assertEqual(value_required_str, '10')
|
self.assertEqual(value_required_str, '10')
|
||||||
self.assertEqual(value_required_decimal, Decimal(10))
|
self.assertEqual(value_required_decimal, Decimal(10))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user