orionis 0.305.0__py3-none-any.whl → 0.306.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.
Files changed (32) hide show
  1. orionis/metadata/framework.py +1 -1
  2. orionis/{services → support}/standard/std.py +2 -2
  3. {orionis-0.305.0.dist-info → orionis-0.306.0.dist-info}/METADATA +1 -1
  4. {orionis-0.305.0.dist-info → orionis-0.306.0.dist-info}/RECORD +23 -32
  5. tests/{services → support}/standard/test_services_std.py +3 -3
  6. tests/{services → support}/wrapper/test_services_wrapper_docdict.py +2 -2
  7. tests/support/inspection/fakes/fake_reflect_abstract.py +0 -276
  8. tests/support/inspection/fakes/fake_reflection_concrete.py +0 -44
  9. tests/support/inspection/fakes/fake_reflection_concrete_with_abstract.py +0 -78
  10. tests/support/inspection/fakes/fake_reflection_instance_with_abstract.py +0 -45
  11. tests/support/inspection/test_reflect_abstract.py +0 -334
  12. tests/support/inspection/test_reflect_instance.py +0 -288
  13. tests/support/inspection/test_reflection_concrete.py +0 -142
  14. tests/support/inspection/test_reflection_concrete_with_abstract.py +0 -87
  15. tests/support/inspection/test_reflection_instance_with_abstract.py +0 -79
  16. /orionis/{services → support}/standard/__init__.py +0 -0
  17. /orionis/{services → support}/standard/contracts/__init__.py +0 -0
  18. /orionis/{services → support}/standard/contracts/std.py +0 -0
  19. /orionis/{services → support}/standard/exceptions/__init__.py +0 -0
  20. /orionis/{services → support}/standard/exceptions/std_value_exception.py +0 -0
  21. /orionis/{services → support}/wrapper/__init__.py +0 -0
  22. /orionis/{services → support}/wrapper/dicts/__init__.py +0 -0
  23. /orionis/{services → support}/wrapper/dicts/dot_dict.py +0 -0
  24. {orionis-0.305.0.dist-info → orionis-0.306.0.dist-info}/WHEEL +0 -0
  25. {orionis-0.305.0.dist-info → orionis-0.306.0.dist-info}/licenses/LICENCE +0 -0
  26. {orionis-0.305.0.dist-info → orionis-0.306.0.dist-info}/top_level.txt +0 -0
  27. {orionis-0.305.0.dist-info → orionis-0.306.0.dist-info}/zip-safe +0 -0
  28. /tests/services/{standard → inspection/reflection}/__init__.py +0 -0
  29. /tests/services/{wrapper → inspection/reflection/mock}/__init__.py +0 -0
  30. /tests/{support/inspection/fakes → services/inspection/reflection/mock}/fake_reflect_instance.py +0 -0
  31. /tests/support/{inspection → standard}/__init__.py +0 -0
  32. /tests/support/{inspection/fakes → wrapper}/__init__.py +0 -0
