From 219c0217ab74192bc3ece98b8e57e410e3a852e6 Mon Sep 17 00:00:00 2001 From: Aldo Mateli Date: Sun, 25 Aug 2024 10:39:37 +0100 Subject: [PATCH] Improve UnknownQualifiedServiceRequestedError message --- test/unit/test_container.py | 8 ++++---- wireup/errors.py | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/unit/test_container.py b/test/unit/test_container.py index 00ecc52..8b5568b 100644 --- a/test/unit/test_container.py +++ b/test/unit/test_container.py @@ -300,7 +300,7 @@ def inner(_sub1: FooBase = Inject(qualifier="sub1")): ... self.assertIn( "Cannot instantiate concrete class for " - "as qualifier 'sub1' is unknown. Available qualifiers: set()", + "as qualifier 'sub1' is unknown. Available qualifiers: []", str(context.exception), ) @@ -315,7 +315,7 @@ def inner(_sub1: FooBase): ... self.assertEqual( f"Cannot instantiate concrete class for {FooBase} as qualifier 'None' is unknown. " - "Available qualifiers: {'foobar'}", + "Available qualifiers: ['foobar'].", str(context.exception), ) @@ -329,7 +329,7 @@ def inner(_sub1: FooBase): ... self.assertEqual( f"Cannot instantiate concrete class for {FooBase} as qualifier 'None' is unknown. " - "Available qualifiers: set()", + "Available qualifiers: [].", str(context.exception), ) @@ -345,7 +345,7 @@ def inner(_foo: RegisterWithQualifierClass): ... self.assertIn( f"Cannot instantiate concrete class for {RegisterWithQualifierClass} " - f"as qualifier 'None' is unknown. Available qualifiers: {{'{__name__}'}}", + f"as qualifier 'None' is unknown. Available qualifiers: ['{__name__}'].", str(context.exception), ) diff --git a/wireup/errors.py b/wireup/errors.py index d5286ac..a979443 100644 --- a/wireup/errors.py +++ b/wireup/errors.py @@ -68,10 +68,11 @@ def __init__( ) -> None: self.klass = klass self.qualifier = qualifier + qualifiers_str = ", ".join(sorted(f"'{q}'" for q in available_qualifiers)) super().__init__( f"Cannot instantiate concrete class for {klass} as qualifier '{qualifier}' is unknown. " - f"Available qualifiers: {available_qualifiers}", + f"Available qualifiers: [{qualifiers_str}].", )