orionis 0.306.0__py3-none-any.whl → 0.307.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/metadata/framework.py +1 -1
- orionis/services/introspection/abstract/contracts/reflection_abstract.py +1 -1
- orionis/services/introspection/abstract/reflection_abstract.py +1 -1
- orionis/services/introspection/concretes/contracts/reflection_concrete.py +2 -2
- orionis/services/introspection/concretes/reflection_concrete.py +2 -4
- orionis/services/introspection/instances/contracts/reflection_instance.py +2 -2
- orionis/services/introspection/instances/reflection_instance.py +2 -2
- {orionis-0.306.0.dist-info → orionis-0.307.0.dist-info}/METADATA +1 -1
- {orionis-0.306.0.dist-info → orionis-0.307.0.dist-info}/RECORD +18 -14
- tests/services/inspection/reflection/mock/fake_reflect_instance.py +18 -3
- tests/services/inspection/reflection/test_reflection_abstract.py +588 -0
- tests/services/inspection/reflection/test_reflection_concrete.py +842 -0
- tests/services/inspection/reflection/test_reflection_instance.py +888 -0
- tests/services/inspection/reflection/test_reflection_module.py +397 -0
- {orionis-0.306.0.dist-info → orionis-0.307.0.dist-info}/WHEEL +0 -0
- {orionis-0.306.0.dist-info → orionis-0.307.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.306.0.dist-info → orionis-0.307.0.dist-info}/top_level.txt +0 -0
- {orionis-0.306.0.dist-info → orionis-0.307.0.dist-info}/zip-safe +0 -0
@@ -0,0 +1,888 @@
|
|
1
|
+
from orionis.services.introspection.dependencies.entities.class_dependencies import ClassDependency
|
2
|
+
from tests.services.inspection.reflection.mock.fake_reflect_instance import FakeClass
|
3
|
+
from orionis.services.introspection.instances.reflection_instance import ReflectionInstance
|
4
|
+
from orionis.unittesting import TestCase
|
5
|
+
|
6
|
+
class TestServiceReflectionInstance(TestCase):
|
7
|
+
|
8
|
+
async def testGetInstance(self):
|
9
|
+
"""
|
10
|
+
Tests that the ReflectionInstance.getInstance() method returns an instance of the expected class.
|
11
|
+
This test creates a ReflectionInstance with a FakeClass object, retrieves the instance using getInstance(),
|
12
|
+
and asserts that the returned object is an instance of FakeClass.
|
13
|
+
"""
|
14
|
+
reflect = ReflectionInstance(FakeClass())
|
15
|
+
instance = reflect.getInstance()
|
16
|
+
self.assertIsInstance(instance, FakeClass)
|
17
|
+
|
18
|
+
async def testGetClass(self):
|
19
|
+
"""
|
20
|
+
Tests that the `getClass` method of `ReflectionInstance` returns the correct class type
|
21
|
+
for the given instance.
|
22
|
+
This test creates a `ReflectionInstance` with an instance of `FakeClass`, calls `getClass`,
|
23
|
+
and asserts that the returned class is `FakeClass`.
|
24
|
+
"""
|
25
|
+
reflect = ReflectionInstance(FakeClass())
|
26
|
+
cls = reflect.getClass()
|
27
|
+
self.assertEqual(cls, FakeClass)
|
28
|
+
|
29
|
+
async def testGetClassName(self):
|
30
|
+
"""
|
31
|
+
Tests that the ReflectionInstance correctly retrieves the class name of the given object.
|
32
|
+
This test creates an instance of FakeClass, wraps it with ReflectionInstance,
|
33
|
+
and asserts that getClassName() returns the expected class name 'FakeClass'.
|
34
|
+
"""
|
35
|
+
reflect = ReflectionInstance(FakeClass())
|
36
|
+
class_name = reflect.getClassName()
|
37
|
+
self.assertEqual(class_name, 'FakeClass')
|
38
|
+
|
39
|
+
async def testGetModuleName(self):
|
40
|
+
"""
|
41
|
+
Tests that the `getModuleName` method of `ReflectionInstance` returns the correct module name
|
42
|
+
for the provided `FakeClass` instance.
|
43
|
+
|
44
|
+
Asserts:
|
45
|
+
The returned module name matches the expected string
|
46
|
+
'tests.services.inspection.reflection.mock.fake_reflect_instance'.
|
47
|
+
"""
|
48
|
+
reflect = ReflectionInstance(FakeClass())
|
49
|
+
module_name = reflect.getModuleName()
|
50
|
+
self.assertEqual(module_name, 'tests.services.inspection.reflection.mock.fake_reflect_instance')
|
51
|
+
|
52
|
+
async def testGetModuleWithClassName(self):
|
53
|
+
"""
|
54
|
+
Tests that the getModuleWithClassName method of ReflectionInstance returns the fully qualified
|
55
|
+
module and class name of the provided instance.
|
56
|
+
|
57
|
+
Asserts:
|
58
|
+
The returned string matches the expected module and class path for FakeClass.
|
59
|
+
"""
|
60
|
+
reflect = ReflectionInstance(FakeClass())
|
61
|
+
module_with_class_name = reflect.getModuleWithClassName()
|
62
|
+
self.assertEqual(module_with_class_name, 'tests.services.inspection.reflection.mock.fake_reflect_instance.FakeClass')
|
63
|
+
|
64
|
+
async def testGetDocstring(self):
|
65
|
+
"""
|
66
|
+
Test that the getDocstring method of ReflectionInstance returns the correct docstring
|
67
|
+
for the provided class instance.
|
68
|
+
"""
|
69
|
+
reflect = ReflectionInstance(FakeClass())
|
70
|
+
docstring = reflect.getDocstring()
|
71
|
+
self.assertEqual(docstring, FakeClass.__doc__)
|
72
|
+
|
73
|
+
async def testGetBaseClasses(self):
|
74
|
+
"""
|
75
|
+
Tests that the getBaseClasses method of ReflectionInstance correctly retrieves
|
76
|
+
the base classes of the provided instance.
|
77
|
+
|
78
|
+
This test creates a ReflectionInstance for a FakeClass object, calls getBaseClasses,
|
79
|
+
and asserts that FakeClass's immediate base class is included in the returned list.
|
80
|
+
"""
|
81
|
+
reflect = ReflectionInstance(FakeClass())
|
82
|
+
base_classes = reflect.getBaseClasses()
|
83
|
+
self.assertIn(FakeClass.__base__, base_classes)
|
84
|
+
|
85
|
+
async def testGetSourceCode(self):
|
86
|
+
"""
|
87
|
+
Tests that the `getSourceCode` method of `ReflectionInstance` correctly retrieves
|
88
|
+
the source code of the provided class instance. Asserts that the returned source
|
89
|
+
code starts with the expected class definition.
|
90
|
+
"""
|
91
|
+
reflect = ReflectionInstance(FakeClass())
|
92
|
+
source_code = reflect.getSourceCode()
|
93
|
+
self.assertTrue(source_code.startswith('class FakeClass'))
|
94
|
+
|
95
|
+
async def testGetFile(self):
|
96
|
+
"""
|
97
|
+
Tests that the `getFile` method of `ReflectionInstance` returns the correct file path
|
98
|
+
for the given instance. Asserts that the returned file path ends with 'fake_reflect_instance.py'.
|
99
|
+
"""
|
100
|
+
reflect = ReflectionInstance(FakeClass())
|
101
|
+
file_path = reflect.getFile()
|
102
|
+
self.assertTrue(file_path.endswith('fake_reflect_instance.py'))
|
103
|
+
|
104
|
+
async def testGetAnnotations(self):
|
105
|
+
"""
|
106
|
+
Test that the ReflectionInstance.getAnnotations() method returns the correct annotations
|
107
|
+
for the given FakeClass instance, specifically verifying that 'public_attr' is present
|
108
|
+
in the returned annotations.
|
109
|
+
"""
|
110
|
+
reflect = ReflectionInstance(FakeClass())
|
111
|
+
annotations = reflect.getAnnotations()
|
112
|
+
self.assertIn('public_attr', annotations)
|
113
|
+
|
114
|
+
async def testHasAttribute(self):
|
115
|
+
"""
|
116
|
+
Tests the hasAttribute method of the ReflectionInstance class.
|
117
|
+
|
118
|
+
Verifies that hasAttribute returns True for an existing attribute ('public_attr')
|
119
|
+
and False for a non-existent attribute ('non_existent_attr') on a FakeClass instance.
|
120
|
+
"""
|
121
|
+
reflect = ReflectionInstance(FakeClass())
|
122
|
+
self.assertTrue(reflect.hasAttribute('public_attr'))
|
123
|
+
self.assertFalse(reflect.hasAttribute('non_existent_attr'))
|
124
|
+
|
125
|
+
async def testGetAttribute(self):
|
126
|
+
"""
|
127
|
+
Tests the `getAttribute` method of the `ReflectionInstance` class.
|
128
|
+
|
129
|
+
Verifies that:
|
130
|
+
- Retrieving an existing attribute ('public_attr') returns its correct value (42).
|
131
|
+
- Retrieving a non-existent attribute ('non_existent_attr') returns None.
|
132
|
+
"""
|
133
|
+
reflect = ReflectionInstance(FakeClass())
|
134
|
+
self.assertEqual(reflect.getAttribute('public_attr'), 42)
|
135
|
+
self.assertIsNone(reflect.getAttribute('non_existent_attr'))
|
136
|
+
|
137
|
+
async def testSetAttribute(self):
|
138
|
+
"""
|
139
|
+
Test the setAttribute method of the ReflectionInstance class.
|
140
|
+
|
141
|
+
This test verifies that setAttribute correctly sets the value of attributes
|
142
|
+
on the wrapped object, including public, protected, and private attributes.
|
143
|
+
It also checks that the updated values can be retrieved using getAttribute.
|
144
|
+
|
145
|
+
Assertions:
|
146
|
+
- setAttribute returns True when setting a public attribute.
|
147
|
+
- The value of the public attribute is updated correctly.
|
148
|
+
- setAttribute returns True when setting a protected attribute.
|
149
|
+
- The value of the protected attribute is updated correctly.
|
150
|
+
- setAttribute returns True when setting a private attribute.
|
151
|
+
- The value of the private attribute is updated correctly.
|
152
|
+
"""
|
153
|
+
reflect = ReflectionInstance(FakeClass())
|
154
|
+
self.assertTrue(reflect.setAttribute('name', 'Orionis Framework'))
|
155
|
+
self.assertEqual(reflect.getAttribute('name'), 'Orionis Framework')
|
156
|
+
self.assertTrue(reflect.setAttribute('_version', '1.x'))
|
157
|
+
self.assertEqual(reflect.getAttribute('_version'), '1.x')
|
158
|
+
self.assertTrue(reflect.setAttribute('__python', '3.13+'))
|
159
|
+
self.assertEqual(reflect.getAttribute('__python'), '3.13+')
|
160
|
+
|
161
|
+
async def testRemoveAttribute(self):
|
162
|
+
"""
|
163
|
+
Test that the removeAttribute method successfully removes an attribute from the reflected instance.
|
164
|
+
Verifies that the attribute is removed and no longer present after removal.
|
165
|
+
"""
|
166
|
+
reflect = ReflectionInstance(FakeClass())
|
167
|
+
reflect.setAttribute('new_attr', 100)
|
168
|
+
self.assertTrue(reflect.removeAttribute('new_attr'))
|
169
|
+
self.assertFalse(reflect.hasAttribute('new_attr'))
|
170
|
+
|
171
|
+
async def testGetAttributes(self):
|
172
|
+
"""
|
173
|
+
Tests that the ReflectionInstance.getAttributes() method correctly retrieves
|
174
|
+
all attribute names from an instance of FakeClass, including public, protected,
|
175
|
+
and private attributes.
|
176
|
+
"""
|
177
|
+
reflect = ReflectionInstance(FakeClass())
|
178
|
+
attributes = reflect.getAttributes()
|
179
|
+
self.assertIn('public_attr', attributes)
|
180
|
+
self.assertIn('_protected_attr', attributes)
|
181
|
+
self.assertIn('__private_attr', attributes)
|
182
|
+
|
183
|
+
async def testGetPublicAttributes(self):
|
184
|
+
"""
|
185
|
+
Test that ReflectionInstance.getPublicAttributes() returns only public attributes of a class instance.
|
186
|
+
|
187
|
+
This test verifies that:
|
188
|
+
- Public attributes (e.g., 'public_attr') are included in the returned list.
|
189
|
+
- Protected attributes (e.g., '_protected_attr') are not included.
|
190
|
+
- Private attributes (e.g., '__private_attr') are not included.
|
191
|
+
"""
|
192
|
+
reflect = ReflectionInstance(FakeClass())
|
193
|
+
public_attributes = reflect.getPublicAttributes()
|
194
|
+
self.assertIn('public_attr', public_attributes)
|
195
|
+
self.assertNotIn('_protected_attr', public_attributes)
|
196
|
+
self.assertNotIn('__private_attr', public_attributes)
|
197
|
+
|
198
|
+
async def testGetProtectedAttributes(self):
|
199
|
+
"""
|
200
|
+
Test that ReflectionInstance.getProtectedAttributes() correctly identifies protected attributes.
|
201
|
+
|
202
|
+
This test verifies that:
|
203
|
+
- Protected attributes (those prefixed with a single underscore) are included in the result.
|
204
|
+
- Public attributes are not included.
|
205
|
+
- Private attributes (those prefixed with double underscores) are not included.
|
206
|
+
"""
|
207
|
+
reflect = ReflectionInstance(FakeClass())
|
208
|
+
protected_attributes = reflect.getProtectedAttributes()
|
209
|
+
self.assertIn('_protected_attr', protected_attributes)
|
210
|
+
self.assertNotIn('public_attr', protected_attributes)
|
211
|
+
self.assertNotIn('__private_attr', protected_attributes)
|
212
|
+
|
213
|
+
async def testGetPrivateAttributes(self):
|
214
|
+
"""
|
215
|
+
Test that the `getPrivateAttributes` method of `ReflectionInstance` correctly identifies and returns only the private attributes of a class instance.
|
216
|
+
|
217
|
+
This test verifies that:
|
218
|
+
- The private attribute (`__private_attr`) is included in the returned list.
|
219
|
+
- The public attribute (`public_attr`) is not included.
|
220
|
+
- The protected attribute (`_protected_attr`) is not included.
|
221
|
+
"""
|
222
|
+
reflect = ReflectionInstance(FakeClass())
|
223
|
+
private_attributes = reflect.getPrivateAttributes()
|
224
|
+
self.assertIn('__private_attr', private_attributes)
|
225
|
+
self.assertNotIn('public_attr', private_attributes)
|
226
|
+
self.assertNotIn('_protected_attr', private_attributes)
|
227
|
+
|
228
|
+
async def testGetDunderAttributes(self):
|
229
|
+
"""
|
230
|
+
Tests that the getDunderAttributes method of ReflectionInstance correctly retrieves
|
231
|
+
all double underscore (dunder) attributes from an instance of FakeClass.
|
232
|
+
|
233
|
+
Asserts that the attribute '__dd__' is present in the returned list of dunder attributes.
|
234
|
+
"""
|
235
|
+
reflect = ReflectionInstance(FakeClass())
|
236
|
+
dunder_attributes = reflect.getDunderAttributes()
|
237
|
+
self.assertIn('__dd__', dunder_attributes)
|
238
|
+
|
239
|
+
async def testGetMagicAttributes(self):
|
240
|
+
"""
|
241
|
+
Tests that the `getMagicAttributes` method of `ReflectionInstance` returns a list of magic attributes
|
242
|
+
for the given instance, and verifies that the attribute '__dd__' is present in the result.
|
243
|
+
"""
|
244
|
+
reflect = ReflectionInstance(FakeClass())
|
245
|
+
magic_attributes = reflect.getMagicAttributes()
|
246
|
+
self.assertIn('__dd__', magic_attributes)
|
247
|
+
|
248
|
+
async def testHasMethod(self):
|
249
|
+
"""
|
250
|
+
Tests the hasMethod function of the ReflectionInstance class.
|
251
|
+
|
252
|
+
Verifies that hasMethod correctly identifies the presence or absence of a method
|
253
|
+
on the provided FakeClass instance. Asserts that 'instanceSyncMethod' exists and
|
254
|
+
'non_existent_method' does not.
|
255
|
+
"""
|
256
|
+
reflect = ReflectionInstance(FakeClass())
|
257
|
+
self.assertTrue(reflect.hasMethod('instanceSyncMethod'))
|
258
|
+
self.assertFalse(reflect.hasMethod('non_existent_method'))
|
259
|
+
|
260
|
+
async def testCallMethod(self):
|
261
|
+
"""
|
262
|
+
Tests the callMethod function of the ReflectionInstance class.
|
263
|
+
|
264
|
+
This test verifies that calling the 'instanceSyncMethod' on a FakeClass instance
|
265
|
+
via ReflectionInstance.callMethod with arguments 2 and 3 returns the expected result (5).
|
266
|
+
"""
|
267
|
+
reflect = ReflectionInstance(FakeClass())
|
268
|
+
result = reflect.callMethod('instanceSyncMethod', 2, 3)
|
269
|
+
self.assertEqual(result, 5)
|
270
|
+
|
271
|
+
async def testCallAsyncMethod(self):
|
272
|
+
"""
|
273
|
+
Tests that the ReflectionInstance can correctly call an asynchronous method on an instance
|
274
|
+
and return the expected result.
|
275
|
+
|
276
|
+
This test creates a ReflectionInstance for a FakeClass object, invokes the 'instanceAsyncMethod'
|
277
|
+
asynchronously with arguments 2 and 3, and asserts that the result is 5.
|
278
|
+
"""
|
279
|
+
reflect = ReflectionInstance(FakeClass())
|
280
|
+
result = await reflect.callMethod('instanceAsyncMethod', 2, 3)
|
281
|
+
self.assertEqual(result, 5)
|
282
|
+
|
283
|
+
async def testSetMethod(self):
|
284
|
+
"""
|
285
|
+
Tests the ability of ReflectionInstance to set and call both synchronous and asynchronous methods dynamically.
|
286
|
+
This test:
|
287
|
+
- Defines a synchronous and an asynchronous mock method.
|
288
|
+
- Sets these methods on a ReflectionInstance of FakeClass using setMethod.
|
289
|
+
- Calls the synchronous method using callMethod and checks the result.
|
290
|
+
- Calls the asynchronous method using await callMethod and checks the result.
|
291
|
+
- Asserts that both methods return the expected sum of their arguments.
|
292
|
+
"""
|
293
|
+
|
294
|
+
def mockSyncMethod(cls:FakeClass, num1, num2):
|
295
|
+
return num1 + num2
|
296
|
+
|
297
|
+
async def mockAsyncMethod(cls:FakeClass, num1, num2):
|
298
|
+
import asyncio
|
299
|
+
await asyncio.sleep(0.1)
|
300
|
+
return num1 + num2
|
301
|
+
|
302
|
+
reflect = ReflectionInstance(FakeClass())
|
303
|
+
reflect.setMethod('mockSyncMethodInstance', mockSyncMethod)
|
304
|
+
reflect.setMethod('mockAsyncMethodInstance', mockAsyncMethod)
|
305
|
+
sync_result = reflect.callMethod('mockSyncMethodInstance', 2, 3)
|
306
|
+
async_result = await reflect.callMethod('mockAsyncMethodInstance', 2, 3)
|
307
|
+
self.assertEqual(sync_result, 5)
|
308
|
+
self.assertEqual(async_result, 5)
|
309
|
+
|
310
|
+
async def testRemoveMethod(self):
|
311
|
+
"""
|
312
|
+
Tests the removal of a dynamically added method from a ReflectionInstance.
|
313
|
+
This test adds a protected-like method to a ReflectionInstance of FakeClass,
|
314
|
+
verifies its existence, removes it, and then checks that it no longer exists.
|
315
|
+
"""
|
316
|
+
def _testProtectedMethod(cls:FakeClass, x, y):
|
317
|
+
return x + y
|
318
|
+
|
319
|
+
def __testPrivateMethod(cls:FakeClass, x, y):
|
320
|
+
return x + y
|
321
|
+
|
322
|
+
reflect = ReflectionInstance(FakeClass())
|
323
|
+
reflect.setMethod('_testProtectedMethod', _testProtectedMethod)
|
324
|
+
self.assertTrue(reflect.hasMethod('_testProtectedMethod'))
|
325
|
+
reflect.removeMethod('_testProtectedMethod')
|
326
|
+
self.assertFalse(reflect.hasMethod('_testProtectedMethod'))
|
327
|
+
|
328
|
+
async def testGetMethodSignature(self):
|
329
|
+
"""
|
330
|
+
Tests that the ReflectionInstance.getMethodSignature method correctly retrieves
|
331
|
+
the signature of the 'instanceSyncMethod' from the FakeClass instance.
|
332
|
+
Asserts that the returned signature string matches the expected format:
|
333
|
+
'(self, x: int, y: int) -> int'.
|
334
|
+
"""
|
335
|
+
reflect = ReflectionInstance(FakeClass())
|
336
|
+
signature = reflect.getMethodSignature('instanceSyncMethod')
|
337
|
+
self.assertEqual(str(signature), '(self, x: int, y: int) -> int')
|
338
|
+
|
339
|
+
async def testGetMethods(self):
|
340
|
+
"""
|
341
|
+
Tests that the ReflectionInstance.getMethods() method correctly retrieves the names of all instance methods,
|
342
|
+
including both synchronous and asynchronous methods, from the FakeClass instance.
|
343
|
+
Asserts that 'instanceSyncMethod' and 'instanceAsyncMethod' are present in the returned methods list.
|
344
|
+
"""
|
345
|
+
reflect = ReflectionInstance(FakeClass())
|
346
|
+
methods = reflect.getMethods()
|
347
|
+
self.assertIn('instanceSyncMethod', methods)
|
348
|
+
self.assertIn('instanceAsyncMethod', methods)
|
349
|
+
|
350
|
+
async def testGetPublicMethods(self):
|
351
|
+
"""
|
352
|
+
Tests that the `getPublicMethods` method of `ReflectionInstance` returns only the public methods of a class instance.
|
353
|
+
Verifies that:
|
354
|
+
- Public methods (e.g., 'instanceSyncMethod') are included in the result.
|
355
|
+
- Protected methods (prefixed with a single underscore) are not included.
|
356
|
+
- Private methods (prefixed with double underscores) are not included.
|
357
|
+
"""
|
358
|
+
reflect = ReflectionInstance(FakeClass())
|
359
|
+
public_methods = reflect.getPublicMethods()
|
360
|
+
self.assertIn('instanceSyncMethod', public_methods)
|
361
|
+
self.assertNotIn('_protected_method', public_methods)
|
362
|
+
self.assertNotIn('__private_method', public_methods)
|
363
|
+
|
364
|
+
async def testGetPublicSyncMethods(self):
|
365
|
+
"""
|
366
|
+
Test that ReflectionInstance.getPublicSyncMethods() returns only the names of public synchronous methods.
|
367
|
+
|
368
|
+
This test verifies that:
|
369
|
+
- Public synchronous methods (e.g., 'instanceSyncMethod') are included in the result.
|
370
|
+
- Protected methods (prefixed with a single underscore) are excluded.
|
371
|
+
- Private methods (prefixed with double underscores) are excluded.
|
372
|
+
"""
|
373
|
+
reflect = ReflectionInstance(FakeClass())
|
374
|
+
public_sync_methods = reflect.getPublicSyncMethods()
|
375
|
+
self.assertIn('instanceSyncMethod', public_sync_methods)
|
376
|
+
self.assertNotIn('_protected_method', public_sync_methods)
|
377
|
+
self.assertNotIn('__private_method', public_sync_methods)
|
378
|
+
|
379
|
+
async def testGetPublicAsyncMethods(self):
|
380
|
+
"""
|
381
|
+
Test that ReflectionInstance.getPublicAsyncMethods() correctly identifies public asynchronous methods.
|
382
|
+
|
383
|
+
This test verifies that:
|
384
|
+
- Public async methods (e.g., 'instanceAsyncMethod') are included in the returned list.
|
385
|
+
- Protected (prefixed with a single underscore) and private (double underscore) async methods are not included.
|
386
|
+
"""
|
387
|
+
reflect = ReflectionInstance(FakeClass())
|
388
|
+
public_async_methods = reflect.getPublicAsyncMethods()
|
389
|
+
self.assertIn('instanceAsyncMethod', public_async_methods)
|
390
|
+
self.assertNotIn('_protected_async_method', public_async_methods)
|
391
|
+
self.assertNotIn('__private_async_method', public_async_methods)
|
392
|
+
|
393
|
+
async def testGetProtectedMethods(self):
|
394
|
+
"""
|
395
|
+
Test that ReflectionInstance.getProtectedMethods() correctly identifies protected methods.
|
396
|
+
|
397
|
+
This test verifies that:
|
398
|
+
- Protected methods (those prefixed with a single underscore) are included in the result.
|
399
|
+
- Public methods are not included.
|
400
|
+
- Private methods (those prefixed with double underscores) are not included.
|
401
|
+
"""
|
402
|
+
reflect = ReflectionInstance(FakeClass())
|
403
|
+
protected_methods = reflect.getProtectedMethods()
|
404
|
+
self.assertIn('_protectedAsyncMethod', protected_methods)
|
405
|
+
self.assertNotIn('instanceSyncMethod', protected_methods)
|
406
|
+
self.assertNotIn('__privateSyncMethod', protected_methods)
|
407
|
+
|
408
|
+
async def testGetProtectedSyncMethods(self):
|
409
|
+
"""
|
410
|
+
Test that ReflectionInstance.getProtectedSyncMethods() correctly identifies protected synchronous methods.
|
411
|
+
|
412
|
+
This test verifies that:
|
413
|
+
- Protected synchronous methods (e.g., methods prefixed with a single underscore) are included in the result.
|
414
|
+
- Asynchronous methods and private methods (e.g., methods prefixed with double underscores) are not included in the result.
|
415
|
+
"""
|
416
|
+
reflect = ReflectionInstance(FakeClass())
|
417
|
+
protected_sync_methods = reflect.getProtectedSyncMethods()
|
418
|
+
self.assertIn('_protectedsyncMethod', protected_sync_methods)
|
419
|
+
self.assertNotIn('instanceAsyncMethod', protected_sync_methods)
|
420
|
+
self.assertNotIn('__privateSyncMethod', protected_sync_methods)
|
421
|
+
|
422
|
+
async def testGetProtectedAsyncMethods(self):
|
423
|
+
"""
|
424
|
+
Test that ReflectionInstance.getProtectedAsyncMethods() correctly identifies protected asynchronous methods.
|
425
|
+
|
426
|
+
This test verifies that:
|
427
|
+
- The protected asynchronous method '_protectedAsyncMethod' is included in the returned list.
|
428
|
+
- The public synchronous method 'instanceSyncMethod' is not included.
|
429
|
+
- The private synchronous method '__privateSyncMethod' is not included.
|
430
|
+
"""
|
431
|
+
reflect = ReflectionInstance(FakeClass())
|
432
|
+
protected_async_methods = reflect.getProtectedAsyncMethods()
|
433
|
+
self.assertIn('_protectedAsyncMethod', protected_async_methods)
|
434
|
+
self.assertNotIn('instanceSyncMethod', protected_async_methods)
|
435
|
+
self.assertNotIn('__privateSyncMethod', protected_async_methods)
|
436
|
+
|
437
|
+
async def testGetPrivateMethods(self):
|
438
|
+
"""
|
439
|
+
Test that `getPrivateMethods` correctly identifies private methods of a class instance.
|
440
|
+
|
441
|
+
This test verifies that:
|
442
|
+
- The method `__privateSyncMethod` is included in the list of private methods.
|
443
|
+
- The method `instanceSyncMethod` (a public method) is not included.
|
444
|
+
- The method `_protectedAsyncMethod` (a protected method) is not included.
|
445
|
+
"""
|
446
|
+
reflect = ReflectionInstance(FakeClass())
|
447
|
+
private_methods = reflect.getPrivateMethods()
|
448
|
+
self.assertIn('__privateSyncMethod', private_methods)
|
449
|
+
self.assertNotIn('instanceSyncMethod', private_methods)
|
450
|
+
self.assertNotIn('_protectedAsyncMethod', private_methods)
|
451
|
+
|
452
|
+
async def testGetPrivateSyncMethods(self):
|
453
|
+
"""
|
454
|
+
Test that ReflectionInstance.getPrivateSyncMethods correctly identifies private synchronous methods.
|
455
|
+
|
456
|
+
This test verifies that:
|
457
|
+
- The method '__privateSyncMethod' is included in the list of private synchronous methods.
|
458
|
+
- The methods 'instanceAsyncMethod' and '_protectedAsyncMethod' are not included in the list.
|
459
|
+
"""
|
460
|
+
reflect = ReflectionInstance(FakeClass())
|
461
|
+
private_sync_methods = reflect.getPrivateSyncMethods()
|
462
|
+
self.assertIn('__privateSyncMethod', private_sync_methods)
|
463
|
+
self.assertNotIn('instanceAsyncMethod', private_sync_methods)
|
464
|
+
self.assertNotIn('_protectedAsyncMethod', private_sync_methods)
|
465
|
+
|
466
|
+
async def testGetPrivateAsyncMethods(self):
|
467
|
+
"""
|
468
|
+
Test that ReflectionInstance.getPrivateAsyncMethods correctly identifies private asynchronous methods.
|
469
|
+
|
470
|
+
This test verifies that:
|
471
|
+
- The method '__privateAsyncMethod' is included in the list of private async methods.
|
472
|
+
- The method 'instanceSyncMethod' is not included in the list.
|
473
|
+
- The method '_protectedAsyncMethod' is not included in the list.
|
474
|
+
"""
|
475
|
+
reflect = ReflectionInstance(FakeClass())
|
476
|
+
private_async_methods = reflect.getPrivateAsyncMethods()
|
477
|
+
self.assertIn('__privateAsyncMethod', private_async_methods)
|
478
|
+
self.assertNotIn('instanceSyncMethod', private_async_methods)
|
479
|
+
self.assertNotIn('_protectedAsyncMethod', private_async_methods)
|
480
|
+
|
481
|
+
async def testGetPublicClassMethods(self):
|
482
|
+
"""
|
483
|
+
Test that `getPublicClassMethods` returns only the public class methods of the given instance.
|
484
|
+
|
485
|
+
This test verifies that:
|
486
|
+
- Public class methods (e.g., 'classSyncMethod') are included in the result.
|
487
|
+
- Protected (e.g., '_protected_class_method') and private (e.g., '__private_class_method') class methods are excluded from the result.
|
488
|
+
"""
|
489
|
+
reflect = ReflectionInstance(FakeClass())
|
490
|
+
public_class_methods = reflect.getPublicClassMethods()
|
491
|
+
self.assertIn('classSyncMethod', public_class_methods)
|
492
|
+
self.assertNotIn('_protected_class_method', public_class_methods)
|
493
|
+
self.assertNotIn('__private_class_method', public_class_methods)
|
494
|
+
|
495
|
+
async def testGetPublicClassSyncMethods(self):
|
496
|
+
"""
|
497
|
+
Test that `getPublicClassSyncMethods` returns only public synchronous class methods.
|
498
|
+
|
499
|
+
This test verifies that:
|
500
|
+
- Public synchronous class methods (e.g., 'classSyncMethod') are included in the result.
|
501
|
+
- Protected (methods starting with a single underscore) and private (methods starting with double underscores) class methods are excluded from the result.
|
502
|
+
"""
|
503
|
+
reflect = ReflectionInstance(FakeClass())
|
504
|
+
public_class_sync_methods = reflect.getPublicClassSyncMethods()
|
505
|
+
self.assertIn('classSyncMethod', public_class_sync_methods)
|
506
|
+
self.assertNotIn('_protected_class_method', public_class_sync_methods)
|
507
|
+
self.assertNotIn('__private_class_method', public_class_sync_methods)
|
508
|
+
|
509
|
+
async def testGetPublicClassAsyncMethods(self):
|
510
|
+
"""
|
511
|
+
Test that ReflectionInstance.getPublicClassAsyncMethods() correctly identifies public asynchronous class methods.
|
512
|
+
|
513
|
+
This test verifies that:
|
514
|
+
- Public async class methods (e.g., 'classAsyncMethod') are included in the returned list.
|
515
|
+
- Protected (prefixed with a single underscore) and private (prefixed with double underscores) async class methods are not included.
|
516
|
+
"""
|
517
|
+
reflect = ReflectionInstance(FakeClass())
|
518
|
+
public_class_async_methods = reflect.getPublicClassAsyncMethods()
|
519
|
+
self.assertIn('classAsyncMethod', public_class_async_methods)
|
520
|
+
self.assertNotIn('_protected_class_async_method', public_class_async_methods)
|
521
|
+
self.assertNotIn('__private_class_async_method', public_class_async_methods)
|
522
|
+
|
523
|
+
async def testGetProtectedClassMethods(self):
|
524
|
+
"""
|
525
|
+
Test that ReflectionInstance.getProtectedClassMethods() correctly identifies protected class methods.
|
526
|
+
|
527
|
+
This test verifies that:
|
528
|
+
- Protected class methods (those prefixed with a single underscore) are included in the result.
|
529
|
+
- Public class methods are not included.
|
530
|
+
- Private class methods (those prefixed with double underscores) are not included.
|
531
|
+
"""
|
532
|
+
reflect = ReflectionInstance(FakeClass())
|
533
|
+
protected_class_methods = reflect.getProtectedClassMethods()
|
534
|
+
self.assertIn('_classMethodProtected', protected_class_methods)
|
535
|
+
self.assertNotIn('classSyncMethod', protected_class_methods)
|
536
|
+
self.assertNotIn('__classMethodPrivate', protected_class_methods)
|
537
|
+
|
538
|
+
async def testGetProtectedClassSyncMethods(self):
|
539
|
+
"""
|
540
|
+
Test that ReflectionInstance.getProtectedClassSyncMethods correctly identifies
|
541
|
+
protected (single underscore-prefixed) synchronous class methods.
|
542
|
+
|
543
|
+
Asserts that:
|
544
|
+
- '_classMethodProtected' is included in the returned list.
|
545
|
+
- 'classSyncMethod' (public) is not included.
|
546
|
+
- '__classSyncMethodPrivate' (private, double underscore) is not included.
|
547
|
+
"""
|
548
|
+
reflect = ReflectionInstance(FakeClass())
|
549
|
+
protected_class_sync_methods = reflect.getProtectedClassSyncMethods()
|
550
|
+
self.assertIn('_classMethodProtected', protected_class_sync_methods)
|
551
|
+
self.assertNotIn('classSyncMethod', protected_class_sync_methods)
|
552
|
+
self.assertNotIn('__classSyncMethodPrivate', protected_class_sync_methods)
|
553
|
+
|
554
|
+
async def testGetProtectedClassAsyncMethods(self):
|
555
|
+
"""
|
556
|
+
Test that ReflectionInstance correctly retrieves protected asynchronous class methods.
|
557
|
+
|
558
|
+
This test verifies that:
|
559
|
+
- Protected async class methods (those prefixed with a single underscore) are included in the result.
|
560
|
+
- Public async class methods are not included.
|
561
|
+
- Private async class methods (those prefixed with double underscores) are not included.
|
562
|
+
"""
|
563
|
+
reflect = ReflectionInstance(FakeClass())
|
564
|
+
protected_class_async_methods = reflect.getProtectedClassAsyncMethods()
|
565
|
+
self.assertIn('_classAsyncMethodProtected', protected_class_async_methods)
|
566
|
+
self.assertNotIn('classAsyncMethod', protected_class_async_methods)
|
567
|
+
self.assertNotIn('__classAsyncMethodPrivate', protected_class_async_methods)
|
568
|
+
|
569
|
+
async def testGetPrivateClassMethods(self):
|
570
|
+
"""
|
571
|
+
Test that `getPrivateClassMethods` correctly identifies private class methods.
|
572
|
+
|
573
|
+
This test verifies that:
|
574
|
+
- The private class method '__classMethodPrivate' is included in the returned list.
|
575
|
+
- The public class method 'classSyncMethod' is not included.
|
576
|
+
- The protected class method '_classMethodProtected' is not included.
|
577
|
+
"""
|
578
|
+
reflect = ReflectionInstance(FakeClass())
|
579
|
+
private_class_methods = reflect.getPrivateClassMethods()
|
580
|
+
self.assertIn('__classMethodPrivate', private_class_methods)
|
581
|
+
self.assertNotIn('classSyncMethod', private_class_methods)
|
582
|
+
self.assertNotIn('_classMethodProtected', private_class_methods)
|
583
|
+
|
584
|
+
async def testGetPrivateClassSyncMethods(self):
|
585
|
+
"""
|
586
|
+
Test that ReflectionInstance.getPrivateClassSyncMethods() correctly identifies private class-level synchronous methods.
|
587
|
+
|
588
|
+
This test verifies that:
|
589
|
+
- The private class method '__classMethodPrivate' is included in the returned list.
|
590
|
+
- The public class method 'classSyncMethod' is not included.
|
591
|
+
- The protected class method '_classMethodProtected' is not included.
|
592
|
+
"""
|
593
|
+
reflect = ReflectionInstance(FakeClass())
|
594
|
+
private_class_methods = reflect.getPrivateClassSyncMethods()
|
595
|
+
self.assertIn('__classMethodPrivate', private_class_methods)
|
596
|
+
self.assertNotIn('classSyncMethod', private_class_methods)
|
597
|
+
self.assertNotIn('_classMethodProtected', private_class_methods)
|
598
|
+
|
599
|
+
async def testGetPrivateClassAsyncMethods(self):
|
600
|
+
"""
|
601
|
+
Test that ReflectionInstance correctly retrieves private class asynchronous methods.
|
602
|
+
|
603
|
+
This test verifies that:
|
604
|
+
- The private async method '__classAsyncMethodPrivate' is included in the list of private class async methods.
|
605
|
+
- The public async method 'classAsyncMethod' is not included.
|
606
|
+
- The protected async method '_classAsyncMethodProtected' is not included.
|
607
|
+
"""
|
608
|
+
reflect = ReflectionInstance(FakeClass())
|
609
|
+
private_class_async_methods = reflect.getPrivateClassAsyncMethods()
|
610
|
+
self.assertIn('__classAsyncMethodPrivate', private_class_async_methods)
|
611
|
+
self.assertNotIn('classAsyncMethod', private_class_async_methods)
|
612
|
+
self.assertNotIn('_classAsyncMethodProtected', private_class_async_methods)
|
613
|
+
|
614
|
+
async def testGetPublicStaticMethods(self):
|
615
|
+
"""
|
616
|
+
Tests that the `getPublicStaticMethods` method of `ReflectionInstance` correctly retrieves
|
617
|
+
the names of public static methods from the `FakeClass` instance.
|
618
|
+
|
619
|
+
Asserts that:
|
620
|
+
- 'staticMethod' is included in the list of public static methods.
|
621
|
+
- 'staticAsyncMethod' is included in the list of public static methods.
|
622
|
+
- 'static_async_method' is not included in the list of public static methods.
|
623
|
+
"""
|
624
|
+
reflect = ReflectionInstance(FakeClass())
|
625
|
+
public_static_methods = reflect.getPublicStaticMethods()
|
626
|
+
self.assertIn('staticMethod', public_static_methods)
|
627
|
+
self.assertIn('staticAsyncMethod', public_static_methods)
|
628
|
+
self.assertNotIn('static_async_method', public_static_methods)
|
629
|
+
|
630
|
+
async def testGetPublicStaticSyncMethods(self):
|
631
|
+
"""
|
632
|
+
Test that ReflectionInstance.getPublicStaticSyncMethods() correctly identifies public static synchronous methods.
|
633
|
+
|
634
|
+
This test verifies that:
|
635
|
+
- 'staticMethod' (a public static synchronous method) is included in the returned list.
|
636
|
+
- 'staticAsyncMethod' and 'static_async_method' (presumed to be static asynchronous methods) are not included in the returned list.
|
637
|
+
"""
|
638
|
+
reflect = ReflectionInstance(FakeClass())
|
639
|
+
public_static_sync_methods = reflect.getPublicStaticSyncMethods()
|
640
|
+
self.assertIn('staticMethod', public_static_sync_methods)
|
641
|
+
self.assertNotIn('staticAsyncMethod', public_static_sync_methods)
|
642
|
+
self.assertNotIn('static_async_method', public_static_sync_methods)
|
643
|
+
|
644
|
+
async def testGetPublicStaticAsyncMethods(self):
|
645
|
+
"""
|
646
|
+
Test that ReflectionInstance.getPublicStaticAsyncMethods() correctly identifies public static asynchronous methods.
|
647
|
+
|
648
|
+
This test verifies that:
|
649
|
+
- 'staticAsyncMethod' is included in the list of public static async methods.
|
650
|
+
- 'staticMethod' and 'static_async_method' are not included in the list.
|
651
|
+
"""
|
652
|
+
reflect = ReflectionInstance(FakeClass())
|
653
|
+
public_static_async_methods = reflect.getPublicStaticAsyncMethods()
|
654
|
+
self.assertIn('staticAsyncMethod', public_static_async_methods)
|
655
|
+
self.assertNotIn('staticMethod', public_static_async_methods)
|
656
|
+
self.assertNotIn('static_async_method', public_static_async_methods)
|
657
|
+
|
658
|
+
async def testGetProtectedStaticMethods(self):
|
659
|
+
"""
|
660
|
+
Test that ReflectionInstance.getProtectedStaticMethods() correctly identifies protected static methods.
|
661
|
+
|
662
|
+
This test verifies that:
|
663
|
+
- The protected static method '_staticMethodProtected' is included in the returned list.
|
664
|
+
- The public static method 'staticMethod' is not included.
|
665
|
+
- The private static method '__staticMethodPrivate' is not included.
|
666
|
+
"""
|
667
|
+
reflect = ReflectionInstance(FakeClass())
|
668
|
+
protected_static_methods = reflect.getProtectedStaticMethods()
|
669
|
+
self.assertIn('_staticMethodProtected', protected_static_methods)
|
670
|
+
self.assertNotIn('staticMethod', protected_static_methods)
|
671
|
+
self.assertNotIn('__staticMethodPrivate', protected_static_methods)
|
672
|
+
|
673
|
+
async def testGetProtectedStaticSyncMethods(self):
|
674
|
+
"""
|
675
|
+
Test that ReflectionInstance.getProtectedStaticSyncMethods() correctly identifies
|
676
|
+
protected static synchronous methods of the FakeClass.
|
677
|
+
|
678
|
+
Asserts that:
|
679
|
+
- '_staticMethodProtected' is included in the returned list.
|
680
|
+
- 'staticAsyncMethod' and '__staticMethodPrivate' are not included.
|
681
|
+
"""
|
682
|
+
reflect = ReflectionInstance(FakeClass())
|
683
|
+
protected_static_sync_methods = reflect.getProtectedStaticSyncMethods()
|
684
|
+
self.assertIn('_staticMethodProtected', protected_static_sync_methods)
|
685
|
+
self.assertNotIn('staticAsyncMethod', protected_static_sync_methods)
|
686
|
+
self.assertNotIn('__staticMethodPrivate', protected_static_sync_methods)
|
687
|
+
|
688
|
+
async def testGetProtectedStaticAsyncMethods(self):
|
689
|
+
"""
|
690
|
+
Test that ReflectionInstance correctly identifies protected static asynchronous methods.
|
691
|
+
|
692
|
+
This test verifies that:
|
693
|
+
- The protected static async method '_staticAsyncMethodProtected' is included in the list returned by getProtectedStaticAsyncMethods().
|
694
|
+
- The public static method 'staticMethod' is not included in the list.
|
695
|
+
- The private static method '__staticMethodPrivate' is not included in the list.
|
696
|
+
"""
|
697
|
+
reflect = ReflectionInstance(FakeClass())
|
698
|
+
protected_static_async_methods = reflect.getProtectedStaticAsyncMethods()
|
699
|
+
self.assertIn('_staticAsyncMethodProtected', protected_static_async_methods)
|
700
|
+
self.assertNotIn('staticMethod', protected_static_async_methods)
|
701
|
+
self.assertNotIn('__staticMethodPrivate', protected_static_async_methods)
|
702
|
+
|
703
|
+
async def testGetPrivateStaticMethods(self):
|
704
|
+
"""
|
705
|
+
Test that `getPrivateStaticMethods` correctly identifies and returns the names of private static methods
|
706
|
+
from the reflected class instance. Ensures that private static methods (those with double underscores)
|
707
|
+
are included, while protected (single underscore) and public static methods are excluded from the result.
|
708
|
+
"""
|
709
|
+
reflect = ReflectionInstance(FakeClass())
|
710
|
+
private_static_methods = reflect.getPrivateStaticMethods()
|
711
|
+
self.assertIn('__staticMethodPrivate', private_static_methods)
|
712
|
+
self.assertNotIn('staticMethod', private_static_methods)
|
713
|
+
self.assertNotIn('_staticMethodProtected', private_static_methods)
|
714
|
+
|
715
|
+
async def testGetPrivateStaticSyncMethods(self):
|
716
|
+
"""
|
717
|
+
Test that ReflectionInstance.getPrivateStaticSyncMethods() correctly identifies private static synchronous methods.
|
718
|
+
|
719
|
+
This test verifies that:
|
720
|
+
- The method '__staticMethodPrivate' (a private static sync method) is included in the returned list.
|
721
|
+
- The methods 'staticMethod' (public) and '_staticMethodProtected' (protected) are not included in the returned list.
|
722
|
+
"""
|
723
|
+
reflect = ReflectionInstance(FakeClass())
|
724
|
+
private_static_sync_methods = reflect.getPrivateStaticSyncMethods()
|
725
|
+
self.assertIn('__staticMethodPrivate', private_static_sync_methods)
|
726
|
+
self.assertNotIn('staticMethod', private_static_sync_methods)
|
727
|
+
self.assertNotIn('_staticMethodProtected', private_static_sync_methods)
|
728
|
+
|
729
|
+
async def testGetPrivateStaticAsyncMethods(self):
|
730
|
+
"""
|
731
|
+
Test that ReflectionInstance correctly identifies private static asynchronous methods.
|
732
|
+
|
733
|
+
This test verifies that:
|
734
|
+
- The list of private static async methods includes '__staticAsyncMethodPrivate'.
|
735
|
+
- The list does not include 'staticAsyncMethod' (public) or '_staticAsyncMethodProtected' (protected).
|
736
|
+
"""
|
737
|
+
reflect = ReflectionInstance(FakeClass())
|
738
|
+
private_static_async_methods = reflect.getPrivateStaticAsyncMethods()
|
739
|
+
self.assertIn('__staticAsyncMethodPrivate', private_static_async_methods)
|
740
|
+
self.assertNotIn('staticAsyncMethod', private_static_async_methods)
|
741
|
+
self.assertNotIn('_staticAsyncMethodProtected', private_static_async_methods)
|
742
|
+
|
743
|
+
async def testGetDunderMethods(self):
|
744
|
+
"""
|
745
|
+
Test that the getDunderMethods method of ReflectionInstance returns a list containing
|
746
|
+
dunder (double underscore) methods of the given instance, such as '__init__' and '__class__'.
|
747
|
+
"""
|
748
|
+
reflect = ReflectionInstance(FakeClass())
|
749
|
+
dunder_methods = reflect.getDunderMethods()
|
750
|
+
self.assertIn('__init__', dunder_methods)
|
751
|
+
self.assertIn('__class__', dunder_methods)
|
752
|
+
|
753
|
+
async def testGetMagicMethods(self):
|
754
|
+
"""
|
755
|
+
Tests that the ReflectionInstance.getMagicMethods() method correctly retrieves
|
756
|
+
the list of magic methods from the given FakeClass instance.
|
757
|
+
|
758
|
+
Asserts that commonly expected magic methods such as '__init__' and '__class__'
|
759
|
+
are present in the returned list.
|
760
|
+
"""
|
761
|
+
reflect = ReflectionInstance(FakeClass())
|
762
|
+
magic_methods = reflect.getMagicMethods()
|
763
|
+
self.assertIn('__init__', magic_methods)
|
764
|
+
self.assertIn('__class__', magic_methods)
|
765
|
+
|
766
|
+
async def testGetProperties(self):
|
767
|
+
"""
|
768
|
+
Test that ReflectionInstance.getProperties() returns all expected properties,
|
769
|
+
including public, protected, and private computed properties of the target class.
|
770
|
+
"""
|
771
|
+
reflect = ReflectionInstance(FakeClass())
|
772
|
+
properties = reflect.getProperties()
|
773
|
+
self.assertIn('computed_public_property', properties)
|
774
|
+
self.assertIn('_computed_property_protected', properties)
|
775
|
+
self.assertIn('__computed_property_private', properties)
|
776
|
+
|
777
|
+
async def testGetPublicProperties(self):
|
778
|
+
"""
|
779
|
+
Tests that the `getPublicProperties` method of `ReflectionInstance` correctly identifies
|
780
|
+
and returns only the public properties of a given class instance.
|
781
|
+
|
782
|
+
Verifies that:
|
783
|
+
- Public properties (e.g., 'computed_public_property') are included in the result.
|
784
|
+
- Protected (e.g., '_computed_property_protected') and private (e.g., '__computed_property_private')
|
785
|
+
properties are not included in the result.
|
786
|
+
"""
|
787
|
+
reflect = ReflectionInstance(FakeClass())
|
788
|
+
public_properties = reflect.getPublicProperties()
|
789
|
+
self.assertIn('computed_public_property', public_properties)
|
790
|
+
self.assertNotIn('_computed_property_protected', public_properties)
|
791
|
+
self.assertNotIn('__computed_property_private', public_properties)
|
792
|
+
|
793
|
+
async def testGetProtectedProperties(self):
|
794
|
+
"""
|
795
|
+
Test that ReflectionInstance.getProtectedProperties() correctly identifies protected properties.
|
796
|
+
|
797
|
+
This test verifies that:
|
798
|
+
- Protected properties (those prefixed with a single underscore) are included in the result.
|
799
|
+
- Public properties are not included.
|
800
|
+
- Private properties (those prefixed with double underscores) are not included.
|
801
|
+
"""
|
802
|
+
reflect = ReflectionInstance(FakeClass())
|
803
|
+
protected_properties = reflect.getProtectedProperties()
|
804
|
+
self.assertIn('_computed_property_protected', protected_properties)
|
805
|
+
self.assertNotIn('computed_public_property', protected_properties)
|
806
|
+
self.assertNotIn('__computed_property_private', protected_properties)
|
807
|
+
|
808
|
+
async def testGetPrivateProperties(self):
|
809
|
+
"""
|
810
|
+
Test that ReflectionInstance.getPrivateProperties() correctly identifies private properties.
|
811
|
+
|
812
|
+
This test verifies that:
|
813
|
+
- Private properties (those with double underscores) are included in the result.
|
814
|
+
- Public and protected properties are not included in the result.
|
815
|
+
"""
|
816
|
+
reflect = ReflectionInstance(FakeClass())
|
817
|
+
private_properties = reflect.getPrivateProperties()
|
818
|
+
self.assertIn('__computed_property_private', private_properties)
|
819
|
+
self.assertNotIn('computed_public_property', private_properties)
|
820
|
+
self.assertNotIn('_computed_property_protected', private_properties)
|
821
|
+
|
822
|
+
async def testGetProperty(self):
|
823
|
+
"""
|
824
|
+
Tests that the ReflectionInstance.getProperty method correctly retrieves the value of a computed public property
|
825
|
+
from an instance of FakeClass.
|
826
|
+
|
827
|
+
Asserts that the value returned by getProperty for 'computed_public_property' matches the actual property value
|
828
|
+
from a new FakeClass instance.
|
829
|
+
"""
|
830
|
+
reflect = ReflectionInstance(FakeClass())
|
831
|
+
value = reflect.getProperty('computed_public_property')
|
832
|
+
self.assertEqual(value, FakeClass().computed_public_property)
|
833
|
+
|
834
|
+
async def testGetPropertySignature(self):
|
835
|
+
"""
|
836
|
+
Tests that the `getPropertySignature` method of `ReflectionInstance` correctly retrieves
|
837
|
+
the signature of the specified property ('computed_public_property') from a `FakeClass` instance.
|
838
|
+
Asserts that the returned signature string matches the expected format '(self) -> str'.
|
839
|
+
"""
|
840
|
+
reflect = ReflectionInstance(FakeClass())
|
841
|
+
signature = reflect.getPropertySignature('computed_public_property')
|
842
|
+
self.assertEqual(str(signature), '(self) -> str')
|
843
|
+
|
844
|
+
async def testGetPropertyDocstring(self):
|
845
|
+
"""
|
846
|
+
Tests that the getPropertyDocstring method of ReflectionInstance correctly retrieves
|
847
|
+
the docstring for the specified property ('computed_public_property') of the FakeClass instance.
|
848
|
+
Asserts that the returned docstring contains the expected description.
|
849
|
+
"""
|
850
|
+
reflect = ReflectionInstance(FakeClass())
|
851
|
+
docstring = reflect.getPropertyDocstring('computed_public_property')
|
852
|
+
self.assertIn('Returns the string "public" as', docstring)
|
853
|
+
|
854
|
+
async def testGetConstructorDependencies(self):
|
855
|
+
"""
|
856
|
+
Tests that the `getConstructorDependencies` method of `ReflectionInstance` returns an instance of `ClassDependency`.
|
857
|
+
|
858
|
+
This test creates a `ReflectionInstance` for a `FakeClass` object, retrieves its constructor dependencies,
|
859
|
+
and asserts that the returned value is an instance of `ClassDependency`.
|
860
|
+
"""
|
861
|
+
reflect = ReflectionInstance(FakeClass())
|
862
|
+
dependencies = reflect.getConstructorDependencies()
|
863
|
+
self.assertIsInstance(dependencies, ClassDependency)
|
864
|
+
|
865
|
+
async def testGetMethodDependencies(self):
|
866
|
+
"""
|
867
|
+
Test that the `getMethodDependencies` method of `ReflectionInstance` correctly resolves
|
868
|
+
the dependencies of the 'instanceSyncMethod' in `FakeClass`.
|
869
|
+
|
870
|
+
This test verifies that:
|
871
|
+
- The method dependencies 'x' and 'y' are present in the resolved dependencies.
|
872
|
+
- Both 'x' and 'y' are identified as integers (`int`), with the correct class name, module name,
|
873
|
+
type, and full class path.
|
874
|
+
- There are no unresolved dependencies.
|
875
|
+
"""
|
876
|
+
reflect = ReflectionInstance(FakeClass())
|
877
|
+
method_deps = reflect.getMethodDependencies('instanceSyncMethod')
|
878
|
+
self.assertIn('x', method_deps.resolved)
|
879
|
+
self.assertIn('y', method_deps.resolved)
|
880
|
+
self.assertEqual(method_deps.resolved['x'].class_name, 'int')
|
881
|
+
self.assertEqual(method_deps.resolved['y'].class_name, 'int')
|
882
|
+
self.assertEqual(method_deps.resolved['x'].module_name, 'builtins')
|
883
|
+
self.assertEqual(method_deps.resolved['y'].module_name, 'builtins')
|
884
|
+
self.assertEqual(method_deps.resolved['x'].type, int)
|
885
|
+
self.assertEqual(method_deps.resolved['y'].type, int)
|
886
|
+
self.assertEqual(method_deps.resolved['x'].full_class_path, 'builtins.int')
|
887
|
+
self.assertEqual(method_deps.resolved['y'].full_class_path, 'builtins.int')
|
888
|
+
self.assertEqual(method_deps.unresolved, [])
|