orionis 0.313.0__py3-none-any.whl → 0.314.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.
@@ -0,0 +1,462 @@
1
+ from orionis.services.introspection.reflection import Reflection
2
+ from orionis.unittesting import TestCase
3
+ import sys
4
+ import inspect
5
+ import abc
6
+
7
+ class TestServiceReflectionAbstract(TestCase):
8
+
9
+ async def testIsAbstract(self):
10
+ """
11
+ Test Reflection.isAbstract for abstract and concrete classes.
12
+
13
+ Parameters
14
+ ----------
15
+ None
16
+
17
+ Tests
18
+ -----
19
+ - DummyAbstract: An abstract class using abc.ABCMeta with an abstract method.
20
+ - DummyConcrete: A regular concrete class.
21
+
22
+ Returns
23
+ -------
24
+ None
25
+
26
+ Asserts
27
+ -------
28
+ - Reflection.isAbstract(DummyAbstract) returns True.
29
+ - Reflection.isAbstract(DummyConcrete) returns False.
30
+ """
31
+ class DummyAbstract(metaclass=abc.ABCMeta):
32
+ @abc.abstractmethod
33
+ def foo(self):
34
+ pass
35
+
36
+ class DummyConcrete:
37
+ def bar(self):
38
+ return 42
39
+
40
+ self.assertTrue(Reflection.isAbstract(DummyAbstract))
41
+ self.assertFalse(Reflection.isAbstract(DummyConcrete))
42
+
43
+ async def testIsAsyncGen(self):
44
+ """
45
+ Test Reflection.isAsyncGen for correct identification of asynchronous generators.
46
+
47
+ Notes
48
+ -----
49
+ - The asynchronous generator is defined using `async def` and `yield`.
50
+ - The regular generator is defined using `def` and `yield`.
51
+
52
+ Returns
53
+ -------
54
+ None
55
+
56
+ Asserts
57
+ -------
58
+ - Reflection.isAsyncGen(agen) is True.
59
+ - Reflection.isAsyncGen(dummy_generator()) is False.
60
+ """
61
+ async def dummy_asyncgen():
62
+ yield 1
63
+
64
+ def dummy_generator():
65
+ yield 1
66
+
67
+ agen = dummy_asyncgen()
68
+ self.assertTrue(Reflection.isAsyncGen(agen))
69
+ self.assertFalse(Reflection.isAsyncGen(dummy_generator()))
70
+
71
+ async def testIsAsyncGenFunction(self):
72
+ """
73
+ Test Reflection.isAsyncGenFunction for correct identification of async generator functions.
74
+
75
+ Returns
76
+ -------
77
+ None
78
+
79
+ Asserts
80
+ -------
81
+ - Reflection.isAsyncGenFunction(dummy_asyncgen) returns True.
82
+ - Reflection.isAsyncGenFunction(dummy_generator) returns False.
83
+ """
84
+ async def dummy_asyncgen():
85
+ yield 1
86
+
87
+ def dummy_generator():
88
+ yield 1
89
+
90
+ self.assertTrue(Reflection.isAsyncGenFunction(dummy_asyncgen))
91
+ self.assertFalse(Reflection.isAsyncGenFunction(dummy_generator))
92
+
93
+ async def testIsAwaitable(self):
94
+ """
95
+ Test Reflection.isAwaitable to verify correct identification of awaitable objects.
96
+
97
+ Returns
98
+ -------
99
+ None
100
+
101
+ Asserts
102
+ -------
103
+ - An async coroutine object is recognized as awaitable.
104
+ - A non-awaitable object (e.g., an integer) is not recognized as awaitable.
105
+ """
106
+ async def dummy_coroutine():
107
+ pass
108
+
109
+ coro = dummy_coroutine()
110
+ self.assertTrue(Reflection.isAwaitable(coro))
111
+ self.assertFalse(Reflection.isAwaitable(42))
112
+
113
+ async def testIsBuiltin(self):
114
+ """
115
+ Test Reflection.isBuiltin to verify correct identification of built-in functions.
116
+
117
+ Returns
118
+ -------
119
+ None
120
+
121
+ Asserts
122
+ -------
123
+ - The built-in function `len` is recognized as built-in.
124
+ - A user-defined function is not recognized as built-in.
125
+ """
126
+ def dummy_function():
127
+ pass
128
+
129
+ self.assertTrue(Reflection.isBuiltin(len))
130
+ self.assertFalse(Reflection.isBuiltin(dummy_function))
131
+
132
+ async def testIsClass(self):
133
+ """
134
+ Test Reflection.isClass to verify correct identification of classes and non-class objects.
135
+
136
+ Returns
137
+ -------
138
+ None
139
+
140
+ Asserts
141
+ -------
142
+ - Reflection.isClass returns True for a class.
143
+ - Reflection.isClass returns False for a function.
144
+ """
145
+ class DummyConcrete:
146
+ def bar(self):
147
+ return 42
148
+
149
+ def dummy_function():
150
+ pass
151
+
152
+ self.assertTrue(Reflection.isClass(DummyConcrete))
153
+ self.assertFalse(Reflection.isClass(dummy_function))
154
+
155
+ async def testIsCode(self):
156
+ """
157
+ Test Reflection.isCode to verify correct identification of code objects.
158
+
159
+ Returns
160
+ -------
161
+ None
162
+
163
+ Asserts
164
+ -------
165
+ - Passing a function's __code__ attribute returns True.
166
+ - Passing the function itself returns False.
167
+ """
168
+ def dummy_function():
169
+ pass
170
+
171
+ self.assertTrue(Reflection.isCode(dummy_function.__code__))
172
+ self.assertFalse(Reflection.isCode(dummy_function))
173
+
174
+ async def testIsCoroutine(self):
175
+ """
176
+ Test Reflection.isCoroutine to ensure correct identification of coroutine objects.
177
+
178
+ Returns
179
+ -------
180
+ None
181
+
182
+ Asserts
183
+ -------
184
+ - Reflection.isCoroutine returns True for a coroutine object.
185
+ - Reflection.isCoroutine returns False for a regular function.
186
+ """
187
+ async def dummy_coroutine():
188
+ pass
189
+
190
+ def dummy_function():
191
+ pass
192
+
193
+ coro = dummy_coroutine()
194
+ self.assertTrue(Reflection.isCoroutine(coro))
195
+ self.assertFalse(Reflection.isCoroutine(dummy_function))
196
+
197
+ async def testIsCoroutineFunction(self):
198
+ """
199
+ Test Reflection.isCoroutineFunction to verify correct identification of coroutine functions.
200
+
201
+ Returns
202
+ -------
203
+ None
204
+
205
+ Asserts
206
+ -------
207
+ - Reflection.isCoroutineFunction(dummy_coroutine) returns True.
208
+ - Reflection.isCoroutineFunction(dummy_function) returns False.
209
+ """
210
+ async def dummy_coroutine():
211
+ pass
212
+
213
+ def dummy_function():
214
+ pass
215
+
216
+ self.assertTrue(Reflection.isCoroutineFunction(dummy_coroutine))
217
+ self.assertFalse(Reflection.isCoroutineFunction(dummy_function))
218
+
219
+ async def testIsDataDescriptor(self):
220
+ """
221
+ Test Reflection.isDataDescriptor to verify correct identification of data descriptors.
222
+
223
+ Returns
224
+ -------
225
+ None
226
+
227
+ Asserts
228
+ -------
229
+ - A property object is recognized as a data descriptor.
230
+ - A non-descriptor object (such as an integer) is not.
231
+ """
232
+ class X:
233
+ @property
234
+ def foo(self): return 1
235
+
236
+ self.assertTrue(Reflection.isDataDescriptor(X.__dict__['foo']))
237
+ self.assertFalse(Reflection.isDataDescriptor(42))
238
+
239
+ async def testIsFrame(self):
240
+ """
241
+ Test Reflection.isFrame to verify correct identification of frame objects.
242
+
243
+ Returns
244
+ -------
245
+ None
246
+
247
+ Asserts
248
+ -------
249
+ - Reflection.isFrame returns True for a valid frame object.
250
+ - Reflection.isFrame returns False for a non-frame object.
251
+ """
252
+ frame = inspect.currentframe()
253
+ self.assertTrue(Reflection.isFrame(frame))
254
+ self.assertFalse(Reflection.isFrame(42))
255
+
256
+ async def testIsFunction(self):
257
+ """
258
+ Test Reflection.isFunction to verify correct identification of functions.
259
+
260
+ Returns
261
+ -------
262
+ None
263
+
264
+ Asserts
265
+ -------
266
+ - A standalone function is correctly identified as a function.
267
+ - An unbound method is not identified as a function.
268
+ """
269
+ def dummy_function():
270
+ pass
271
+
272
+ class DummyConcrete:
273
+ def bar(self):
274
+ return 42
275
+
276
+ self.assertTrue(Reflection.isFunction(dummy_function))
277
+ # Unbound methods in Python 3 are just functions, so this should be True
278
+ self.assertTrue(Reflection.isFunction(DummyConcrete.bar))
279
+
280
+ async def testIsGenerator(self):
281
+ """
282
+ Test Reflection.isGenerator to verify correct identification of generator objects.
283
+
284
+ Returns
285
+ -------
286
+ None
287
+
288
+ Asserts
289
+ -------
290
+ - Reflection.isGenerator returns True for a generator object.
291
+ - Reflection.isGenerator returns False for a regular function.
292
+ """
293
+ def dummy_generator():
294
+ yield 1
295
+
296
+ def dummy_function():
297
+ pass
298
+
299
+ gen = dummy_generator()
300
+ self.assertTrue(Reflection.isGenerator(gen))
301
+ self.assertFalse(Reflection.isGenerator(dummy_function))
302
+
303
+ async def testIsGeneratorFunction(self):
304
+ """
305
+ Test Reflection.isGeneratorFunction to verify correct identification of generator functions.
306
+
307
+ Returns
308
+ -------
309
+ None
310
+
311
+ Asserts
312
+ -------
313
+ - Reflection.isGeneratorFunction(dummy_generator) returns True.
314
+ - Reflection.isGeneratorFunction(dummy_function) returns False.
315
+ """
316
+ def dummy_generator():
317
+ yield 1
318
+
319
+ def dummy_function():
320
+ pass
321
+
322
+ self.assertTrue(Reflection.isGeneratorFunction(dummy_generator))
323
+ self.assertFalse(Reflection.isGeneratorFunction(dummy_function))
324
+
325
+ async def testIsGetSetDescriptor(self):
326
+ """
327
+ Test Reflection.isGetSetDescriptor to verify correct identification of get-set descriptors.
328
+
329
+ Returns
330
+ -------
331
+ None
332
+
333
+ Asserts
334
+ -------
335
+ - Reflection.isGetSetDescriptor returns True for a known get-set descriptor.
336
+ - Reflection.isGetSetDescriptor returns False for a non-descriptor object.
337
+ """
338
+ self.assertTrue(Reflection.isGetSetDescriptor(type.__dict__['__dict__']))
339
+ self.assertFalse(Reflection.isGetSetDescriptor(42))
340
+
341
+ async def testIsMemberDescriptor(self):
342
+ """
343
+ Test Reflection.isMemberDescriptor to verify correct identification of member descriptors.
344
+
345
+ Returns
346
+ -------
347
+ None
348
+
349
+ Asserts
350
+ -------
351
+ - type.__dict__['__weakref__'] is recognized as a member descriptor.
352
+ - An integer is not recognized as a member descriptor.
353
+ """
354
+ # Use an alternative member descriptor: use a slot from a new-style class
355
+ class Y:
356
+ __slots__ = ('foo',)
357
+ self.assertTrue(Reflection.isMemberDescriptor(Y.__dict__['foo']))
358
+ self.assertFalse(Reflection.isMemberDescriptor(42))
359
+ self.assertFalse(Reflection.isMemberDescriptor(42))
360
+
361
+ async def testIsMethod(self):
362
+ """
363
+ Test Reflection.isMethod to verify correct identification of methods.
364
+
365
+ Returns
366
+ -------
367
+ None
368
+
369
+ Asserts
370
+ -------
371
+ - Reflection.isMethod returns True for a class method.
372
+ - Reflection.isMethod returns False for a standalone function.
373
+ """
374
+ class DummyConcrete:
375
+ def bar(self):
376
+ return 42
377
+
378
+ obj = DummyConcrete()
379
+ def dummy_function():
380
+ pass
381
+
382
+ self.assertTrue(Reflection.isMethod(obj.bar))
383
+ self.assertFalse(Reflection.isMethod(dummy_function))
384
+
385
+ async def testIsMethodDescriptor(self):
386
+ """
387
+ Test Reflection.isMethodDescriptor to verify correct identification of method descriptors.
388
+
389
+ Returns
390
+ -------
391
+ None
392
+
393
+ Asserts
394
+ -------
395
+ - Reflection.isMethodDescriptor(str.upper) returns True.
396
+ - Reflection.isMethodDescriptor(dummy_function) returns False.
397
+ """
398
+ def dummy_function():
399
+ pass
400
+
401
+ self.assertTrue(Reflection.isMethodDescriptor(str.upper))
402
+ self.assertFalse(Reflection.isMethodDescriptor(dummy_function))
403
+
404
+ async def testIsModule(self):
405
+ """
406
+ Test Reflection.isModule to verify correct identification of module objects.
407
+
408
+ Returns
409
+ -------
410
+ None
411
+
412
+ Asserts
413
+ -------
414
+ - Reflection.isModule returns True for a module (e.g., sys).
415
+ - Reflection.isModule returns False for a non-module (e.g., a function).
416
+ """
417
+ def dummy_function():
418
+ pass
419
+
420
+ self.assertTrue(Reflection.isModule(sys))
421
+ self.assertFalse(Reflection.isModule(dummy_function))
422
+
423
+ async def testIsRoutine(self):
424
+ """
425
+ Test Reflection.isRoutine to verify correct identification of routine objects.
426
+
427
+ Returns
428
+ -------
429
+ None
430
+
431
+ Asserts
432
+ -------
433
+ - A user-defined function is recognized as a routine.
434
+ - A built-in function is recognized as a routine.
435
+ - A non-routine object is not recognized as a routine.
436
+ """
437
+ def dummy_function():
438
+ pass
439
+
440
+ self.assertTrue(Reflection.isRoutine(dummy_function))
441
+ self.assertTrue(Reflection.isRoutine(len))
442
+ self.assertFalse(Reflection.isRoutine(42))
443
+
444
+ async def testIsTraceback(self):
445
+ """
446
+ Test Reflection.isTraceback to verify correct identification of traceback objects.
447
+
448
+ Returns
449
+ -------
450
+ None
451
+
452
+ Asserts
453
+ -------
454
+ - Reflection.isTraceback returns True for a traceback object.
455
+ - Reflection.isTraceback returns False for a non-traceback object.
456
+ """
457
+ try:
458
+ raise Exception("test")
459
+ except Exception:
460
+ tb = sys.exc_info()[2]
461
+ self.assertTrue(Reflection.isTraceback(tb))
462
+ self.assertFalse(Reflection.isTraceback(42))
@@ -76,7 +76,7 @@ class TestTestingUnit(TestCase):
76
76
  unit_test = UnitTest()
77
77
  with patch.object(unit_test.loader, 'loadTestsFromName') as mock_load:
78
78
  mock_load.return_value = StandardTestSuite()
79
- result = unit_test.discoverTestsInModule('test_module')
79
+ result = unit_test.discoverTestsInModule(module_name='test_module')
80
80
 
81
81
  mock_load.assert_called_once_with('test_module')
82
82
  self.assertEqual(result, unit_test)