@@ -1,334 +0,0 @@
1
- from abc import ABC
2
- import json
3
- from orionis.support.introspection.reflection import Reflection
4
- from orionis.test import TestCase
5
- from tests.support.inspection.fakes.fake_reflect_abstract import FakeAbstractClass
6
-
7
- class TestReflectAbstract(TestCase):
8
- """Test cases for ReflexionAbstract using FakeAbstractClass.
9
-
10
- This test suite verifies all functionality of the ReflexionAbstract class
11
- using FakeAbstractClass as the test subject.
12
- """
13
-
14
- async def testReflectionAbstractExceptionValueError(self):
15
- """Class setup method.
16
-
17
- Initializes the ReflexionAbstract instance with FakeAbstractClass
18
- before any tests run.
19
- """
20
- with self.assertRaises(ValueError):
21
- Reflection.abstract(str)
22
-
23
- async def testReflectionAbstractGetClassName(self):
24
- """Test getClassName() method.
25
-
26
- Verifies that:
27
- - The returned class name matches exactly
28
- - The return type is str
29
- """
30
- class_name = Reflection.abstract(FakeAbstractClass).getClassName()
31
- self.assertEqual(class_name, "FakeAbstractClass")
32
- self.assertIsInstance(class_name, str)
33
-
34
- async def testReflectionAbstractGetModuleName(self):
35
- """Test getModuleName() method.
36
-
37
- Verifies that:
38
- - The module name is returned
39
- - The name is a string
40
- """
41
- module_name = Reflection.abstract(FakeAbstractClass).getModuleName()
42
- self.assertTrue(module_name == 'tests.support.inspection.fakes.fake_reflect_abstract')
43
- self.assertIsInstance(module_name, str)
44
-
45
- async def testReflectionAbstractGetClass(self):
46
- """
47
- Test the `getClass()` method of the `Reflection.abstract` function.
48
- This test verifies the following:
49
- - The method raises a `RuntimeError` when attempting to retrieve a class
50
- from an abstract class.
51
- - Ensures that the behavior aligns with the expected handling of abstract
52
- classes in the reflection mechanism.
53
- """
54
- with self.assertRaises(RuntimeError):
55
- Reflection.abstract(FakeAbstractClass).getClass()
56
-
57
- async def testReflectionAbstractGetAllAttributes(self):
58
- """Test getAllAttributes() method.
59
-
60
- Verifies that:
61
- - All attributes are detected
62
- - No private/protected attributes are included
63
- - Return type is correct
64
- """
65
- attributes = Reflection.abstract(FakeAbstractClass).getAllAttributes()
66
- self.assertIn('__private_class_attribute', attributes.private)
67
- self.assertIn('_protected_class_attribute', attributes.protected)
68
- self.assertIn('public_class_attribute', attributes.public)
69
-
70
- async def testReflectionAbstractGetAttribute(self):
71
- """Test getAttribute() method.
72
-
73
- Verifies that:
74
- - Correct attribute is returned
75
- - Attribute type is correct
76
- """
77
- attr = Reflection.abstract(FakeAbstractClass).getAttributes()
78
- self.assertIn('__private_class_attribute', attr)
79
- self.assertIn('_protected_class_attribute', attr)
80
- self.assertIn('public_class_attribute', attr)
81
-
82
- async def testReflectionAbstractGetPublicAttributes(self):
83
- """Test getPublicAttributes() method.
84
-
85
- Verifies that:
86
- - Only public attributes are returned
87
- - No private/protected attributes are included
88
- """
89
- public_attributes = Reflection.abstract(FakeAbstractClass).getPublicAttributes()
90
- self.assertIn('public_class_attribute', public_attributes)
91
- self.assertNotIn('_protected_class_attribute', public_attributes)
92
- self.assertNotIn('__private_class_attribute', public_attributes)
93
-
94
- async def testReflectionAbstractGetProtectedAttributes(self):
95
- """Test getProtectedAttributes() method.
96
-
97
- Verifies that:
98
- - Only protected attributes are returned
99
- - No private/public attributes are included
100
- """
101
- protected_attributes = Reflection.abstract(FakeAbstractClass).getProtectedAttributes()
102
- self.assertIn('_protected_class_attribute', protected_attributes)
103
- self.assertNotIn('__private_class_attribute', protected_attributes)
104
- self.assertNotIn('public_class_attribute', protected_attributes)
105
-
106
- async def testReflectionAbstractGetPrivateAttributes(self):
107
- """Test getPrivateAttributes() method.
108
-
109
- Verifies that:
110
- - Only private attributes are returned
111
- - No protected/public attributes are included
112
- """
113
- private_attributes = Reflection.abstract(FakeAbstractClass).getPrivateAttributes()
114
- self.assertIn('__private_class_attribute', private_attributes)
115
- self.assertNotIn('_protected_class_attribute', private_attributes)
116
- self.assertNotIn('public_class_attribute', private_attributes)
117
-
118
- async def testReflectionAbstractGetAllMethods(self):
119
- """Test getAllMethods() method.
120
-
121
- Verifies that:
122
- - All methods are detected
123
- - No private/protected methods are included
124
- - Return type is correct
125
- """
126
- methods = Reflection.abstract(FakeAbstractClass).getAllMethods()
127
- self.console().info(message="Hola")
128
- # self.print(Reflection.abstract(FakeAbstractClass).getAllAttributes())
129
- # self.dd(json.dumps(methods, indent=4))
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
- # async def testReflectionAbstractGetAbstractMethods(self):
142
- # """Test getAbstractMethods() method.
143
-
144
- # Verifies that:
145
- # - All abstract methods are detected
146
- # - No concrete methods are included
147
- # - Return type is correct
148
- # """
149
- # methods = Reflection.abstract(FakeAbstractClass).getAbstractMethods()
150
- # expected = {'abstract_method', 'another_abstract'}
151
- # self.assertEqual(methods, expected)
152
- # self.assertIsInstance(methods, set)
153
-
154
- # async def testReflectionAbstractGetConcreteMethods(self):
155
- # """Test getConcreteMethods() method.
156
-
157
- # Verifies that:
158
- # - Concrete methods are detected
159
- # - Abstract methods are excluded
160
- # - Protected/private methods are excluded
161
- # """
162
- # methods = Reflection.abstract(FakeAbstractClass).getConcreteMethods()
163
- # self.assertIn('static_helper', methods)
164
- # self.assertIn('concrete_method', methods)
165
- # self.assertIn('decorated_method', methods)
166
- # self.assertNotIn('abstract_method', methods)
167
- # self.assertNotIn('_protected_method', methods)
168
- # self.assertNotIn('__private_method', methods)
169
-
170
- # async def testReflectionAbstractGetStaticMethods(self):
171
- # """Test getStaticMethods() method.
172
-
173
- # Verifies that:
174
- # - Static methods are detected
175
- # - Only static methods are included
176
- # - Protected/private methods are excluded
177
- # """
178
- # static_methods = Reflection.abstract(FakeAbstractClass).getStaticMethods()
179
- # self.assertIn('static_helper', static_methods)
180
- # self.assertEqual(len(static_methods), 1)
181
- # self.assertNotIn('create_instance', static_methods)
182
-
183
- # async def testReflectionAbstractGetClassMethods(self):
184
- # """Test getClassMethods() method.
185
-
186
- # Verifies that:
187
- # - Class methods are detected
188
- # - Only class methods are included
189
- # - Protected/private methods are excluded
190
- # """
191
- # class_methods = Reflection.abstract(FakeAbstractClass).getClassMethods()
192
- # self.assertIn('create_instance', class_methods)
193
- # self.assertEqual(len(class_methods), 1)
194
- # self.assertNotIn('static_helper', class_methods)
195
-
196
- # async def testReflectionAbstractGetProperties(self):
197
- # """Test getProperties() method.
198
-
199
- # Verifies that:
200
- # - Properties are detected
201
- # - Only properties are included
202
- # - Protected/private properties are excluded
203
- # """
204
- # props = Reflection.abstract(FakeAbstractClass).getProperties()
205
- # self.assertIn('computed_property', props)
206
- # self.assertEqual(len(props), 1)
207
-
208
- # async def testReflectionAbstractGetMethodSignature(self):
209
- # """Test getMethodSignature() method.
210
-
211
- # Verifies that:
212
- # - Correct signature is returned
213
- # - Parameters are properly detected
214
- # - Return type is properly detected
215
- # """
216
- # sig = Reflection.abstract(FakeAbstractClass).getMethodSignature('abstract_method')
217
- # params = list(sig.parameters.keys())
218
- # self.assertEqual(params, ['self', 'x', 'y'])
219
- # self.assertEqual(sig.return_annotation, int)
220
-
221
- # async def testReflectionAbstractGetDocstring(self):
222
- # """Test getDocstring() method.
223
-
224
- # Verifies that:
225
- # - Docstring is returned
226
- # - Docstring contains expected content
227
- # """
228
- # doc = Reflection.abstract(FakeAbstractClass).getDocstring()
229
- # self.assertTrue(doc.startswith("A fake abstract class"))
230
- # self.assertIsInstance(doc, str)
231
-
232
- # async def testReflectionAbstractGetBaseAbstractClasses(self):
233
- # """Test getBaseAbstractClasses() method.
234
-
235
- # Verifies that:
236
- # - Base abstract classes are detected
237
- # - Only abstract bases are included
238
- # """
239
- # bases = Reflection.abstract(FakeAbstractClass).getBaseAbstractClasses()
240
- # self.assertEqual(bases, (ABC,))
241
-
242
- # async def testReflectionAbstractGetInterfaceMethods(self):
243
- # """Test getInterfaceMethods() method.
244
-
245
- # Verifies that:
246
- # - Interface methods are detected
247
- # - Signatures are correct
248
- # - Only abstract methods are included
249
- # """
250
- # interface = Reflection.abstract(FakeAbstractClass).getInterfaceMethods()
251
- # self.assertEqual(len(interface), 2)
252
- # self.assertIn('abstract_method', interface)
253
- # sig = interface['abstract_method']
254
- # self.assertEqual(list(sig.parameters.keys()), ['self', 'x', 'y'])
255
-
256
- # async def testReflectionAbstractIsSubclassOf(self):
257
- # """Test isSubclassOf() method.
258
-
259
- # Verifies that:
260
- # - Correctly identifies abstract base classes
261
- # - Returns False for non-parent classes
262
- # """
263
- # self.assertTrue(Reflection.abstract(FakeAbstractClass).isSubclassOf(ABC))
264
- # self.assertTrue(Reflection.abstract(FakeAbstractClass).isSubclassOf(object))
265
-
266
- # async def testReflectionAbstractGetSourceCode(self):
267
- # """Test getSourceCode() method.
268
-
269
- # Verifies that:
270
- # - Source code is returned
271
- # - Contains class definition
272
- # """
273
- # source = Reflection.abstract(FakeAbstractClass).getSourceCode()
274
- # self.assertIsNotNone(source)
275
- # self.assertIn("class FakeAbstractClass(ABC):", source)
276
-
277
- # async def testReflectionAbstractGetFileLocation(self):
278
- # """Test getFileLocation() method.
279
-
280
- # Verifies that:
281
- # - File location is returned
282
- # - Path ends with .py extension
283
- # """
284
- # location = Reflection.abstract(FakeAbstractClass).getFileLocation()
285
- # self.assertIsNotNone(location)
286
- # self.assertTrue('fake_reflection_abstract.py' in location)
287
-
288
- # async def testReflectionAbstractGetAnnotations(self):
289
- # """Test getAnnotations() method.
290
-
291
- # Verifies that:
292
- # - Annotations are detected
293
- # - Class attributes are included
294
- # """
295
- # annotations = Reflection.abstract(FakeAbstractClass).getAnnotations()
296
- # self.assertIn('class_attr', annotations)
297
- # self.assertEqual(annotations['class_attr'], str)
298
-
299
- # async def testReflectionAbstractGetDecorators(self):
300
- # """Test getDecorators() method.
301
-
302
- # Verifies that:
303
- # - Decorators are detected
304
- # - Correct number of decorators is returned
305
- # - Decorator order is preserved
306
- # """
307
- # decorators = Reflection.abstract(FakeAbstractClass).getDecorators('decorated_method')
308
- # for decorator in decorators:
309
- # self.assertTrue(decorator in ['decorator_example', 'another_decorator'])
310
-
311
- # async def testReflectionAbstractIsProtocol(self):
312
- # """Test isProtocol() method.
313
-
314
- # Verifies that:
315
- # - Correctly identifies non-Protocol classes
316
- # """
317
- # self.assertFalse(Reflection.abstract(FakeAbstractClass).isProtocol())
318
-
319
- # async def testReflectionAbstractGetRequiredAttributes(self):
320
- # """Test getRequiredAttributes() method.
321
-
322
- # Verifies that:
323
- # - Returns empty set for non-Protocol classes
324
- # """
325
- # self.assertEqual(Reflection.abstract(FakeAbstractClass).getRequiredAttributes(), set())
326
-
327
- # async def testReflectionAbstractGetAbstractProperties(self):
328
- # """Test getRequiredMethods() method."""
329
- # self.assertEqual(Reflection.abstract(FakeAbstractClass).getAbstractProperties(), set())
330
-
331
- # async def testReflectionAbstractGetPropertySignature(self):
332
- # """Test getPropertySignature() method."""
333
- # signature = Reflection.abstract(FakeAbstractClass).getPropertySignature('computed_property')
334
- # self.assertEqual(str(signature), '(self) -> float')
@@ -1,288 +0,0 @@
1
- import asyncio
2
- from orionis.support.introspection import Reflection
3
- from orionis.support.introspection.instances import ReflectionInstance
4
- from orionis.test import TestCase
5
- from tests.support.inspection.fakes.fake_reflect_instance import BaseFakeClass, FakeClass
6
-
7
- class TestReflectInstance(TestCase):
8
- """
9
- Unit tests for the Reflection class.
10
- """
11
-
12
- async def testReflectionInstanceExceptionValueError(self):
13
- """Ensure Reflection.instance raises ValueError for invalid types."""
14
- with self.assertRaises(ValueError):
15
- Reflection.instance(str)
16
-
17
- async def testReflectionInstance(self):
18
- """Verify Reflection.instance returns an instance of ReflectionInstance."""
19
- self.assertIsInstance(Reflection.instance(FakeClass()), ReflectionInstance)
20
-
21
- async def testReflectionInstanceGetClassName(self):
22
- """Check that getClassName returns the correct class name."""
23
- reflex = Reflection.instance(FakeClass())
24
- self.assertEqual(reflex.getClassName(), "FakeClass")
25
-
26
- async def testReflectionInstanceGetClass(self):
27
- """Ensure getClass returns the correct class."""
28
- reflex = Reflection.instance(FakeClass())
29
- self.assertEqual(reflex.getClass(), FakeClass)
30
-
31
- async def testReflectionInstanceGetModuleName(self):
32
- """Verify getModuleName returns the correct module name."""
33
- reflex = Reflection.instance(FakeClass())
34
- self.assertEqual(reflex.getModuleName(), "tests.support.inspection.fakes.fake_reflect_instance")
35
-
36
- async def testReflectionInstanceGetAllAttributes(self):
37
- """Check that getAllAttributes returns all attributes of the class."""
38
- reflex = Reflection.instance(FakeClass())
39
- attributes = reflex.getAllAttributes()
40
- self.assertTrue("public_attr" in attributes.public)
41
- self.assertTrue("__private_attr" in attributes.private)
42
- self.assertTrue("_protected_attr" in attributes.protected)
43
-
44
- async def testReflectionInstanceGetAttributes(self):
45
- """Check that getAttributes returns all attributes of the class."""
46
- reflex = Reflection.instance(FakeClass())
47
- attributes = reflex.getAttributes()
48
- self.assertTrue("public_attr" in attributes)
49
- self.assertTrue("__private_attr" in attributes)
50
- self.assertTrue("dynamic_attr" in attributes)
51
-
52
- async def testReflectionInstanceGetPublicAttributes(self):
53
- """Ensure getPublicAttributes returns all public attributes."""
54
- reflex = Reflection.instance(FakeClass())
55
- attributes = reflex.getPublicAttributes()
56
- self.assertTrue("public_attr" in attributes)
57
- self.assertTrue("dynamic_attr" in attributes)
58
-
59
- async def testReflectionInstanceGetProtectedAttributes(self):
60
- """Check that getProtectedAttributes returns all protected attributes."""
61
- reflex = Reflection.instance(FakeClass())
62
- attributes = reflex.getProtectedAttributes()
63
- self.assertTrue("_protected_attr" in attributes)
64
-
65
- async def testReflectionInstanceGetPrivateAttributes(self):
66
- """Ensure getPrivateAttributes returns all private attributes."""
67
- reflex = Reflection.instance(FakeClass())
68
- attributes = reflex.getPrivateAttributes()
69
- self.assertTrue("__private_attr" in attributes)
70
-
71
- async def testReflectionInstanceGetAllMethods(self):
72
- """Check that getAllMethods returns all methods of the class."""
73
- reflex = Reflection.instance(FakeClass())
74
- methods = reflex.getAllMethods()
75
- self.assertTrue("__privateMethod" in methods.private)
76
- self.assertTrue("_protectedMethod" in methods.protected)
77
- self.assertTrue("asyncMethod" in methods.asynchronous)
78
- self.assertTrue("classMethod" in methods.class_methods)
79
-
80
- async def testReflectionInstanceGetMethods(self):
81
- """Ensure getMethods returns all methods of the class."""
82
- reflex = Reflection.instance(FakeClass())
83
- methods = reflex.getMethods()
84
- self.assertTrue("__privateMethod" in methods)
85
- self.assertTrue("_protectedMethod" in methods)
86
- self.assertTrue("asyncMethod" in methods)
87
- self.assertTrue("classMethod" in methods)
88
- self.assertTrue("instanceMethod" in methods)
89
-
90
- async def testReflectionInstanceGetProtectedMethods(self):
91
- """Check that getProtectedMethods returns all protected methods."""
92
- reflex = Reflection.instance(FakeClass())
93
- methods = reflex.getProtectedMethods()
94
- self.assertTrue("_protectedMethod" in methods)
95
-
96
- async def testReflectionInstanceGetPrivateMethods(self):
97
- """Ensure getPrivateMethods returns all private methods."""
98
- reflex = Reflection.instance(FakeClass())
99
- methods = reflex.getPrivateMethods()
100
- self.assertTrue("__privateMethod" in methods)
101
-
102
- async def testReflectionInstanceGetAsyncMethods(self):
103
- """Check that getAsyncMethods returns all async methods of the class."""
104
- reflex = Reflection.instance(FakeClass())
105
- methods = reflex.getAsyncMethods()
106
- self.assertTrue("asyncMethod" in methods)
107
-
108
- async def testReflectionInstanceGetSyncMethods(self):
109
- """Check that getASyncMethods returns all async methods of the class."""
110
- reflex = Reflection.instance(FakeClass())
111
- methods = reflex.getSyncMethods()
112
- self.assertTrue("__privateMethod" in methods)
113
- self.assertTrue("_protectedMethod" in methods)
114
- self.assertTrue("instanceMethod" in methods)
115
-
116
- async def testReflectionInstanceGetClassMethods(self):
117
- """Verify getClassMethods returns all class methods of the class."""
118
- reflex = Reflection.instance(FakeClass())
119
- methods = reflex.getClassMethods()
120
- self.assertTrue("classMethod" in methods)
121
-
122
- async def testReflectionInstanceGetStaticMethods(self):
123
- """Verify getStaticMethods returns all static methods of the class."""
124
- reflex = Reflection.instance(FakeClass())
125
- methods = reflex.getStaticMethods()
126
- self.assertTrue("staticAsyncMethod" in methods)
127
- self.assertTrue("staticMethod" in methods)
128
-
129
- async def testReflectionInstanceGetAsyncStaticMethods(self):
130
- """Ensure getSyncMethods returns all sync methods of the class."""
131
- reflex = Reflection.instance(FakeClass())
132
- methods = reflex.getAsyncStaticMethods()
133
- self.assertTrue("staticAsyncMethod" in methods)
134
-
135
- async def testReflectionInstanceGetSyncStaticMethods(self):
136
- """Check that getSyncMethods returns all sync methods of the class."""
137
- reflex = Reflection.instance(FakeClass())
138
- methods = reflex.getSyncStaticMethods()
139
- self.assertTrue("staticMethod" in methods)
140
-
141
- async def testReflectionInstanceGetAllProperties(self):
142
- """Check that getAllProperties returns all properties of the class."""
143
- reflex = Reflection.instance(FakeClass())
144
- properties = reflex.getAllProperties()
145
- self.assertTrue("computed_property" in properties.keys())
146
-
147
- async def testReflectionInstanceGetPropertyNames(self):
148
- """Check that getPropertyNames returns all property names."""
149
- reflex = Reflection.instance(FakeClass())
150
- properties = reflex.getPropertyNames()
151
- self.assertTrue("computed_property" in properties)
152
-
153
- async def testReflectionInstanceGetProperty(self):
154
- """Ensure getProperty retrieves the correct property value."""
155
- reflex = Reflection.instance(FakeClass())
156
- property_value = reflex.getProperty("computed_property")
157
- self.assertEqual(property_value, "Value: 42")
158
-
159
- async def testReflectionInstanceGetPropertyDoc(self):
160
- """Check that getPropertyDoc returns the correct property docstring."""
161
- reflex = Reflection.instance(FakeClass())
162
- doc = reflex.getPropertyDoc("computed_property")
163
- self.assertIn("A computed property", doc)
164
-
165
- async def testReflectionInstanceGetPropertySignature(self):
166
- """Ensure getPropertySignature returns the correct property signature."""
167
- reflex = Reflection.instance(FakeClass())
168
- signature = reflex.getPropertySignature("computed_property")
169
- self.assertEqual(str(signature), "(self) -> str")
170
-
171
- async def testReflectionInstanceCallMethod(self):
172
- """Ensure callMethod correctly invokes a method with arguments."""
173
- reflex = Reflection.instance(FakeClass())
174
- result = reflex.callMethod("instanceMethod", 1, 2)
175
- self.assertEqual(result, 3)
176
- result = await reflex.callMethod("asyncMethod")
177
- self.assertEqual(result, "This is async")
178
-
179
- async def testReflectionInstanceGetMethodSignature(self):
180
- """Verify getMethodSignature returns the correct method signature."""
181
- reflex = Reflection.instance(FakeClass())
182
- signature = reflex.getMethodSignature("instanceMethod")
183
- self.assertEqual(str(signature), "(x: int, y: int) -> int")
184
- signature = reflex.getMethodSignature("__privateMethod")
185
- self.assertEqual(str(signature), "() -> str")
186
-
187
- async def testReflectionInstanceGetDocstring(self):
188
- """Check that getDocstring returns the correct class docstring."""
189
- reflex = Reflection.instance(FakeClass())
190
- docstring = reflex.getDocstring()
191
- self.assertIn("This is a test class for", docstring)
192
-
193
- async def testReflectionInstanceGetBaseClasses(self):
194
- """Ensure getBaseClasses returns the correct base classes."""
195
- reflex = Reflection.instance(FakeClass())
196
- base_classes = reflex.getBaseClasses()
197
- self.assertIn(BaseFakeClass, base_classes)
198
-
199
- async def testReflectionInstanceIsInstanceOf(self):
200
- """Verify isInstanceOf checks inheritance correctly."""
201
- reflex = Reflection.instance(FakeClass())
202
- result = reflex.isInstanceOf(BaseFakeClass)
203
- self.assertTrue(result)
204
-
205
- async def testReflectionInstanceGetSourceCode(self):
206
- """Check that getSourceCode returns the class source code."""
207
- reflex = Reflection.instance(FakeClass())
208
- source_code = reflex.getSourceCode()
209
- self.assertIn("class FakeClass(BaseFakeClass):", source_code)
210
-
211
- async def testReflectionInstanceGetFileLocation(self):
212
- """Ensure getFileLocation returns the correct file path."""
213
- reflex = Reflection.instance(FakeClass())
214
- file_location = reflex.getFileLocation()
215
- self.assertIn("fake_reflect_instance.py", file_location)
216
-
217
- async def testReflectionInstanceGetAnnotations(self):
218
- """Verify getAnnotations returns the correct class annotations."""
219
- reflex = Reflection.instance(FakeClass())
220
- annotations = reflex.getAnnotations()
221
- self.assertEqual("{'class_attr': <class 'str'>}", str(annotations))
222
-
223
- async def testReflectionInstanceHasAttribute(self):
224
- """Check that hasAttribute correctly identifies attributes."""
225
- reflex = Reflection.instance(FakeClass())
226
- self.assertTrue(reflex.hasAttribute("public_attr"))
227
- self.assertFalse(reflex.hasAttribute("non_existent_attr"))
228
-
229
- async def testReflectionInstanceGetAttribute(self):
230
- """Ensure getAttribute retrieves the correct attribute value."""
231
- reflex = Reflection.instance(FakeClass())
232
- attr_value = reflex.getAttribute("public_attr")
233
- self.assertEqual(attr_value, 42)
234
- attr_value = reflex.getAttribute("__private_attr")
235
- self.assertEqual(attr_value, "private")
236
-
237
- async def testReflectionInstanceSetAttribute(self):
238
- """Check that setAttribute correctly sets a new attribute."""
239
- reflex = Reflection.instance(FakeClass())
240
- reflex.setAttribute("new_attr", 'Orionis')
241
- attr_value = reflex.getAttribute("new_attr")
242
- self.assertEqual(attr_value, 'Orionis')
243
- reflex.setAttribute("__new_private_attr", 'Hidden')
244
- attr_value = reflex.getAttribute("__new_private_attr")
245
- self.assertEqual(attr_value, 'Hidden')
246
-
247
- async def testReflectionInstanceRemoveAttribute(self):
248
- """Ensure removeAttribute correctly removes an attribute."""
249
- reflex = Reflection.instance(FakeClass())
250
- reflex.setAttribute("temp_attr", 'Temporary')
251
- reflex.removeAttribute("temp_attr")
252
- self.assertFalse(reflex.hasAttribute("temp_attr"))
253
-
254
- async def testReflectionInstanceSetMacro(self):
255
- """Check that setMacro correctly."""
256
- async def asyncMacro(cls: FakeClass, num):
257
- await asyncio.sleep(0.1)
258
- return cls.instanceMethod(10, 12) + num
259
- def syncMacro(cls: FakeClass, num):
260
- return cls.instanceMethod(10, 12) + num
261
- def __privateMacro(cls: FakeClass, num):
262
- return cls.instanceMethod(10, 12) + num
263
-
264
- reflex = Reflection.instance(FakeClass())
265
-
266
- reflex.setMacro("asyncMacro", asyncMacro)
267
- result = await reflex.callMethod("asyncMacro", reflex._instance, 3)
268
- self.assertEqual(result, 25)
269
-
270
- reflex.setMacro("syncMacro", syncMacro)
271
- result = reflex.callMethod("syncMacro", reflex._instance, 3)
272
- self.assertEqual(result, 25)
273
-
274
- reflex.setMacro("__privateMacro", __privateMacro)
275
- result = reflex.callMethod("__privateMacro", reflex._instance, 3)
276
- self.assertEqual(result, 25)
277
-
278
- async def testReflectionInstanceRemoveMacro(self):
279
- """Ensure removeMacro correctly removes a macro."""
280
- async def asyncMacro(cls: FakeClass, num):
281
- await asyncio.sleep(0.1)
282
- return cls.instanceMethod(10, 12) + num
283
-
284
- reflex = Reflection.instance(FakeClass())
285
- reflex.setMacro("asyncMacro", asyncMacro)
286
- reflex.removeMacro("asyncMacro")
287
- with self.assertRaises(Exception):
288
- await reflex.callMethod("asyncMacro", reflex._instance, 3)