orionis 0.438.0__py3-none-any.whl → 0.439.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/context/scope.py +1 -1
- orionis/metadata/framework.py +1 -1
- {orionis-0.438.0.dist-info → orionis-0.439.0.dist-info}/METADATA +1 -1
- {orionis-0.438.0.dist-info → orionis-0.439.0.dist-info}/RECORD +23 -23
- tests/container/context/test_manager.py +1 -0
- tests/container/context/test_scope.py +1 -0
- tests/container/core/test_container.py +45 -1
- tests/container/core/test_singleton.py +5 -0
- tests/container/core/test_thread_safety.py +2 -0
- tests/container/validators/test_is_not_subclass.py +0 -1
- tests/foundation/config/queue/test_foundation_config_queue_brokers.py +1 -0
- tests/foundation/config/startup/test_foundation_config_startup.py +0 -1
- tests/services/environment/test_services_environment.py +5 -4
- tests/services/introspection/reflection/mock/fake_reflect_instance.py +750 -267
- tests/services/introspection/reflection/test_reflection_abstract.py +167 -92
- tests/services/introspection/reflection/test_reflection_callable.py +85 -35
- tests/services/introspection/reflection/test_reflection_concrete.py +345 -226
- tests/services/introspection/reflection/test_reflection_instance.py +627 -273
- tests/services/introspection/reflection/test_reflection_module.py +346 -175
- {orionis-0.438.0.dist-info → orionis-0.439.0.dist-info}/WHEEL +0 -0
- {orionis-0.438.0.dist-info → orionis-0.439.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.438.0.dist-info → orionis-0.439.0.dist-info}/top_level.txt +0 -0
- {orionis-0.438.0.dist-info → orionis-0.439.0.dist-info}/zip-safe +0 -0
|
@@ -3,13 +3,27 @@ from orionis.services.introspection.modules.reflection import ReflectionModule
|
|
|
3
3
|
from orionis.services.introspection.exceptions import ReflectionTypeError, ReflectionValueError
|
|
4
4
|
|
|
5
5
|
class TestServiceReflectionModule(AsyncTestCase):
|
|
6
|
+
"""
|
|
7
|
+
Test suite for the ReflectionModule class functionality.
|
|
8
|
+
|
|
9
|
+
This test class validates the introspection capabilities of the ReflectionModule
|
|
10
|
+
which provides reflection functionality for Python modules including class,
|
|
11
|
+
function, and constant discovery and manipulation.
|
|
12
|
+
"""
|
|
6
13
|
|
|
7
14
|
module_name = 'tests.services.introspection.reflection.mock.fake_reflect_instance'
|
|
8
15
|
|
|
9
16
|
async def testGetModule(self):
|
|
10
17
|
"""
|
|
11
|
-
Test
|
|
12
|
-
|
|
18
|
+
Test retrieval of the underlying module object.
|
|
19
|
+
|
|
20
|
+
Validates that the getModule method returns the correct module object
|
|
21
|
+
and that the module's __name__ attribute matches the expected name.
|
|
22
|
+
|
|
23
|
+
Raises
|
|
24
|
+
------
|
|
25
|
+
AssertionError
|
|
26
|
+
If the module name does not match the expected value.
|
|
13
27
|
"""
|
|
14
28
|
reflection = ReflectionModule(self.module_name)
|
|
15
29
|
module = reflection.getModule()
|
|
@@ -17,75 +31,102 @@ class TestServiceReflectionModule(AsyncTestCase):
|
|
|
17
31
|
|
|
18
32
|
async def testHasClass(self):
|
|
19
33
|
"""
|
|
20
|
-
|
|
34
|
+
Test class existence detection within the module.
|
|
35
|
+
|
|
36
|
+
Verifies that the hasClass method correctly identifies the presence
|
|
37
|
+
or absence of classes within the reflected module.
|
|
21
38
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
39
|
+
Raises
|
|
40
|
+
------
|
|
41
|
+
AssertionError
|
|
42
|
+
If the class existence check returns incorrect boolean values.
|
|
25
43
|
"""
|
|
26
44
|
reflection = ReflectionModule(self.module_name)
|
|
27
|
-
self.assertTrue(reflection.hasClass('PublicFakeClass'))
|
|
28
|
-
self.assertFalse(reflection.hasClass('NonExistentClass'))
|
|
45
|
+
self.assertTrue(reflection.hasClass('PublicFakeClass')) # Existing class should return True
|
|
46
|
+
self.assertFalse(reflection.hasClass('NonExistentClass')) # Non-existent class should return False
|
|
29
47
|
|
|
30
48
|
async def testGetClass(self):
|
|
31
49
|
"""
|
|
32
|
-
Test
|
|
50
|
+
Test class object retrieval by name.
|
|
33
51
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
52
|
+
Validates that the getClass method returns the correct class object
|
|
53
|
+
for existing classes and None for non-existent classes.
|
|
54
|
+
|
|
55
|
+
Raises
|
|
56
|
+
------
|
|
57
|
+
AssertionError
|
|
58
|
+
If the retrieved class object is incorrect or None when it should exist.
|
|
38
59
|
"""
|
|
39
60
|
reflection = ReflectionModule(self.module_name)
|
|
40
61
|
cls = reflection.getClass('PublicFakeClass')
|
|
41
|
-
self.assertIsNotNone(cls)
|
|
42
|
-
self.assertEqual(cls.__name__, 'PublicFakeClass')
|
|
43
|
-
self.assertIsNone(reflection.getClass('NonExistentClass'))
|
|
62
|
+
self.assertIsNotNone(cls) # Class should exist and be returned
|
|
63
|
+
self.assertEqual(cls.__name__, 'PublicFakeClass') # Class name should match
|
|
64
|
+
self.assertIsNone(reflection.getClass('NonExistentClass')) # Non-existent class should return None
|
|
44
65
|
|
|
45
66
|
async def testSetAndRemoveClass(self):
|
|
46
67
|
"""
|
|
47
|
-
Test
|
|
68
|
+
Test dynamic class registration and removal operations.
|
|
69
|
+
|
|
70
|
+
Validates the complete lifecycle of dynamically adding and removing
|
|
71
|
+
classes from the module through the ReflectionModule interface.
|
|
48
72
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- The class can be removed with removeClass.
|
|
54
|
-
- After removal, hasClass returns False for the class name.
|
|
73
|
+
Raises
|
|
74
|
+
------
|
|
75
|
+
AssertionError
|
|
76
|
+
If class registration, retrieval, or removal operations fail.
|
|
55
77
|
"""
|
|
56
78
|
reflection = ReflectionModule(self.module_name)
|
|
79
|
+
|
|
80
|
+
# Define a mock class for testing
|
|
57
81
|
class MockClass:
|
|
58
82
|
pass
|
|
83
|
+
|
|
84
|
+
# Test class registration
|
|
59
85
|
reflection.setClass('MockClass', MockClass)
|
|
60
|
-
self.assertTrue(reflection.hasClass('MockClass'))
|
|
61
|
-
self.assertEqual(reflection.getClass('MockClass'), MockClass)
|
|
86
|
+
self.assertTrue(reflection.hasClass('MockClass')) # Class should be registered
|
|
87
|
+
self.assertEqual(reflection.getClass('MockClass'), MockClass) # Retrieved class should match
|
|
88
|
+
|
|
89
|
+
# Test class removal
|
|
62
90
|
reflection.removeClass('MockClass')
|
|
63
|
-
self.assertFalse(reflection.hasClass('MockClass'))
|
|
91
|
+
self.assertFalse(reflection.hasClass('MockClass')) # Class should be removed
|
|
64
92
|
|
|
65
93
|
async def testSetClassInvalid(self):
|
|
66
94
|
"""
|
|
67
|
-
Test
|
|
68
|
-
|
|
95
|
+
Test error handling for invalid class registration attempts.
|
|
96
|
+
|
|
97
|
+
Validates that the setClass method properly raises ReflectionValueError
|
|
98
|
+
when provided with invalid class names or non-class objects.
|
|
69
99
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
100
|
+
Raises
|
|
101
|
+
------
|
|
102
|
+
AssertionError
|
|
103
|
+
If expected ReflectionValueError exceptions are not raised.
|
|
74
104
|
"""
|
|
75
105
|
reflection = ReflectionModule(self.module_name)
|
|
106
|
+
|
|
107
|
+
# Test invalid class name starting with digit
|
|
76
108
|
with self.assertRaises(ReflectionValueError):
|
|
77
109
|
reflection.setClass('123Invalid', object)
|
|
110
|
+
|
|
111
|
+
# Test reserved keyword as class name
|
|
78
112
|
with self.assertRaises(ReflectionValueError):
|
|
79
113
|
reflection.setClass('class', object)
|
|
114
|
+
|
|
115
|
+
# Test non-class object registration
|
|
80
116
|
with self.assertRaises(ReflectionValueError):
|
|
81
117
|
reflection.setClass('ValidName', 123)
|
|
82
118
|
|
|
83
119
|
async def testRemoveClassInvalid(self):
|
|
84
120
|
"""
|
|
85
|
-
Test
|
|
121
|
+
Test error handling for invalid class removal attempts.
|
|
86
122
|
|
|
87
|
-
|
|
88
|
-
|
|
123
|
+
Validates that the removeClass method properly raises ValueError
|
|
124
|
+
when attempting to remove a non-existent class from the module.
|
|
125
|
+
|
|
126
|
+
Raises
|
|
127
|
+
------
|
|
128
|
+
AssertionError
|
|
129
|
+
If the expected ValueError exception is not raised.
|
|
89
130
|
"""
|
|
90
131
|
reflection = ReflectionModule(self.module_name)
|
|
91
132
|
with self.assertRaises(ValueError):
|
|
@@ -93,304 +134,434 @@ class TestServiceReflectionModule(AsyncTestCase):
|
|
|
93
134
|
|
|
94
135
|
async def testInitClass(self):
|
|
95
136
|
"""
|
|
96
|
-
|
|
137
|
+
Test class instantiation through reflection.
|
|
138
|
+
|
|
139
|
+
Validates that the initClass method can successfully create instances
|
|
140
|
+
of existing classes and properly handles non-existent class errors.
|
|
97
141
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
142
|
+
Raises
|
|
143
|
+
------
|
|
144
|
+
AssertionError
|
|
145
|
+
If class instantiation fails or error handling is incorrect.
|
|
102
146
|
"""
|
|
103
147
|
reflection = ReflectionModule(self.module_name)
|
|
148
|
+
|
|
149
|
+
# Test successful class instantiation
|
|
104
150
|
instance = reflection.initClass('PublicFakeClass')
|
|
105
151
|
self.assertEqual(instance.__class__.__name__, 'PublicFakeClass')
|
|
152
|
+
|
|
153
|
+
# Test error handling for non-existent class
|
|
106
154
|
with self.assertRaises(ReflectionValueError):
|
|
107
155
|
reflection.initClass('NonExistentClass')
|
|
108
156
|
|
|
109
157
|
async def testGetClasses(self):
|
|
110
158
|
"""
|
|
111
|
-
Test
|
|
112
|
-
|
|
159
|
+
Test retrieval of all classes defined in the module.
|
|
160
|
+
|
|
161
|
+
Validates that the getClasses method returns a complete dictionary
|
|
162
|
+
of all class definitions including public, protected, and private classes.
|
|
163
|
+
|
|
164
|
+
Raises
|
|
165
|
+
------
|
|
166
|
+
AssertionError
|
|
167
|
+
If expected classes are not found in the returned dictionary.
|
|
113
168
|
"""
|
|
114
169
|
reflection = ReflectionModule(self.module_name)
|
|
115
170
|
classes = reflection.getClasses()
|
|
116
|
-
self.assertIn('PublicFakeClass', classes)
|
|
117
|
-
self.assertIn('_ProtectedFakeClass', classes)
|
|
118
|
-
self.assertIn('__PrivateFakeClass', classes)
|
|
171
|
+
self.assertIn('PublicFakeClass', classes) # Public class should be included
|
|
172
|
+
self.assertIn('_ProtectedFakeClass', classes) # Protected class should be included
|
|
173
|
+
self.assertIn('__PrivateFakeClass', classes) # Private class should be included
|
|
119
174
|
|
|
120
175
|
async def testGetPublicClasses(self):
|
|
121
176
|
"""
|
|
122
|
-
Test
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
177
|
+
Test retrieval of public classes only.
|
|
178
|
+
|
|
179
|
+
Validates that the getPublicClasses method returns only classes
|
|
180
|
+
with public visibility (not prefixed with underscores).
|
|
181
|
+
|
|
182
|
+
Raises
|
|
183
|
+
------
|
|
184
|
+
AssertionError
|
|
185
|
+
If protected or private classes are included or public classes are excluded.
|
|
126
186
|
"""
|
|
127
187
|
reflection = ReflectionModule(self.module_name)
|
|
128
188
|
public_classes = reflection.getPublicClasses()
|
|
129
|
-
self.assertIn('PublicFakeClass', public_classes)
|
|
130
|
-
self.assertNotIn('_ProtectedFakeClass', public_classes)
|
|
131
|
-
self.assertNotIn('__PrivateFakeClass', public_classes)
|
|
189
|
+
self.assertIn('PublicFakeClass', public_classes) # Public class should be included
|
|
190
|
+
self.assertNotIn('_ProtectedFakeClass', public_classes) # Protected class should be excluded
|
|
191
|
+
self.assertNotIn('__PrivateFakeClass', public_classes) # Private class should be excluded
|
|
132
192
|
|
|
133
193
|
async def testGetProtectedClasses(self):
|
|
134
194
|
"""
|
|
135
|
-
Test
|
|
195
|
+
Test retrieval of protected classes only.
|
|
196
|
+
|
|
197
|
+
Validates that the getProtectedClasses method returns only classes
|
|
198
|
+
with protected visibility (prefixed with single underscore).
|
|
136
199
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
200
|
+
Raises
|
|
201
|
+
------
|
|
202
|
+
AssertionError
|
|
203
|
+
If public or private classes are included or protected classes are excluded.
|
|
141
204
|
"""
|
|
142
205
|
reflection = ReflectionModule(self.module_name)
|
|
143
206
|
protected_classes = reflection.getProtectedClasses()
|
|
144
|
-
self.assertIn('_ProtectedFakeClass', protected_classes)
|
|
145
|
-
self.assertNotIn('PublicFakeClass', protected_classes)
|
|
207
|
+
self.assertIn('_ProtectedFakeClass', protected_classes) # Protected class should be included
|
|
208
|
+
self.assertNotIn('PublicFakeClass', protected_classes) # Public class should be excluded
|
|
146
209
|
|
|
147
210
|
async def testGetPrivateClasses(self):
|
|
148
211
|
"""
|
|
149
|
-
Test
|
|
212
|
+
Test retrieval of private classes only.
|
|
150
213
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
214
|
+
Validates that the getPrivateClasses method returns only classes
|
|
215
|
+
with private visibility (prefixed with double underscores, not ending with them).
|
|
216
|
+
|
|
217
|
+
Raises
|
|
218
|
+
------
|
|
219
|
+
AssertionError
|
|
220
|
+
If public or protected classes are included or private classes are excluded.
|
|
154
221
|
"""
|
|
155
222
|
reflection = ReflectionModule(self.module_name)
|
|
156
223
|
private_classes = reflection.getPrivateClasses()
|
|
157
|
-
self.assertIn('__PrivateFakeClass', private_classes)
|
|
158
|
-
self.assertNotIn('PublicFakeClass', private_classes)
|
|
224
|
+
self.assertIn('__PrivateFakeClass', private_classes) # Private class should be included
|
|
225
|
+
self.assertNotIn('PublicFakeClass', private_classes) # Public class should be excluded
|
|
159
226
|
|
|
160
227
|
async def testGetConstants(self):
|
|
161
228
|
"""
|
|
162
|
-
Test
|
|
163
|
-
|
|
229
|
+
Test retrieval of all constants defined in the module.
|
|
230
|
+
|
|
231
|
+
Validates that the getConstants method returns a complete dictionary
|
|
232
|
+
of all constant definitions including public, protected, and private constants.
|
|
164
233
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
234
|
+
Raises
|
|
235
|
+
------
|
|
236
|
+
AssertionError
|
|
237
|
+
If expected constants are not found in the returned dictionary.
|
|
169
238
|
"""
|
|
170
239
|
reflection = ReflectionModule(self.module_name)
|
|
171
240
|
consts = reflection.getConstants()
|
|
172
|
-
self.assertIn('PUBLIC_CONSTANT', consts)
|
|
173
|
-
self.assertIn('_PROTECTED_CONSTANT', consts)
|
|
174
|
-
self.assertIn('__PRIVATE_CONSTANT', consts)
|
|
241
|
+
self.assertIn('PUBLIC_CONSTANT', consts) # Public constant should be included
|
|
242
|
+
self.assertIn('_PROTECTED_CONSTANT', consts) # Protected constant should be included
|
|
243
|
+
self.assertIn('__PRIVATE_CONSTANT', consts) # Private constant should be included
|
|
175
244
|
|
|
176
245
|
async def testGetPublicConstants(self):
|
|
177
246
|
"""
|
|
178
|
-
Test
|
|
247
|
+
Test retrieval of public constants only.
|
|
248
|
+
|
|
249
|
+
Validates that the getPublicConstants method returns only constants
|
|
250
|
+
with public visibility (not prefixed with underscores).
|
|
179
251
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
252
|
+
Raises
|
|
253
|
+
------
|
|
254
|
+
AssertionError
|
|
255
|
+
If protected or private constants are included or public constants are excluded.
|
|
183
256
|
"""
|
|
184
257
|
reflection = ReflectionModule(self.module_name)
|
|
185
258
|
public_consts = reflection.getPublicConstants()
|
|
186
|
-
self.assertIn('PUBLIC_CONSTANT', public_consts)
|
|
187
|
-
self.assertNotIn('_PROTECTED_CONSTANT', public_consts)
|
|
188
|
-
self.assertNotIn('__PRIVATE_CONSTANT', public_consts)
|
|
259
|
+
self.assertIn('PUBLIC_CONSTANT', public_consts) # Public constant should be included
|
|
260
|
+
self.assertNotIn('_PROTECTED_CONSTANT', public_consts) # Protected constant should be excluded
|
|
261
|
+
self.assertNotIn('__PRIVATE_CONSTANT', public_consts) # Private constant should be excluded
|
|
189
262
|
|
|
190
263
|
async def testGetProtectedConstants(self):
|
|
191
264
|
"""
|
|
192
|
-
|
|
193
|
-
correctly retrieves protected constants (those prefixed with an underscore) from the module.
|
|
265
|
+
Test retrieval of protected constants only.
|
|
194
266
|
|
|
195
|
-
|
|
196
|
-
|
|
267
|
+
Validates that the getProtectedConstants method returns only constants
|
|
268
|
+
with protected visibility (prefixed with single underscore).
|
|
269
|
+
|
|
270
|
+
Raises
|
|
271
|
+
------
|
|
272
|
+
AssertionError
|
|
273
|
+
If public or private constants are included or protected constants are excluded.
|
|
197
274
|
"""
|
|
198
275
|
reflection = ReflectionModule(self.module_name)
|
|
199
276
|
protected_consts = reflection.getProtectedConstants()
|
|
200
|
-
self.assertIn('_PROTECTED_CONSTANT', protected_consts)
|
|
201
|
-
self.assertNotIn('PUBLIC_CONSTANT', protected_consts)
|
|
277
|
+
self.assertIn('_PROTECTED_CONSTANT', protected_consts) # Protected constant should be included
|
|
278
|
+
self.assertNotIn('PUBLIC_CONSTANT', protected_consts) # Public constant should be excluded
|
|
202
279
|
|
|
203
280
|
async def testGetPrivateConstants(self):
|
|
204
281
|
"""
|
|
205
|
-
Test
|
|
282
|
+
Test retrieval of private constants only.
|
|
283
|
+
|
|
284
|
+
Validates that the getPrivateConstants method returns only constants
|
|
285
|
+
with private visibility (prefixed with double underscores, not ending with them).
|
|
206
286
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
287
|
+
Raises
|
|
288
|
+
------
|
|
289
|
+
AssertionError
|
|
290
|
+
If public or protected constants are included or private constants are excluded.
|
|
210
291
|
"""
|
|
211
292
|
reflection = ReflectionModule(self.module_name)
|
|
212
293
|
private_consts = reflection.getPrivateConstants()
|
|
213
|
-
self.assertIn('__PRIVATE_CONSTANT', private_consts)
|
|
214
|
-
self.assertNotIn('PUBLIC_CONSTANT', private_consts)
|
|
294
|
+
self.assertIn('__PRIVATE_CONSTANT', private_consts) # Private constant should be included
|
|
295
|
+
self.assertNotIn('PUBLIC_CONSTANT', private_consts) # Public constant should be excluded
|
|
215
296
|
|
|
216
297
|
async def testGetConstant(self):
|
|
217
298
|
"""
|
|
218
|
-
Test
|
|
299
|
+
Test individual constant value retrieval by name.
|
|
219
300
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
301
|
+
Validates that the getConstant method returns the correct value
|
|
302
|
+
for existing constants and None for non-existent constants.
|
|
303
|
+
|
|
304
|
+
Raises
|
|
305
|
+
------
|
|
306
|
+
AssertionError
|
|
307
|
+
If the retrieved constant value is incorrect or None when it should exist.
|
|
223
308
|
"""
|
|
224
309
|
reflection = ReflectionModule(self.module_name)
|
|
225
310
|
value = reflection.getConstant('PUBLIC_CONSTANT')
|
|
226
|
-
self.assertEqual(value, 'public constant')
|
|
227
|
-
self.assertIsNone(reflection.getConstant('NON_EXISTENT_CONST'))
|
|
311
|
+
self.assertEqual(value, 'public constant') # Constant value should match expected
|
|
312
|
+
self.assertIsNone(reflection.getConstant('NON_EXISTENT_CONST')) # Non-existent constant should return None
|
|
228
313
|
|
|
229
314
|
async def testGetFunctions(self):
|
|
230
315
|
"""
|
|
231
|
-
Test
|
|
316
|
+
Test retrieval of all functions defined in the module.
|
|
317
|
+
|
|
318
|
+
Validates that the getFunctions method returns a complete dictionary
|
|
319
|
+
of all function definitions including public, protected, and private functions
|
|
320
|
+
of both synchronous and asynchronous types.
|
|
321
|
+
|
|
322
|
+
Raises
|
|
323
|
+
------
|
|
324
|
+
AssertionError
|
|
325
|
+
If expected functions are not found in the returned dictionary.
|
|
232
326
|
"""
|
|
233
327
|
reflection = ReflectionModule(self.module_name)
|
|
234
328
|
funcs = reflection.getFunctions()
|
|
235
|
-
|
|
236
|
-
self.assertIn('
|
|
237
|
-
self.assertIn('
|
|
238
|
-
|
|
239
|
-
self.assertIn('
|
|
240
|
-
self.assertIn('
|
|
329
|
+
# Test public functions
|
|
330
|
+
self.assertIn('publicSyncFunction', funcs) # Public sync function should be included
|
|
331
|
+
self.assertIn('publicAsyncFunction', funcs) # Public async function should be included
|
|
332
|
+
# Test protected functions
|
|
333
|
+
self.assertIn('_protectedSyncFunction', funcs) # Protected sync function should be included
|
|
334
|
+
self.assertIn('_protectedAsyncFunction', funcs) # Protected async function should be included
|
|
335
|
+
# Test private functions
|
|
336
|
+
self.assertIn('__privateSyncFunction', funcs) # Private sync function should be included
|
|
337
|
+
self.assertIn('__privateAsyncFunction', funcs) # Private async function should be included
|
|
241
338
|
|
|
242
339
|
async def testGetPublicFunctions(self):
|
|
243
340
|
"""
|
|
244
|
-
Test
|
|
341
|
+
Test retrieval of public functions only.
|
|
342
|
+
|
|
343
|
+
Validates that the getPublicFunctions method returns only functions
|
|
344
|
+
with public visibility (not prefixed with underscores) including
|
|
345
|
+
both synchronous and asynchronous functions.
|
|
245
346
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
347
|
+
Raises
|
|
348
|
+
------
|
|
349
|
+
AssertionError
|
|
350
|
+
If protected or private functions are included or public functions are excluded.
|
|
249
351
|
"""
|
|
250
352
|
reflection = ReflectionModule(self.module_name)
|
|
251
353
|
public_funcs = reflection.getPublicFunctions()
|
|
252
|
-
self.assertIn('publicSyncFunction', public_funcs)
|
|
253
|
-
self.assertIn('publicAsyncFunction', public_funcs)
|
|
254
|
-
self.assertNotIn('_protectedSyncFunction', public_funcs)
|
|
255
|
-
self.assertNotIn('__privateSyncFunction', public_funcs)
|
|
354
|
+
self.assertIn('publicSyncFunction', public_funcs) # Public sync function should be included
|
|
355
|
+
self.assertIn('publicAsyncFunction', public_funcs) # Public async function should be included
|
|
356
|
+
self.assertNotIn('_protectedSyncFunction', public_funcs) # Protected function should be excluded
|
|
357
|
+
self.assertNotIn('__privateSyncFunction', public_funcs) # Private function should be excluded
|
|
256
358
|
|
|
257
359
|
async def testGetPublicSyncFunctions(self):
|
|
258
360
|
"""
|
|
259
|
-
Test
|
|
361
|
+
Test retrieval of public synchronous functions only.
|
|
362
|
+
|
|
363
|
+
Validates that the getPublicSyncFunctions method returns only functions
|
|
364
|
+
with public visibility that are synchronous (non-async).
|
|
260
365
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
366
|
+
Raises
|
|
367
|
+
------
|
|
368
|
+
AssertionError
|
|
369
|
+
If asynchronous functions are included or synchronous public functions are excluded.
|
|
264
370
|
"""
|
|
265
371
|
reflection = ReflectionModule(self.module_name)
|
|
266
372
|
sync_funcs = reflection.getPublicSyncFunctions()
|
|
267
|
-
self.assertIn('publicSyncFunction', sync_funcs)
|
|
268
|
-
self.assertNotIn('publicAsyncFunction', sync_funcs)
|
|
373
|
+
self.assertIn('publicSyncFunction', sync_funcs) # Public sync function should be included
|
|
374
|
+
self.assertNotIn('publicAsyncFunction', sync_funcs) # Public async function should be excluded
|
|
269
375
|
|
|
270
376
|
async def testGetPublicAsyncFunctions(self):
|
|
271
377
|
"""
|
|
272
|
-
Test
|
|
273
|
-
|
|
378
|
+
Test retrieval of public asynchronous functions only.
|
|
379
|
+
|
|
380
|
+
Validates that the getPublicAsyncFunctions method returns only functions
|
|
381
|
+
with public visibility that are asynchronous (async def).
|
|
382
|
+
|
|
383
|
+
Raises
|
|
384
|
+
------
|
|
385
|
+
AssertionError
|
|
386
|
+
If synchronous functions are included or asynchronous public functions are excluded.
|
|
274
387
|
"""
|
|
275
388
|
reflection = ReflectionModule(self.module_name)
|
|
276
389
|
async_funcs = reflection.getPublicAsyncFunctions()
|
|
277
|
-
self.assertIn('publicAsyncFunction', async_funcs)
|
|
278
|
-
self.assertNotIn('publicSyncFunction', async_funcs)
|
|
390
|
+
self.assertIn('publicAsyncFunction', async_funcs) # Public async function should be included
|
|
391
|
+
self.assertNotIn('publicSyncFunction', async_funcs) # Public sync function should be excluded
|
|
279
392
|
|
|
280
393
|
async def testGetProtectedFunctions(self):
|
|
281
394
|
"""
|
|
282
|
-
Test
|
|
395
|
+
Test retrieval of protected functions only.
|
|
396
|
+
|
|
397
|
+
Validates that the getProtectedFunctions method returns only functions
|
|
398
|
+
with protected visibility (prefixed with single underscore) including
|
|
399
|
+
both synchronous and asynchronous functions.
|
|
283
400
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
401
|
+
Raises
|
|
402
|
+
------
|
|
403
|
+
AssertionError
|
|
404
|
+
If public functions are included or protected functions are excluded.
|
|
287
405
|
"""
|
|
288
406
|
reflection = ReflectionModule(self.module_name)
|
|
289
407
|
protected_funcs = reflection.getProtectedFunctions()
|
|
290
|
-
self.assertIn('_protectedSyncFunction', protected_funcs)
|
|
291
|
-
self.assertIn('_protectedAsyncFunction', protected_funcs)
|
|
292
|
-
self.assertNotIn('publicSyncFunction', protected_funcs)
|
|
408
|
+
self.assertIn('_protectedSyncFunction', protected_funcs) # Protected sync function should be included
|
|
409
|
+
self.assertIn('_protectedAsyncFunction', protected_funcs) # Protected async function should be included
|
|
410
|
+
self.assertNotIn('publicSyncFunction', protected_funcs) # Public function should be excluded
|
|
293
411
|
|
|
294
412
|
async def testGetProtectedSyncFunctions(self):
|
|
295
413
|
"""
|
|
296
|
-
Test
|
|
297
|
-
|
|
298
|
-
|
|
414
|
+
Test retrieval of protected synchronous functions only.
|
|
415
|
+
|
|
416
|
+
Validates that the getProtectedSyncFunctions method returns only functions
|
|
417
|
+
with protected visibility that are synchronous (non-async).
|
|
418
|
+
|
|
419
|
+
Raises
|
|
420
|
+
------
|
|
421
|
+
AssertionError
|
|
422
|
+
If asynchronous functions are included or synchronous protected functions are excluded.
|
|
299
423
|
"""
|
|
300
424
|
reflection = ReflectionModule(self.module_name)
|
|
301
425
|
sync_funcs = reflection.getProtectedSyncFunctions()
|
|
302
|
-
self.assertIn('_protectedSyncFunction', sync_funcs)
|
|
303
|
-
self.assertNotIn('_protectedAsyncFunction', sync_funcs)
|
|
426
|
+
self.assertIn('_protectedSyncFunction', sync_funcs) # Protected sync function should be included
|
|
427
|
+
self.assertNotIn('_protectedAsyncFunction', sync_funcs) # Protected async function should be excluded
|
|
304
428
|
|
|
305
429
|
async def testGetProtectedAsyncFunctions(self):
|
|
306
430
|
"""
|
|
307
|
-
Test
|
|
431
|
+
Test retrieval of protected asynchronous functions only.
|
|
432
|
+
|
|
433
|
+
Validates that the getProtectedAsyncFunctions method returns only functions
|
|
434
|
+
with protected visibility that are asynchronous (async def).
|
|
308
435
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
436
|
+
Raises
|
|
437
|
+
------
|
|
438
|
+
AssertionError
|
|
439
|
+
If synchronous functions are included or asynchronous protected functions are excluded.
|
|
312
440
|
"""
|
|
313
441
|
reflection = ReflectionModule(self.module_name)
|
|
314
442
|
async_funcs = reflection.getProtectedAsyncFunctions()
|
|
315
|
-
self.assertIn('_protectedAsyncFunction', async_funcs)
|
|
316
|
-
self.assertNotIn('_protectedSyncFunction', async_funcs)
|
|
443
|
+
self.assertIn('_protectedAsyncFunction', async_funcs) # Protected async function should be included
|
|
444
|
+
self.assertNotIn('_protectedSyncFunction', async_funcs) # Protected sync function should be excluded
|
|
317
445
|
|
|
318
446
|
async def testGetPrivateFunctions(self):
|
|
319
447
|
"""
|
|
320
|
-
Test
|
|
448
|
+
Test retrieval of private functions only.
|
|
321
449
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
450
|
+
Validates that the getPrivateFunctions method returns only functions
|
|
451
|
+
with private visibility (prefixed with double underscores, not ending with them)
|
|
452
|
+
including both synchronous and asynchronous functions.
|
|
453
|
+
|
|
454
|
+
Raises
|
|
455
|
+
------
|
|
456
|
+
AssertionError
|
|
457
|
+
If public functions are included or private functions are excluded.
|
|
325
458
|
"""
|
|
326
459
|
reflection = ReflectionModule(self.module_name)
|
|
327
460
|
private_funcs = reflection.getPrivateFunctions()
|
|
328
|
-
self.assertIn('__privateSyncFunction', private_funcs)
|
|
329
|
-
self.assertIn('__privateAsyncFunction', private_funcs)
|
|
330
|
-
self.assertNotIn('publicSyncFunction', private_funcs)
|
|
461
|
+
self.assertIn('__privateSyncFunction', private_funcs) # Private sync function should be included
|
|
462
|
+
self.assertIn('__privateAsyncFunction', private_funcs) # Private async function should be included
|
|
463
|
+
self.assertNotIn('publicSyncFunction', private_funcs) # Public function should be excluded
|
|
331
464
|
|
|
332
465
|
async def testGetPrivateSyncFunctions(self):
|
|
333
466
|
"""
|
|
334
|
-
Test
|
|
335
|
-
|
|
336
|
-
|
|
467
|
+
Test retrieval of private synchronous functions only.
|
|
468
|
+
|
|
469
|
+
Validates that the getPrivateSyncFunctions method returns only functions
|
|
470
|
+
with private visibility that are synchronous (non-async).
|
|
471
|
+
|
|
472
|
+
Raises
|
|
473
|
+
------
|
|
474
|
+
AssertionError
|
|
475
|
+
If asynchronous functions are included or synchronous private functions are excluded.
|
|
337
476
|
"""
|
|
338
477
|
reflection = ReflectionModule(self.module_name)
|
|
339
478
|
sync_funcs = reflection.getPrivateSyncFunctions()
|
|
340
|
-
self.assertIn('__privateSyncFunction', sync_funcs)
|
|
341
|
-
self.assertNotIn('__privateAsyncFunction', sync_funcs)
|
|
479
|
+
self.assertIn('__privateSyncFunction', sync_funcs) # Private sync function should be included
|
|
480
|
+
self.assertNotIn('__privateAsyncFunction', sync_funcs) # Private async function should be excluded
|
|
342
481
|
|
|
343
482
|
async def testGetPrivateAsyncFunctions(self):
|
|
344
483
|
"""
|
|
345
|
-
|
|
484
|
+
Test retrieval of private asynchronous functions only.
|
|
346
485
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
486
|
+
Validates that the getPrivateAsyncFunctions method returns only functions
|
|
487
|
+
with private visibility that are asynchronous (async def).
|
|
488
|
+
|
|
489
|
+
Raises
|
|
490
|
+
------
|
|
491
|
+
AssertionError
|
|
492
|
+
If synchronous functions are included or asynchronous private functions are excluded.
|
|
350
493
|
"""
|
|
351
494
|
reflection = ReflectionModule(self.module_name)
|
|
352
495
|
async_funcs = reflection.getPrivateAsyncFunctions()
|
|
353
|
-
self.assertIn('__privateAsyncFunction', async_funcs)
|
|
354
|
-
self.assertNotIn('__privateSyncFunction', async_funcs)
|
|
496
|
+
self.assertIn('__privateAsyncFunction', async_funcs) # Private async function should be included
|
|
497
|
+
self.assertNotIn('__privateSyncFunction', async_funcs) # Private sync function should be excluded
|
|
355
498
|
|
|
356
499
|
async def testGetImports(self):
|
|
357
500
|
"""
|
|
358
|
-
Test
|
|
359
|
-
|
|
501
|
+
Test retrieval of imported modules within the reflected module.
|
|
502
|
+
|
|
503
|
+
Validates that the getImports method correctly identifies and returns
|
|
504
|
+
all imported module objects from the module's namespace.
|
|
505
|
+
|
|
506
|
+
Raises
|
|
507
|
+
------
|
|
508
|
+
AssertionError
|
|
509
|
+
If expected imported modules are not found in the returned dictionary.
|
|
360
510
|
"""
|
|
361
511
|
reflection = ReflectionModule(self.module_name)
|
|
362
512
|
imports = reflection.getImports()
|
|
363
|
-
self.assertIn('asyncio', imports)
|
|
513
|
+
self.assertIn('asyncio', imports) # asyncio module should be imported
|
|
364
514
|
|
|
365
515
|
async def testGetFile(self):
|
|
366
516
|
"""
|
|
367
|
-
|
|
517
|
+
Test retrieval of the module's file path.
|
|
368
518
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
519
|
+
Validates that the getFile method returns the correct absolute path
|
|
520
|
+
to the module's source file.
|
|
521
|
+
|
|
522
|
+
Raises
|
|
523
|
+
------
|
|
524
|
+
AssertionError
|
|
525
|
+
If the returned file path does not end with the expected filename.
|
|
372
526
|
"""
|
|
373
527
|
reflection = ReflectionModule(self.module_name)
|
|
374
528
|
file_path = reflection.getFile()
|
|
375
|
-
self.assertTrue(file_path.endswith('fake_reflect_instance.py'))
|
|
529
|
+
self.assertTrue(file_path.endswith('fake_reflect_instance.py')) # Path should end with expected filename
|
|
376
530
|
|
|
377
531
|
async def testGetSourceCode(self):
|
|
378
532
|
"""
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
533
|
+
Test retrieval of the module's complete source code.
|
|
534
|
+
|
|
535
|
+
Validates that the getSourceCode method returns the entire source code
|
|
536
|
+
content of the module file and contains expected code elements.
|
|
537
|
+
|
|
538
|
+
Raises
|
|
539
|
+
------
|
|
540
|
+
AssertionError
|
|
541
|
+
If expected code elements are not found in the returned source code.
|
|
382
542
|
"""
|
|
383
543
|
reflection = ReflectionModule(self.module_name)
|
|
384
544
|
code = reflection.getSourceCode()
|
|
385
|
-
self.assertIn('PUBLIC_CONSTANT', code)
|
|
386
|
-
self.assertIn('def publicSyncFunction', code)
|
|
545
|
+
self.assertIn('PUBLIC_CONSTANT', code) # Constant should be present in source
|
|
546
|
+
self.assertIn('def publicSyncFunction', code) # Function definition should be present in source
|
|
387
547
|
|
|
388
548
|
async def test_invalid_module_name(self):
|
|
389
549
|
"""
|
|
390
|
-
Test
|
|
391
|
-
|
|
550
|
+
Test error handling for invalid module initialization.
|
|
551
|
+
|
|
552
|
+
Validates that ReflectionModule properly raises ReflectionTypeError
|
|
553
|
+
when initialized with invalid module names such as empty strings
|
|
554
|
+
or non-existent module paths.
|
|
555
|
+
|
|
556
|
+
Raises
|
|
557
|
+
------
|
|
558
|
+
AssertionError
|
|
559
|
+
If expected ReflectionTypeError exceptions are not raised.
|
|
392
560
|
"""
|
|
561
|
+
# Test empty string module name
|
|
393
562
|
with self.assertRaises(ReflectionTypeError):
|
|
394
563
|
ReflectionModule('')
|
|
564
|
+
|
|
565
|
+
# Test non-existent module path
|
|
395
566
|
with self.assertRaises(ReflectionTypeError):
|
|
396
567
|
ReflectionModule('nonexistent.module.name')
|