From 5f6777db19688917895697fc885d2d854778ba64 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Tue, 23 Feb 2021 10:20:04 -0500 Subject: [PATCH] Add tests for ``.as_float()`` modifier usage with wiring --- docs/main/changelog.rst | 4 ++++ tests/unit/samples/wiringsamples/module.py | 4 ++++ .../samples/wiringstringidssamples/module.py | 16 +++++++++++++++- tests/unit/wiring/test_wiring_py36.py | 4 ++++ tests/unit/wiring/test_wiring_string_ids_py36.py | 4 ++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 3df4dcef..cf3df9b7 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -7,6 +7,10 @@ that were made in every particular version. From version 0.7.6 *Dependency Injector* framework strictly follows `Semantic versioning`_ +Development version +------------------- +- Add tests for ``.as_float()`` modifier usage with wiring. + 4.26.0 ------ - Add wiring by string id. diff --git a/tests/unit/samples/wiringsamples/module.py b/tests/unit/samples/wiringsamples/module.py index 01031d2d..4c02b553 100644 --- a/tests/unit/samples/wiringsamples/module.py +++ b/tests/unit/samples/wiringsamples/module.py @@ -44,19 +44,23 @@ def test_function_provider(service_provider: Callable[..., Service] = Provider[C @inject def test_config_value( 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_decimal: Decimal = Provide[Container.config.a.b.c.as_(Decimal)], 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_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_decimal: str = Provide[Container.config.a.b.c.required().as_(Decimal)], ): return ( value_int, + value_float, value_str, value_decimal, value_required, value_required_int, + value_required_float, value_required_str, value_required_decimal, ) diff --git a/tests/unit/samples/wiringstringidssamples/module.py b/tests/unit/samples/wiringstringidssamples/module.py index f83a0a27..019e290b 100644 --- a/tests/unit/samples/wiringstringidssamples/module.py +++ b/tests/unit/samples/wiringstringidssamples/module.py @@ -3,7 +3,17 @@ from decimal import Decimal 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 .service import Service @@ -44,19 +54,23 @@ def test_function_provider(service_provider: Callable[..., Service] = Provider[' @inject def test_config_value( 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_decimal: Decimal = Provide['config.a.b.c', as_(Decimal)], value_required: str = Provide['config.a.b.c', required()], 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_decimal: str = Provide['config.a.b.c', required().as_(Decimal)], ): return ( value_int, + value_float, value_str, value_decimal, value_required, value_required_int, + value_required_float, value_required_str, value_required_decimal, ) diff --git a/tests/unit/wiring/test_wiring_py36.py b/tests/unit/wiring/test_wiring_py36.py index 064aed9b..fd08799b 100644 --- a/tests/unit/wiring/test_wiring_py36.py +++ b/tests/unit/wiring/test_wiring_py36.py @@ -120,19 +120,23 @@ class WiringTest(unittest.TestCase): def test_configuration_option(self): ( value_int, + value_float, value_str, value_decimal, value_required, value_required_int, + value_required_float, value_required_str, value_required_decimal, ) = module.test_config_value() self.assertEqual(value_int, 10) + self.assertEqual(value_float, 10.0) self.assertEqual(value_str, '10') self.assertEqual(value_decimal, Decimal(10)) self.assertEqual(value_required, 10) self.assertEqual(value_required_int, 10) + self.assertEqual(value_required_float, 10.0) self.assertEqual(value_required_str, '10') self.assertEqual(value_required_decimal, Decimal(10)) diff --git a/tests/unit/wiring/test_wiring_string_ids_py36.py b/tests/unit/wiring/test_wiring_string_ids_py36.py index b4d41b3b..0acc99ce 100644 --- a/tests/unit/wiring/test_wiring_string_ids_py36.py +++ b/tests/unit/wiring/test_wiring_string_ids_py36.py @@ -120,19 +120,23 @@ class WiringTest(unittest.TestCase): def test_configuration_option(self): ( value_int, + value_float, value_str, value_decimal, value_required, value_required_int, + value_required_float, value_required_str, value_required_decimal, ) = module.test_config_value() self.assertEqual(value_int, 10) + self.assertEqual(value_float, 10.0) self.assertEqual(value_str, '10') self.assertEqual(value_decimal, Decimal(10)) self.assertEqual(value_required, 10) self.assertEqual(value_required_int, 10) + self.assertEqual(value_required_float, 10.0) self.assertEqual(value_required_str, '10') self.assertEqual(value_required_decimal, Decimal(10))