orionis 0.233.0__py3-none-any.whl → 0.234.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 (60) hide show
  1. orionis/framework.py +1 -1
  2. orionis/luminate/support/inspection/dependencies/contracts/__init__.py +0 -0
  3. orionis/luminate/support/inspection/dependencies/contracts/reflect_dependencies.py +43 -0
  4. orionis/luminate/support/inspection/dependencies/entities/__init__.py +0 -0
  5. orionis/luminate/support/inspection/dependencies/entities/class_dependencies.py +10 -0
  6. orionis/luminate/support/inspection/dependencies/entities/method_dependencies.py +10 -0
  7. orionis/luminate/support/inspection/dependencies/entities/resolved_dependencies.py +12 -0
  8. orionis/luminate/support/inspection/dependencies/reflect_dependencies.py +176 -0
  9. orionis/luminate/support/inspection/helpers/__init__.py +0 -0
  10. orionis/luminate/support/inspection/helpers/functions.py +281 -0
  11. orionis/luminate/support/inspection/reflect_decorators.py +335 -0
  12. orionis/luminate/support/inspection/reflection.py +16 -22
  13. orionis/luminate/support/inspection/reflection_instance.py +801 -0
  14. orionis/luminate/support/inspection/reflexion_concrete_with_abstract.py +1 -1
  15. orionis/luminate/support/inspection/reflexion_instance_with_abstract.py +4 -4
  16. orionis/luminate/test/case.py +9 -0
  17. orionis/luminate/test/cases/__init__.py +0 -0
  18. orionis/luminate/test/cases/test_async.py +32 -0
  19. orionis/luminate/test/cases/test_case.py +23 -0
  20. orionis/luminate/test/cases/test_sync.py +10 -0
  21. orionis/luminate/test/core/__init__.py +0 -0
  22. orionis/luminate/test/core/contracts/__init__.py +0 -0
  23. orionis/luminate/test/{test_suite.py → core/test_suite.py} +2 -2
  24. orionis/luminate/test/{test_unit.py → core/test_unit.py} +4 -4
  25. orionis/luminate/test/entities/__init__.py +0 -0
  26. orionis/luminate/test/{test_result.py → entities/test_result.py} +2 -2
  27. orionis/luminate/test/enums/__init__.py +0 -0
  28. orionis/luminate/test/exceptions/__init__.py +0 -0
  29. orionis/luminate/test/output/__init__.py +0 -0
  30. orionis/luminate/test/{test_std_out.py → output/test_std_out.py} +1 -1
  31. orionis/luminate/test/suite.py +7 -0
  32. {orionis-0.233.0.dist-info → orionis-0.234.0.dist-info}/METADATA +1 -1
  33. {orionis-0.233.0.dist-info → orionis-0.234.0.dist-info}/RECORD +57 -37
  34. tests/example/test_example.py +1 -1
  35. tests/support/adapters/test_doct_dict.py +1 -1
  36. tests/support/async_io/test_async_coroutine.py +1 -1
  37. tests/support/environment/test_env.py +1 -1
  38. tests/support/inspection/test_reflection_abstract.py +19 -1
  39. tests/support/inspection/test_reflection_concrete.py +1 -1
  40. tests/support/inspection/test_reflection_concrete_with_abstract.py +1 -1
  41. tests/support/inspection/test_reflection_instance.py +40 -15
  42. tests/support/inspection/test_reflection_instance_with_abstract.py +1 -1
  43. tests/support/parsers/test_exception_parser.py +1 -1
  44. tests/support/path/test_resolver.py +6 -6
  45. tests/support/patterns/test_singleton.py +1 -1
  46. tests/support/standard/test_std.py +1 -1
  47. orionis/luminate/support/inspection/functions.py +0 -263
  48. orionis/luminate/support/inspection/reflexion_instance.py +0 -580
  49. orionis/luminate/test/test_case.py +0 -62
  50. /orionis/luminate/{test/contracts → support/inspection/dependencies}/__init__.py +0 -0
  51. /orionis/luminate/support/inspection/{reflexion_abstract.py → reflect_abstract.py} +0 -0
  52. /orionis/luminate/test/{contracts → core/contracts}/test_suite.py +0 -0
  53. /orionis/luminate/test/{contracts → core/contracts}/test_unit.py +0 -0
  54. /orionis/luminate/test/{test_status.py → enums/test_status.py} +0 -0
  55. /orionis/luminate/test/{test_exception.py → exceptions/test_exception.py} +0 -0
  56. /orionis/luminate/test/{contracts → output/contracts}/test_std_out.py +0 -0
  57. {orionis-0.233.0.dist-info → orionis-0.234.0.dist-info}/LICENCE +0 -0
  58. {orionis-0.233.0.dist-info → orionis-0.234.0.dist-info}/WHEEL +0 -0
  59. {orionis-0.233.0.dist-info → orionis-0.234.0.dist-info}/entry_points.txt +0 -0
  60. {orionis-0.233.0.dist-info → orionis-0.234.0.dist-info}/top_level.txt +0 -0
