orionis 0.406.0__py3-none-any.whl → 0.408.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orionis/container/container.py +11 -9
- orionis/container/enums/lifetimes.py +2 -0
- orionis/container/validators/__init__.py +21 -0
- orionis/metadata/framework.py +1 -1
- orionis/services/asynchrony/contracts/coroutines.py +13 -5
- orionis/services/asynchrony/coroutines.py +33 -29
- orionis/services/asynchrony/exceptions/exception.py +9 -1
- orionis/services/environment/core/dot_env.py +46 -34
- orionis/services/environment/enums/__init__.py +0 -0
- orionis/services/environment/enums/cast_type.py +42 -0
- orionis/services/environment/serializer/__init__.py +0 -0
- orionis/services/environment/serializer/values.py +21 -0
- orionis/services/environment/validators/__init__.py +0 -0
- orionis/services/environment/validators/key_name.py +46 -0
- orionis/services/environment/validators/types.py +45 -0
- orionis/services/system/contracts/imports.py +38 -18
- orionis/services/system/contracts/workers.py +29 -12
- orionis/services/system/imports.py +65 -25
- orionis/services/system/runtime/imports.py +18 -9
- orionis/services/system/workers.py +49 -16
- orionis/test/output/dumper.py +1 -0
- {orionis-0.406.0.dist-info → orionis-0.408.0.dist-info}/METADATA +1 -1
- {orionis-0.406.0.dist-info → orionis-0.408.0.dist-info}/RECORD +52 -45
- tests/container/context/test_manager.py +15 -5
- tests/container/context/test_scope.py +12 -4
- tests/container/entities/test_binding.py +130 -21
- tests/container/enums/test_lifetimes.py +52 -18
- tests/container/facades/test_facade.py +29 -12
- tests/container/providers/test_providers.py +17 -10
- tests/container/resolver/test_resolver.py +14 -7
- tests/container/test_container.py +226 -71
- tests/container/test_singleton.py +43 -24
- tests/container/test_thread_safety.py +28 -156
- tests/container/validators/test_implements.py +59 -13
- tests/container/validators/test_is_abstract_class.py +73 -25
- tests/container/validators/test_is_callable.py +55 -26
- tests/container/validators/test_is_concrete_class.py +80 -17
- tests/container/validators/test_is_instance.py +67 -22
- tests/container/validators/test_is_not_subclass.py +28 -95
- tests/container/validators/test_is_subclass.py +84 -21
- tests/container/validators/test_is_valid_alias.py +46 -12
- tests/container/validators/test_lifetime.py +45 -14
- tests/example/test_example.py +2 -2
- tests/metadata/test_metadata_framework.py +71 -6
- tests/metadata/test_metadata_package.py +55 -10
- tests/services/asynchrony/test_services_asynchrony_coroutine.py +52 -7
- tests/services/system/test_services_system_imports.py +119 -16
- tests/services/system/test_services_system_workers.py +71 -30
- {orionis-0.406.0.dist-info → orionis-0.408.0.dist-info}/WHEEL +0 -0
- {orionis-0.406.0.dist-info → orionis-0.408.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.406.0.dist-info → orionis-0.408.0.dist-info}/top_level.txt +0 -0
- {orionis-0.406.0.dist-info → orionis-0.408.0.dist-info}/zip-safe +0 -0
|
@@ -4,114 +4,47 @@ from orionis.container.exceptions.exception import OrionisContainerException
|
|
|
4
4
|
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
5
5
|
|
|
6
6
|
class TestIsNotSubclass(AsyncTestCase):
|
|
7
|
-
"""
|
|
8
|
-
Test cases for the IsNotSubclass validator in orionis.container.validators.is_not_subclass.
|
|
9
|
-
|
|
10
|
-
Notes
|
|
11
|
-
-----
|
|
12
|
-
This test suite validates the functionality of the IsNotSubclass validator
|
|
13
|
-
which ensures that a concrete class is NOT a subclass of an abstract class.
|
|
14
|
-
"""
|
|
15
7
|
|
|
16
8
|
async def testValidNonSubclass(self) -> None:
|
|
17
9
|
"""
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# Define test classes
|
|
21
|
-
class AbstractClass1(ABC):
|
|
22
|
-
pass
|
|
10
|
+
Validate that `IsNotSubclass` does not raise an exception when the second argument
|
|
11
|
+
is not a subclass of the first argument.
|
|
23
12
|
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
This test covers various scenarios including unrelated abstract classes, concrete classes,
|
|
14
|
+
and built-in types to ensure that only true subclass relationships trigger validation errors.
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
self : TestIsNotSubclass
|
|
19
|
+
The test case instance.
|
|
29
20
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
IsNotSubclass(AbstractClass1, AbstractClass2)
|
|
35
|
-
IsNotSubclass(AbstractClass1, ConcreteClass2)
|
|
36
|
-
IsNotSubclass(ConcreteClass1, AbstractClass1)
|
|
37
|
-
IsNotSubclass(int, str)
|
|
38
|
-
IsNotSubclass(list, dict)
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
None
|
|
24
|
+
This method does not return any value.
|
|
39
25
|
|
|
40
|
-
|
|
26
|
+
Raises
|
|
27
|
+
------
|
|
28
|
+
AssertionError
|
|
29
|
+
If `IsNotSubclass` raises an exception for valid non-subclass relationships.
|
|
41
30
|
"""
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
# Define test classes
|
|
45
|
-
class AbstractClass(ABC):
|
|
46
|
-
pass
|
|
47
|
-
|
|
48
|
-
class ConcreteClass(AbstractClass):
|
|
31
|
+
# Define abstract base classes
|
|
32
|
+
class AbstractClass1(ABC):
|
|
49
33
|
pass
|
|
50
34
|
|
|
51
|
-
class
|
|
35
|
+
class AbstractClass2(ABC):
|
|
52
36
|
pass
|
|
53
37
|
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
IsNotSubclass(AbstractClass, ConcreteClass)
|
|
57
|
-
self.assertIn("must NOT inherit", str(context.exception))
|
|
58
|
-
|
|
59
|
-
with self.assertRaises(OrionisContainerException) as context:
|
|
60
|
-
IsNotSubclass(AbstractClass, SubConcreteClass)
|
|
61
|
-
self.assertIn("must NOT inherit", str(context.exception))
|
|
62
|
-
|
|
63
|
-
with self.assertRaises(OrionisContainerException) as context:
|
|
64
|
-
IsNotSubclass(ConcreteClass, SubConcreteClass)
|
|
65
|
-
self.assertIn("must NOT inherit", str(context.exception))
|
|
66
|
-
|
|
67
|
-
async def testSameClass(self) -> None:
|
|
68
|
-
"""
|
|
69
|
-
Test validation when abstract and concrete are the same class.
|
|
70
|
-
"""
|
|
71
|
-
class TestClass:
|
|
38
|
+
# Define concrete classes inheriting from abstract base classes
|
|
39
|
+
class ConcreteClass1(AbstractClass1):
|
|
72
40
|
pass
|
|
73
41
|
|
|
74
|
-
|
|
75
|
-
with self.assertRaises(OrionisContainerException) as context:
|
|
76
|
-
IsNotSubclass(TestClass, TestClass)
|
|
77
|
-
self.assertIn("must NOT inherit", str(context.exception))
|
|
78
|
-
|
|
79
|
-
async def testBuiltinTypes(self) -> None:
|
|
80
|
-
"""
|
|
81
|
-
Test validation with built-in types.
|
|
82
|
-
"""
|
|
83
|
-
# Valid non-subclass relationships
|
|
84
|
-
IsNotSubclass(ValueError, Exception)
|
|
85
|
-
IsNotSubclass(int, str)
|
|
86
|
-
IsNotSubclass(list, dict)
|
|
87
|
-
|
|
88
|
-
# Invalid non-subclass relationships (are actually subclasses)
|
|
89
|
-
with self.assertRaises(OrionisContainerException):
|
|
90
|
-
IsNotSubclass(Exception, ValueError)
|
|
91
|
-
|
|
92
|
-
with self.assertRaises(OrionisContainerException):
|
|
93
|
-
IsNotSubclass(BaseException, Exception)
|
|
94
|
-
|
|
95
|
-
async def testNonClassArguments(self) -> None:
|
|
96
|
-
"""
|
|
97
|
-
Test validation with non-class arguments which should raise TypeError.
|
|
98
|
-
"""
|
|
99
|
-
class TestClass:
|
|
42
|
+
class ConcreteClass2(AbstractClass2):
|
|
100
43
|
pass
|
|
101
44
|
|
|
102
|
-
# These should raise
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{},
|
|
109
|
-
lambda x: x
|
|
110
|
-
]
|
|
111
|
-
|
|
112
|
-
for arg in non_class_args:
|
|
113
|
-
with self.assertRaises(TypeError):
|
|
114
|
-
IsNotSubclass(TestClass, arg)
|
|
115
|
-
|
|
116
|
-
with self.assertRaises(TypeError):
|
|
117
|
-
IsNotSubclass(arg, TestClass)
|
|
45
|
+
# These calls should NOT raise exceptions since there is no subclass relationship
|
|
46
|
+
IsNotSubclass(AbstractClass1, AbstractClass2) # Unrelated abstract classes
|
|
47
|
+
IsNotSubclass(AbstractClass1, ConcreteClass2) # Unrelated concrete class
|
|
48
|
+
IsNotSubclass(ConcreteClass1, AbstractClass1) # Concrete is not subclass of unrelated abstract
|
|
49
|
+
IsNotSubclass(int, str) # Built-in types, no subclass relationship
|
|
50
|
+
IsNotSubclass(list, dict) # Built-in types, no subclass relationship
|
|
@@ -4,52 +4,73 @@ from orionis.container.exceptions.exception import OrionisContainerException
|
|
|
4
4
|
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
5
5
|
|
|
6
6
|
class TestIsSubclass(AsyncTestCase):
|
|
7
|
-
"""
|
|
8
|
-
Test cases for the IsSubclass validator in orionis.container.validators.is_subclass.
|
|
9
|
-
|
|
10
|
-
Notes
|
|
11
|
-
-----
|
|
12
|
-
This test suite validates the functionality of the IsSubclass validator
|
|
13
|
-
which ensures that a concrete class is a subclass of an abstract class.
|
|
14
|
-
"""
|
|
15
7
|
|
|
16
8
|
async def testValidSubclass(self) -> None:
|
|
17
9
|
"""
|
|
18
|
-
|
|
10
|
+
Validate that `IsSubclass` does not raise an exception when the concrete class is a valid subclass of the abstract class.
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
None
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
-------
|
|
18
|
+
None
|
|
19
|
+
This method does not return anything. It passes if no exception is raised.
|
|
20
|
+
|
|
21
|
+
Notes
|
|
22
|
+
-----
|
|
23
|
+
The test covers direct and indirect subclass relationships.
|
|
19
24
|
"""
|
|
20
|
-
# Define
|
|
25
|
+
# Define an abstract base class
|
|
21
26
|
class AbstractClass(ABC):
|
|
22
27
|
pass
|
|
23
28
|
|
|
29
|
+
# Define a concrete class inheriting from AbstractClass
|
|
24
30
|
class ConcreteClass(AbstractClass):
|
|
25
31
|
pass
|
|
26
32
|
|
|
33
|
+
# Define a subclass of ConcreteClass
|
|
27
34
|
class SubConcreteClass(ConcreteClass):
|
|
28
35
|
pass
|
|
29
36
|
|
|
30
|
-
# These should not raise exceptions
|
|
37
|
+
# These calls should not raise exceptions since subclass relationships are valid
|
|
31
38
|
IsSubclass(AbstractClass, ConcreteClass)
|
|
32
39
|
IsSubclass(AbstractClass, SubConcreteClass)
|
|
33
40
|
IsSubclass(ConcreteClass, SubConcreteClass)
|
|
34
41
|
|
|
35
42
|
async def testInvalidSubclass(self) -> None:
|
|
36
43
|
"""
|
|
37
|
-
|
|
44
|
+
Validate that `IsSubclass` raises `OrionisContainerException` when the concrete class is not a subclass of the abstract class.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
None
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
None
|
|
53
|
+
This method does not return anything. It passes if the expected exception is raised.
|
|
54
|
+
|
|
55
|
+
Notes
|
|
56
|
+
-----
|
|
57
|
+
The test covers cases where classes are unrelated or the inheritance direction is incorrect.
|
|
38
58
|
"""
|
|
39
|
-
# Define
|
|
59
|
+
# Define two unrelated abstract base classes
|
|
40
60
|
class AbstractClass1(ABC):
|
|
41
61
|
pass
|
|
42
62
|
|
|
43
63
|
class AbstractClass2(ABC):
|
|
44
64
|
pass
|
|
45
65
|
|
|
66
|
+
# Define concrete classes inheriting from each abstract class
|
|
46
67
|
class ConcreteClass1(AbstractClass1):
|
|
47
68
|
pass
|
|
48
69
|
|
|
49
70
|
class ConcreteClass2(AbstractClass2):
|
|
50
71
|
pass
|
|
51
72
|
|
|
52
|
-
# These should raise exceptions
|
|
73
|
+
# These calls should raise exceptions due to invalid subclass relationships
|
|
53
74
|
with self.assertRaises(OrionisContainerException) as context:
|
|
54
75
|
IsSubclass(AbstractClass1, AbstractClass2)
|
|
55
76
|
self.assertIn("concrete class must inherit", str(context.exception))
|
|
@@ -64,23 +85,50 @@ class TestIsSubclass(AsyncTestCase):
|
|
|
64
85
|
|
|
65
86
|
async def testSameClass(self) -> None:
|
|
66
87
|
"""
|
|
67
|
-
|
|
88
|
+
Validate that `IsSubclass` does not raise an exception when the abstract and concrete classes are the same.
|
|
89
|
+
|
|
90
|
+
Parameters
|
|
91
|
+
----------
|
|
92
|
+
None
|
|
93
|
+
|
|
94
|
+
Returns
|
|
95
|
+
-------
|
|
96
|
+
None
|
|
97
|
+
This method does not return anything. It passes if no exception is raised.
|
|
98
|
+
|
|
99
|
+
Notes
|
|
100
|
+
-----
|
|
101
|
+
In Python, a class is considered a subclass of itself.
|
|
68
102
|
"""
|
|
103
|
+
# Define a test class
|
|
69
104
|
class TestClass:
|
|
70
105
|
pass
|
|
71
106
|
|
|
72
|
-
#
|
|
107
|
+
# Should not raise since a class is a subclass of itself
|
|
73
108
|
IsSubclass(TestClass, TestClass)
|
|
74
109
|
|
|
75
110
|
async def testBuiltinTypes(self) -> None:
|
|
76
111
|
"""
|
|
77
|
-
|
|
112
|
+
Validate `IsSubclass` behavior with built-in types, ensuring correct subclass relationships and exception raising.
|
|
113
|
+
|
|
114
|
+
Parameters
|
|
115
|
+
----------
|
|
116
|
+
None
|
|
117
|
+
|
|
118
|
+
Returns
|
|
119
|
+
-------
|
|
120
|
+
None
|
|
121
|
+
This method does not return anything. It passes if exceptions are raised or not as expected.
|
|
122
|
+
|
|
123
|
+
Notes
|
|
124
|
+
-----
|
|
125
|
+
The test covers both valid and invalid subclass relationships among built-in types.
|
|
78
126
|
"""
|
|
79
|
-
# Valid subclass relationships
|
|
127
|
+
# Valid subclass relationships for built-in types
|
|
80
128
|
IsSubclass(Exception, ValueError)
|
|
81
129
|
IsSubclass(BaseException, Exception)
|
|
82
130
|
|
|
83
|
-
# Invalid subclass relationships
|
|
131
|
+
# Invalid subclass relationships should raise exceptions
|
|
84
132
|
with self.assertRaises(OrionisContainerException):
|
|
85
133
|
IsSubclass(ValueError, Exception)
|
|
86
134
|
|
|
@@ -92,12 +140,26 @@ class TestIsSubclass(AsyncTestCase):
|
|
|
92
140
|
|
|
93
141
|
async def testNonClassArguments(self) -> None:
|
|
94
142
|
"""
|
|
95
|
-
|
|
143
|
+
Validate that `IsSubclass` raises `TypeError` when non-class arguments are provided.
|
|
144
|
+
|
|
145
|
+
Parameters
|
|
146
|
+
----------
|
|
147
|
+
None
|
|
148
|
+
|
|
149
|
+
Returns
|
|
150
|
+
-------
|
|
151
|
+
None
|
|
152
|
+
This method does not return anything. It passes if `TypeError` is raised for non-class arguments.
|
|
153
|
+
|
|
154
|
+
Notes
|
|
155
|
+
-----
|
|
156
|
+
The test covers various non-class types such as None, int, str, list, dict, and function.
|
|
96
157
|
"""
|
|
158
|
+
# Define a valid test class
|
|
97
159
|
class TestClass:
|
|
98
160
|
pass
|
|
99
161
|
|
|
100
|
-
#
|
|
162
|
+
# List of non-class arguments to test
|
|
101
163
|
non_class_args = [
|
|
102
164
|
None,
|
|
103
165
|
123,
|
|
@@ -107,6 +169,7 @@ class TestIsSubclass(AsyncTestCase):
|
|
|
107
169
|
lambda x: x
|
|
108
170
|
]
|
|
109
171
|
|
|
172
|
+
# Each non-class argument should raise TypeError when used as either abstract or concrete class
|
|
110
173
|
for arg in non_class_args:
|
|
111
174
|
with self.assertRaises(TypeError):
|
|
112
175
|
IsSubclass(TestClass, arg)
|
|
@@ -3,18 +3,19 @@ from orionis.container.exceptions.type import OrionisContainerTypeError
|
|
|
3
3
|
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
4
4
|
|
|
5
5
|
class TestIsValidAlias(AsyncTestCase):
|
|
6
|
-
"""
|
|
7
|
-
Test cases for the IsValidAlias validator in orionis.container.validators.is_valid_alias.
|
|
8
|
-
|
|
9
|
-
Notes
|
|
10
|
-
-----
|
|
11
|
-
This test suite validates the functionality of the IsValidAlias validator
|
|
12
|
-
which ensures that alias values are valid strings without invalid characters.
|
|
13
|
-
"""
|
|
14
6
|
|
|
15
7
|
async def testValidAliases(self) -> None:
|
|
16
8
|
"""
|
|
17
|
-
|
|
9
|
+
Validates that the IsValidAlias validator accepts valid alias strings.
|
|
10
|
+
|
|
11
|
+
This test iterates over a list of valid alias strings and ensures that
|
|
12
|
+
the IsValidAlias validator does not raise any exceptions for these values.
|
|
13
|
+
Valid aliases include strings with letters, numbers, and underscores.
|
|
14
|
+
|
|
15
|
+
Returns
|
|
16
|
+
-------
|
|
17
|
+
None
|
|
18
|
+
This method does not return any value. It passes if no exception is raised.
|
|
18
19
|
"""
|
|
19
20
|
valid_aliases = [
|
|
20
21
|
"valid",
|
|
@@ -30,12 +31,22 @@ class TestIsValidAlias(AsyncTestCase):
|
|
|
30
31
|
"VALID_UPPERCASE_ALIAS"
|
|
31
32
|
]
|
|
32
33
|
|
|
34
|
+
# Ensure each valid alias passes validation without raising an exception
|
|
33
35
|
for alias in valid_aliases:
|
|
34
36
|
IsValidAlias(alias)
|
|
35
37
|
|
|
36
38
|
async def testInvalidAliasTypes(self) -> None:
|
|
37
39
|
"""
|
|
38
|
-
|
|
40
|
+
Ensures that IsValidAlias raises an exception for non-string types.
|
|
41
|
+
|
|
42
|
+
This test checks that passing values of types other than string (such as
|
|
43
|
+
integers, floats, None, booleans, lists, dictionaries, tuples, and sets)
|
|
44
|
+
to the IsValidAlias validator results in an OrionisContainerTypeError.
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
None
|
|
49
|
+
This method does not return any value. It passes if the expected exception is raised.
|
|
39
50
|
"""
|
|
40
51
|
invalid_types = [
|
|
41
52
|
123,
|
|
@@ -49,13 +60,24 @@ class TestIsValidAlias(AsyncTestCase):
|
|
|
49
60
|
set()
|
|
50
61
|
]
|
|
51
62
|
|
|
63
|
+
# Ensure each invalid type raises the expected exception
|
|
52
64
|
for value in invalid_types:
|
|
53
65
|
with self.assertRaises(OrionisContainerTypeError) as context:
|
|
54
66
|
IsValidAlias(value)
|
|
55
67
|
|
|
56
68
|
async def testAliasWithInvalidCharacters(self) -> None:
|
|
57
69
|
"""
|
|
58
|
-
|
|
70
|
+
Verifies that aliases containing invalid characters are rejected.
|
|
71
|
+
|
|
72
|
+
This test iterates over a list of alias strings containing whitespace,
|
|
73
|
+
control characters, and special symbols, and asserts that the
|
|
74
|
+
IsValidAlias validator raises an OrionisContainerTypeError for each.
|
|
75
|
+
It also checks that the exception message is descriptive.
|
|
76
|
+
|
|
77
|
+
Returns
|
|
78
|
+
-------
|
|
79
|
+
None
|
|
80
|
+
This method does not return any value. It passes if the expected exception and message are raised.
|
|
59
81
|
"""
|
|
60
82
|
invalid_aliases = [
|
|
61
83
|
"invalid alias", # space
|
|
@@ -82,17 +104,29 @@ class TestIsValidAlias(AsyncTestCase):
|
|
|
82
104
|
"invalid'alias" # single quote
|
|
83
105
|
]
|
|
84
106
|
|
|
107
|
+
# Ensure each invalid alias raises the expected exception and message
|
|
85
108
|
for alias in invalid_aliases:
|
|
86
109
|
with self.assertRaises(OrionisContainerTypeError) as context:
|
|
87
110
|
IsValidAlias(alias)
|
|
88
111
|
|
|
89
112
|
expected_msg_start = f"Alias '{alias}' contains invalid characters."
|
|
113
|
+
# Check that the exception message starts as expected
|
|
90
114
|
self.assertTrue(str(context.exception).startswith(expected_msg_start))
|
|
115
|
+
# Check that the message contains additional guidance
|
|
91
116
|
self.assertIn("Aliases must not contain whitespace or special symbols", str(context.exception))
|
|
92
117
|
|
|
93
118
|
async def testEmptyAlias(self) -> None:
|
|
94
119
|
"""
|
|
95
|
-
|
|
120
|
+
Checks that empty or whitespace-only aliases are rejected.
|
|
121
|
+
|
|
122
|
+
This test verifies that passing an empty string or a string containing
|
|
123
|
+
only whitespace to the IsValidAlias validator raises an
|
|
124
|
+
OrionisContainerTypeError with the correct error message.
|
|
125
|
+
|
|
126
|
+
Returns
|
|
127
|
+
-------
|
|
128
|
+
None
|
|
129
|
+
This method does not return any value. It passes if the expected exception and message are raised.
|
|
96
130
|
"""
|
|
97
131
|
# Empty string should be rejected
|
|
98
132
|
with self.assertRaises(OrionisContainerTypeError) as context:
|
|
@@ -4,47 +4,68 @@ from orionis.container.exceptions.type import OrionisContainerTypeError
|
|
|
4
4
|
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
5
5
|
|
|
6
6
|
class TestLifetimeValidator(AsyncTestCase):
|
|
7
|
-
"""
|
|
8
|
-
Test cases for the LifetimeValidator in orionis.container.validators.lifetime.
|
|
9
|
-
|
|
10
|
-
Notes
|
|
11
|
-
-----
|
|
12
|
-
This test suite validates the functionality of the LifetimeValidator
|
|
13
|
-
which ensures that lifetime values are correctly validated and converted.
|
|
14
|
-
"""
|
|
15
7
|
|
|
16
8
|
async def testValidLifetimeEnumValues(self) -> None:
|
|
17
9
|
"""
|
|
18
|
-
|
|
10
|
+
Validate that LifetimeValidator correctly accepts Lifetime enum values.
|
|
11
|
+
|
|
12
|
+
This test checks that the validator returns the corresponding Lifetime enum
|
|
13
|
+
when provided with valid enum values.
|
|
14
|
+
|
|
15
|
+
Returns
|
|
16
|
+
-------
|
|
17
|
+
None
|
|
18
|
+
This method does not return anything. It asserts correctness via test assertions.
|
|
19
19
|
"""
|
|
20
|
+
# Assert that each Lifetime enum value is accepted and returned as expected
|
|
20
21
|
self.assertEqual(LifetimeValidator(Lifetime.TRANSIENT), Lifetime.TRANSIENT)
|
|
21
22
|
self.assertEqual(LifetimeValidator(Lifetime.SINGLETON), Lifetime.SINGLETON)
|
|
22
23
|
self.assertEqual(LifetimeValidator(Lifetime.SCOPED), Lifetime.SCOPED)
|
|
23
24
|
|
|
24
25
|
async def testValidLifetimeStringValues(self) -> None:
|
|
25
26
|
"""
|
|
26
|
-
|
|
27
|
+
Validate that LifetimeValidator correctly accepts valid string representations.
|
|
28
|
+
|
|
29
|
+
This test verifies that the validator returns the correct Lifetime enum when
|
|
30
|
+
provided with valid string representations, including different cases and extra whitespace.
|
|
31
|
+
|
|
32
|
+
Returns
|
|
33
|
+
-------
|
|
34
|
+
None
|
|
35
|
+
This method does not return anything. It asserts correctness via test assertions.
|
|
27
36
|
"""
|
|
37
|
+
# Assert that valid uppercase string representations are accepted
|
|
28
38
|
self.assertEqual(LifetimeValidator("TRANSIENT"), Lifetime.TRANSIENT)
|
|
29
39
|
self.assertEqual(LifetimeValidator("SINGLETON"), Lifetime.SINGLETON)
|
|
30
40
|
self.assertEqual(LifetimeValidator("SCOPED"), Lifetime.SCOPED)
|
|
31
41
|
|
|
32
|
-
#
|
|
42
|
+
# Assert that lowercase and mixed case strings are accepted
|
|
33
43
|
self.assertEqual(LifetimeValidator("transient"), Lifetime.TRANSIENT)
|
|
34
44
|
self.assertEqual(LifetimeValidator("Singleton"), Lifetime.SINGLETON)
|
|
35
45
|
self.assertEqual(LifetimeValidator("scoped"), Lifetime.SCOPED)
|
|
36
46
|
|
|
37
|
-
#
|
|
47
|
+
# Assert that strings with extra whitespace are accepted
|
|
38
48
|
self.assertEqual(LifetimeValidator(" TRANSIENT "), Lifetime.TRANSIENT)
|
|
39
49
|
self.assertEqual(LifetimeValidator(" singleton "), Lifetime.SINGLETON)
|
|
40
50
|
|
|
41
51
|
async def testInvalidLifetimeStringValue(self) -> None:
|
|
42
52
|
"""
|
|
43
|
-
|
|
53
|
+
Validate that LifetimeValidator raises an error for invalid string values.
|
|
54
|
+
|
|
55
|
+
This test ensures that the validator raises OrionisContainerTypeError when
|
|
56
|
+
provided with an invalid string representation, and that the error message
|
|
57
|
+
contains information about valid options.
|
|
58
|
+
|
|
59
|
+
Returns
|
|
60
|
+
-------
|
|
61
|
+
None
|
|
62
|
+
This method does not return anything. It asserts correctness via test assertions.
|
|
44
63
|
"""
|
|
64
|
+
# Attempt to validate an invalid string and check for the expected exception
|
|
45
65
|
with self.assertRaises(OrionisContainerTypeError) as context:
|
|
46
66
|
LifetimeValidator("INVALID_LIFETIME")
|
|
47
67
|
|
|
68
|
+
# Assert that the error message contains relevant information
|
|
48
69
|
self.assertIn("Invalid lifetime 'INVALID_LIFETIME'", str(context.exception))
|
|
49
70
|
self.assertIn("Valid options are:", str(context.exception))
|
|
50
71
|
self.assertIn("TRANSIENT", str(context.exception))
|
|
@@ -53,8 +74,17 @@ class TestLifetimeValidator(AsyncTestCase):
|
|
|
53
74
|
|
|
54
75
|
async def testInvalidLifetimeType(self) -> None:
|
|
55
76
|
"""
|
|
56
|
-
|
|
77
|
+
Validate that LifetimeValidator raises an error for invalid input types.
|
|
78
|
+
|
|
79
|
+
This test checks that the validator raises OrionisContainerTypeError when
|
|
80
|
+
provided with values of types other than str or Lifetime enum.
|
|
81
|
+
|
|
82
|
+
Returns
|
|
83
|
+
-------
|
|
84
|
+
None
|
|
85
|
+
This method does not return anything. It asserts correctness via test assertions.
|
|
57
86
|
"""
|
|
87
|
+
# List of invalid types to test
|
|
58
88
|
invalid_values = [
|
|
59
89
|
123,
|
|
60
90
|
3.14,
|
|
@@ -67,6 +97,7 @@ class TestLifetimeValidator(AsyncTestCase):
|
|
|
67
97
|
set()
|
|
68
98
|
]
|
|
69
99
|
|
|
100
|
+
# Assert that each invalid type raises the expected exception
|
|
70
101
|
for value in invalid_values:
|
|
71
102
|
with self.assertRaises(OrionisContainerTypeError) as context:
|
|
72
103
|
LifetimeValidator(value)
|
tests/example/test_example.py
CHANGED
|
@@ -6,7 +6,7 @@ This module contains comprehensive test examples demonstrating the capabilities
|
|
|
6
6
|
of the Orionis testing framework, including both synchronous and asynchronous
|
|
7
7
|
testing patterns with dependency injection.
|
|
8
8
|
|
|
9
|
-
Examples
|
|
9
|
+
Examples:
|
|
10
10
|
--------
|
|
11
11
|
Run synchronous tests:
|
|
12
12
|
>>> from tests.example.test_example import TestSynchronousExample
|
|
@@ -20,7 +20,7 @@ Examples
|
|
|
20
20
|
>>> await test.asyncSetUp()
|
|
21
21
|
>>> await test.testAsyncBasicOperations()
|
|
22
22
|
|
|
23
|
-
Notes
|
|
23
|
+
Notes:
|
|
24
24
|
-----
|
|
25
25
|
These examples showcase:
|
|
26
26
|
- Dependency injection patterns
|