From d6223bd53bfe8c0b66275e0c7782cc7ae4a303d9 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Mon, 7 Oct 2024 17:07:20 +0200 Subject: [PATCH] wip: example of the component mismatch of to_component to_component creates a wrapper that copies reconfigured dependencies, however as it turns out, component stays bound to the methods theres need for either a fixup or a warning on self bound to_component usage --- tests/unit/container/test_components.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/unit/container/test_components.py b/tests/unit/container/test_components.py index 25022d36..192bb78b 100644 --- a/tests/unit/container/test_components.py +++ b/tests/unit/container/test_components.py @@ -89,6 +89,19 @@ def test_change_component(): assert container.get(int, component="Y") == 20 +class ToComponentComponentNameProvider(Provider): + scope = Scope.APP + @provide + def my_component(self) -> str: + return self.component + +def test_change_component_access(): + provider = ToComponentComponentNameProvider(component="start") + container = make_container(provider, provider.to_component("other")) + assert container.get(str, component="start") == "start" + assert container.get(str, component="other") == "other" + + def test_set_component(): container = make_container(SingleProvider(20, component="Y")) assert container.get(int, component="Y") == 20