@@ -1,580 +0,0 @@
1
- from typing import Any, Type, Dict, List, Tuple, Callable, Optional
2
- import inspect
3
-
4
- from orionis.luminate.support.asynchrony.async_io import AsyncIO
5
-
6
- class ReflexionInstance:
7
- """A reflection object encapsulating a class instance.
8
-
9
- Parameters
10
- ----------
11
- instance : Any
12
- The instance being reflected upon
13
-
14
- Attributes
15
- ----------
16
- _instance : Any
17
- The encapsulated instance
18
- """
19
-
20
- def __init__(self, instance: Any) -> None:
21
- """Initialize with the instance to reflect upon."""
22
- self._instance = instance
23
-
24
- def getClassName(self) -> str:
25
- """Get the name of the instance's class.
26
-
27
- Returns
28
- -------
29
- str
30
- The name of the class
31
- """
32
- return self._instance.__class__.__name__
33
-
34
- def getClass(self) -> Type:
35
- """Get the class of the instance.
36
-
37
- Returns
38
- -------
39
- Type
40
- The class object of the instance
41
- """
42
- return self._instance.__class__
43
-
44
- def getModuleName(self) -> str:
45
- """Get the name of the module where the class is defined.
46
-
47
- Returns
48
- -------
49
- str
50
- The module name
51
- """
52
- return self._instance.__class__.__module__
53
-
54
- def getAttributes(self) -> Dict[str, Any]:
55
- """Get all attributes of the instance.
56
-
57
- Returns
58
- -------
59
- Dict[str, Any]
60
- Dictionary of attribute names and their values
61
- """
62
- attributes : dict = vars(self._instance)
63
- class_name : str = self.getClassName()
64
- out_attributes = {}
65
- for attr, value in attributes.items():
66
- out_attributes[str(attr).replace(f"_{class_name}", "")] = value
67
- return out_attributes
68
-
69
- def getPublicAttributes(self) -> Dict[str, Any]:
70
- """Get all public attributes of the instance.
71
-
72
- Returns
73
- -------
74
- Dict[str, Any]
75
- Dictionary of public attribute names and their values
76
- """
77
- attributes : dict = vars(self._instance)
78
- out_attributes = {}
79
- for attr, value in attributes.items():
80
- if not str(attr).startswith("_"):
81
- out_attributes[attr] = value
82
- return out_attributes
83
-
84
- def getPrivateAttributes(self) -> Dict[str, Any]:
85
- """Get all private attributes of the instance.
86
-
87
- Returns
88
- -------
89
- Dict[str, Any]
90
- Dictionary of private attribute names and their values
91
- """
92
- attributes : dict = vars(self._instance)
93
- class_name : str = self.getClassName()
94
- out_attributes = {}
95
- for attr, value in attributes.items():
96
- if str(attr).startswith(f"_{class_name}"):
97
- out_attributes[str(attr).replace(f"_{class_name}", "")] = value
98
- return out_attributes
99
-
100
- def getProtectedAttributes(self) -> Dict[str, Any]:
101
- """Get all Protected attributes of the instance.
102
-
103
- Returns
104
- -------
105
- Dict[str, Any]
106
- Dictionary of Protected attribute names and their values
107
- """
108
- attributes : dict = vars(self._instance)
109
- class_name : str = self.getClassName()
110
- out_attributes = {}
111
- for attr, value in attributes.items():
112
- if str(attr).startswith("_") and not str(attr).startswith("__") and not str(attr).startswith(f"_{class_name}"):
113
- out_attributes[attr] = value
114
- return out_attributes
115
-
116
- def getMethods(self) -> List[str]:
117
- """Get all method names of the instance.
118
-
119
- Returns
120
- -------
121
- List[str]
122
- List of method names
123
- """
124
- class_name = self.getClassName()
125
- methods = [name for name, _ in inspect.getmembers(
126
- self._instance,
127
- predicate=inspect.ismethod
128
- )]
129
-
130
- out_methods = []
131
- for method in methods:
132
- out_methods.append(method.replace(f"_{class_name}", ""))
133
-
134
- return out_methods
135
-
136
- def getProtectedMethods(self) -> List[str]:
137
- """Get all protected method names of the instance.
138
-
139
- Returns
140
- -------
141
- List[str]
142
- List of protected method names, excluding private methods (starting with '_')
143
- """
144
- class_name = self.getClassName()
145
- methods = [name for name, _ in inspect.getmembers(
146
- self._instance,
147
- predicate=inspect.ismethod
148
- )]
149
-
150
- out_methods = []
151
- for method in methods:
152
- if method.startswith("_") and not method.startswith("__") and not method.startswith(f"_{class_name}"):
153
- out_methods.append(method)
154
-
155
- return out_methods
156
-
157
- def getPrivateMethods(self) -> List[str]:
158
- """Get all private method names of the instance.
159
-
160
- Returns
161
- -------
162
- List[str]
163
- List of private method names, excluding protected methods (starting with '_')
164
- """
165
- class_name = self.getClassName()
166
- methods = [name for name, _ in inspect.getmembers(
167
- self._instance,
168
- predicate=inspect.ismethod
169
- )]
170
-
171
- out_methods = []
172
- for method in methods:
173
- if method.startswith(f"_{class_name}"):
174
- out_methods.append(method.replace(f"_{class_name}", ""))
175
-
176
- return out_methods
177
-
178
- def getAsyncMethods(self) -> List[str]:
179
- """
180
- Get all asynchronous method names of the instance that are not static methods.
181
-
182
- Returns
183
- -------
184
- List[str]
185
- List of asynchronous method names
186
- """
187
- obj = self._instance
188
- cls = obj if inspect.isclass(obj) else obj.__class__
189
- class_name = self.getClassName()
190
- methods = [
191
- name for name, func in inspect.getmembers(obj, inspect.iscoroutinefunction)
192
- if not isinstance(inspect.getattr_static(cls, name, None), staticmethod)
193
- ]
194
-
195
- out_methods = []
196
- for method in methods:
197
- out_methods.append(method.replace(f"_{class_name}", ""))
198
-
199
- return out_methods
200
-
201
- def getSyncMethods(self) -> List[str]:
202
- """
203
- Get all synchronous method names of the instance that are not static methods.
204
-
205
- Returns
206
- -------
207
- List[str]
208
- List of synchronous method names
209
- """
210
- obj = self._instance
211
- cls = obj if inspect.isclass(obj) else obj.__class__
212
- class_name = self.getClassName()
213
- methods = [
214
- name for name, func in inspect.getmembers(obj, predicate=inspect.ismethod)
215
- if not inspect.iscoroutinefunction(func) and
216
- not isinstance(inspect.getattr_static(cls, name, None), staticmethod)
217
- ]
218
-
219
- out_methods = []
220
- for method in methods:
221
- out_methods.append(method.replace(f"_{class_name}", ""))
222
-
223
- return out_methods
224
-
225
- def getClassMethods(self) -> List[str]:
226
- """Get all class method names of the instance.
227
-
228
- Returns
229
- -------
230
- List[str]
231
- List of class method names.
232
- """
233
- return [
234
- name for name in dir(self._instance.__class__)
235
- if isinstance(inspect.getattr_static(self._instance.__class__, name), classmethod)
236
- ]
237
-
238
- def getStaticMethods(self) -> List[str]:
239
- """Get all static method names of the instance.
240
-
241
- Returns
242
- -------
243
- List[str]
244
- List of static method names.
245
- """
246
- return [
247
- name for name in dir(self._instance.__class__)
248
- if isinstance(inspect.getattr_static(self._instance.__class__, name), staticmethod)
249
- ]
250
-
251
- def getAsyncStaticMethods(self) -> List[str]:
252
- """
253
- Get all asynchronous method names of the instance that are not static methods.
254
-
255
- Returns
256
- -------
257
- List[str]
258
- List of asynchronous method names
259
- """
260
- obj = self._instance
261
- cls = obj if inspect.isclass(obj) else obj.__class__
262
- return [
263
- name for name, func in inspect.getmembers(obj, inspect.iscoroutinefunction)
264
- if isinstance(inspect.getattr_static(cls, name, None), staticmethod)
265
- ]
266
-
267
- def getSyncStaticMethods(self) -> List[str]:
268
- """
269
- Get all synchronous static method names of the instance.
270
-
271
- Returns
272
- -------
273
- List[str]
274
- List of synchronous static method names
275
- """
276
- obj = self._instance
277
- cls = obj if inspect.isclass(obj) else obj.__class__
278
- return [
279
- name for name, func in inspect.getmembers(cls, inspect.isfunction)
280
- if not inspect.iscoroutinefunction(func) and
281
- isinstance(inspect.getattr_static(cls, name, None), staticmethod)
282
- ]
283
-
284
- def getPropertyNames(self) -> List[str]:
285
- """Get all property names of the instance.
286
-
287
- Returns
288
- -------
289
- List[str]
290
- List of property names
291
- """
292
- return [name for name, _ in inspect.getmembers(
293
- self._instance.__class__,
294
- lambda x: isinstance(x, property)
295
- )]
296
-
297
- def getProperty(self, propertyName: str) -> Any:
298
- """Get the value of a property.
299
-
300
- Parameters
301
- ----------
302
- propertyName : str
303
- Name of the property
304
-
305
- Returns
306
- -------
307
- Any
308
- The value of the property
309
-
310
- Raises
311
- ------
312
- AttributeError
313
- If the property doesn't exist or is not a property
314
- """
315
- attr = getattr(self._instance.__class__, propertyName, None)
316
- if isinstance(attr, property) and attr.fget is not None:
317
- return getattr(self._instance, propertyName)
318
- raise AttributeError(f"{propertyName} is not a property or doesn't have a getter.")
319
-
320
- def getPropertySignature(self, propertyName: str) -> inspect.Signature:
321
- """Get the signature of a property.
322
-
323
- Parameters
324
- ----------
325
- propertyName : str
326
- Name of the property
327
-
328
- Returns
329
- -------
330
- inspect.Signature
331
- The property signature
332
-
333
- Raises
334
- ------
335
- AttributeError
336
- If the property doesn't exist or is not a property
337
- """
338
- attr = getattr(self._instance.__class__, propertyName, None)
339
- if isinstance(attr, property) and attr.fget is not None:
340
- return inspect.signature(attr.fget)
341
- raise AttributeError(f"{propertyName} is not a property or doesn't have a getter.")
342
-
343
- def callMethod(self, methodName: str, *args: Any, **kwargs: Any) -> Any:
344
- """Call a method on the instance.
345
-
346
- Parameters
347
- ----------
348
- methodName : str
349
- Name of the method to call
350
- *args : Any
351
- Positional arguments for the method
352
- **kwargs : Any
353
- Keyword arguments for the method
354
-
355
- Returns
356
- -------
357
- Any
358
- The result of the method call
359
-
360
- Raises
361
- ------
362
- AttributeError
363
- If the method does not exist on the instance
364
- TypeError
365
- If the method is not callable
366
- """
367
-
368
- if methodName in self.getPrivateMethods():
369
- methodName = f"_{self.getClassName()}{methodName}"
370
-
371
- method = getattr(self._instance, methodName, None)
372
-
373
- if method is None:
374
- raise AttributeError(f"'{self.getClassName()}' object has no method '{methodName}'.")
375
- if not callable(method):
376
- raise TypeError(f"'{methodName}' is not callable on '{self.getClassName()}'.")
377
-
378
- if inspect.iscoroutinefunction(method):
379
- return AsyncIO.run(method(*args, **kwargs))
380
-
381
- return method(*args, **kwargs)
382
-
383
- def getMethodSignature(self, methodName: str) -> inspect.Signature:
384
- """Get the signature of a method.
385
-
386
- Parameters
387
- ----------
388
- methodName : str
389
- Name of the method
390
-
391
- Returns
392
- -------
393
- inspect.Signature
394
- The method signature
395
- """
396
- if methodName in self.getPrivateMethods():
397
- methodName = f"_{self.getClassName()}{methodName}"
398
-
399
- method = getattr(self._instance, methodName)
400
- if callable(method):
401
- return inspect.signature(method)
402
-
403
- def getDocstring(self) -> Optional[str]:
404
- """Get the docstring of the instance's class.
405
-
406
- Returns
407
- -------
408
- Optional[str]
409
- The class docstring, or None if not available
410
- """
411
- return self._instance.__class__.__doc__
412
-
413
- def getBaseClasses(self) -> Tuple[Type, ...]:
414
- """Get the base classes of the instance's class.
415
-
416
- Returns
417
- -------
418
- Tuple[Type, ...]
419
- Tuple of base classes
420
- """
421
- return self._instance.__class__.__bases__
422
-
423
- def isInstanceOf(self, cls: Type) -> bool:
424
- """Check if the instance is of a specific class.
425
-
426
- Parameters
427
- ----------
428
- cls : Type
429
- The class to check against
430
-
431
- Returns
432
- -------
433
- bool
434
- True if the instance is of the specified class
435
- """
436
- return isinstance(self._instance, cls)
437
-
438
- def getSourceCode(self) -> Optional[str]:
439
- """Get the source code of the instance's class.
440
-
441
- Returns
442
- -------
443
- Optional[str]
444
- The source code if available, None otherwise
445
- """
446
- try:
447
- return inspect.getsource(self._instance.__class__)
448
- except (TypeError, OSError):
449
- return None
450
-
451
- def getFileLocation(self) -> Optional[str]:
452
- """Get the file location where the class is defined.
453
-
454
- Returns
455
- -------
456
- Optional[str]
457
- The file path if available, None otherwise
458
- """
459
- try:
460
- return inspect.getfile(self._instance.__class__)
461
- except (TypeError, OSError):
462
- return None
463
-
464
- def getAnnotations(self) -> Dict[str, Any]:
465
- """Get type annotations of the class.
466
-
467
- Returns
468
- -------
469
- Dict[str, Any]
470
- Dictionary of attribute names and their type annotations
471
- """
472
- return self._instance.__class__.__annotations__
473
-
474
- def hasAttribute(self, name: str) -> bool:
475
- """Check if the instance has a specific attribute.
476
-
477
- Parameters
478
- ----------
479
- name : str
480
- The attribute name to check
481
-
482
- Returns
483
- -------
484
- bool
485
- True if the attribute exists
486
- """
487
- return hasattr(self._instance, name)
488
-
489
- def getAttribute(self, name: str) -> Any:
490
- """Get an attribute value by name.
491
-
492
- Parameters
493
- ----------
494
- name : str
495
- The attribute name
496
-
497
- Returns
498
- -------
499
- Any
500
- The attribute value
501
-
502
- Raises
503
- ------
504
- AttributeError
505
- If the attribute doesn't exist
506
- """
507
- attrs = self.getAttributes()
508
- return attrs.get(name, getattr(self._instance, name, None))
509
-
510
- def setAttribute(self, name: str, value: Any) -> None:
511
- """Set an attribute value.
512
-
513
- Parameters
514
- ----------
515
- name : str
516
- The attribute name
517
- value : Any
518
- The value to set
519
-
520
- Raises
521
- ------
522
- AttributeError
523
- If the attribute is read-only
524
- """
525
- if callable(value):
526
- raise AttributeError(f"Cannot set attribute '{name}' to a callable.")
527
- setattr(self._instance, name, value)
528
-
529
- def removeAttribute(self, name: str) -> None:
530
- """Remove an attribute from the instance.
531
-
532
- Parameters
533
- ----------
534
- name : str
535
- The attribute name to remove
536
-
537
- Raises
538
- ------
539
- AttributeError
540
- If the attribute doesn't exist or is read-only
541
- """
542
- if not hasattr(self._instance, name):
543
- raise AttributeError(f"'{self.getClassName()}' object has no attribute '{name}'.")
544
- delattr(self._instance, name)
545
-
546
- def setMacro(self, name: str, value: Callable) -> None:
547
- """Set a callable attribute value.
548
-
549
- Parameters
550
- ----------
551
- name : str
552
- The attribute name
553
- value : Callable
554
- The callable to set
555
-
556
- Raises
557
- ------
558
- AttributeError
559
- If the value is not callable
560
- """
561
- if not callable(value):
562
- raise AttributeError(f"The value for '{name}' must be a callable.")
563
- setattr(self._instance, name, value)
564
-
565
- def removeMacro(self, name: str) -> None:
566
- """Remove a callable attribute from the instance.
567
-
568
- Parameters
569
- ----------
570
- name : str
571
- The attribute name to remove
572
-
573
- Raises
574
- ------
575
- AttributeError
576
- If the attribute doesn't exist or is not callable
577
- """
578
- if not hasattr(self._instance, name) or not callable(getattr(self._instance, name)):
579
- raise AttributeError(f"'{self.getClassName()}' object has no callable macro '{name}'.")
580
- delattr(self._instance, name)
@@ -1,62 +0,0 @@
1
- import unittest
2
- from orionis.luminate.test.test_std_out import TestStdOut
3
-
4
- class TestCase(unittest.IsolatedAsyncioTestCase, TestStdOut):
5
- """
6
- TestCase is a base class for unit tests that provides support for asynchronous
7
- testing using `unittest.IsolatedAsyncioTestCase` and additional functionality
8
- from `TestStdOut`."""
9
- async def asyncSetUp(self):
10
- """
11
- Asynchronous setup method called before each test.
12
- It ensures that the parent class's asyncSetUp method is invoked to initialize
13
- any required resources.
14
- """
15
- await super().asyncSetUp()
16
-
17
- async def asyncTearDown(self):
18
- """
19
- Asynchronous teardown method called after each test.
20
- It ensures that the parent class's asyncTearDown method is invoked to clean up
21
- any resources used during the test.
22
- """
23
- await super().asyncTearDown()
24
-
25
- # Another asynchronous test case class
26
- class AsyncTestCase(unittest.IsolatedAsyncioTestCase, TestStdOut):
27
- """
28
- AsyncTestCase is a test case class designed for asynchronous unit testing.
29
- It inherits from `unittest.IsolatedAsyncioTestCase` to provide support for
30
- async test methods and `TestStdOut` for additional functionality.
31
- Methods
32
- -------
33
- asyncSetUp()
34
- Asynchronous setup method called before each test. It ensures that the
35
- parent class's asyncSetUp method is invoked to initialize any required
36
- resources.
37
- asyncTearDown()
38
- Asynchronous teardown method called after each test. It ensures that the
39
- parent class's asyncTearDown method is invoked to clean up any resources
40
- used during the test.
41
- """
42
- async def asyncSetUp(self):
43
- """
44
- Asynchronous setup method called before each test.
45
- It ensures that the parent class's asyncSetUp method is invoked to initialize
46
- """
47
- await super().asyncSetUp()
48
-
49
- async def asyncTearDown(self):
50
- """
51
- Asynchronous teardown method called after each test.
52
- It ensures that the parent class's asyncTearDown method is invoked to clean up
53
- """
54
- await super().asyncTearDown()
55
-
56
- class SyncTestCase(unittest.TestCase, TestStdOut):
57
- """
58
- SyncTestCase is a test case class designed for synchronous unit testing.
59
- It inherits from `unittest.TestCase` to provide support for standard test methods
60
- and `TestStdOut` for additional functionality.
61
- """
62
- pass