orionis 0.546.0__py3-none-any.whl → 0.548.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 (160) hide show
  1. orionis/console/base/scheduler_event_listener.py +0 -17
  2. orionis/console/contracts/schedule_event_listener.py +0 -18
  3. orionis/foundation/config/app/entities/app.py +3 -2
  4. orionis/foundation/config/app/enums/ciphers.py +5 -19
  5. orionis/foundation/config/session/entities/session.py +2 -2
  6. orionis/metadata/framework.py +1 -1
  7. orionis/services/encrypter/encrypter.py +115 -0
  8. orionis/services/environment/dynamic/caster.py +35 -27
  9. orionis/services/environment/key/key_generator.py +32 -11
  10. {orionis-0.546.0.dist-info → orionis-0.548.0.dist-info}/METADATA +1 -1
  11. {orionis-0.546.0.dist-info → orionis-0.548.0.dist-info}/RECORD +14 -159
  12. {orionis-0.546.0.dist-info → orionis-0.548.0.dist-info}/top_level.txt +0 -1
  13. orionis-0.546.0.dist-info/zip-safe +0 -1
  14. tests/container/__init__.py +0 -0
  15. tests/container/context/__init__.py +0 -0
  16. tests/container/context/test_manager.py +0 -38
  17. tests/container/context/test_scope.py +0 -32
  18. tests/container/core/__init__.py +0 -0
  19. tests/container/core/test_advanced_async.py +0 -234
  20. tests/container/core/test_async_optimizations.py +0 -268
  21. tests/container/core/test_container.py +0 -453
  22. tests/container/core/test_singleton.py +0 -122
  23. tests/container/core/test_thread_safety.py +0 -90
  24. tests/container/entities/__init__.py +0 -0
  25. tests/container/entities/test_binding.py +0 -242
  26. tests/container/enums/__init__.py +0 -0
  27. tests/container/enums/test_lifetimes.py +0 -97
  28. tests/container/facades/__init__.py +0 -0
  29. tests/container/facades/test_facade.py +0 -78
  30. tests/container/mocks/__init__.py +0 -0
  31. tests/container/mocks/mock_advanced_async.py +0 -332
  32. tests/container/mocks/mock_async_optimizations.py +0 -407
  33. tests/container/mocks/mock_auto_resolution.py +0 -192
  34. tests/container/mocks/mock_complex_classes.py +0 -792
  35. tests/container/mocks/mock_simple_classes.py +0 -98
  36. tests/container/providers/__init__.py +0 -0
  37. tests/container/providers/test_providers.py +0 -55
  38. tests/container/validators/__init__.py +0 -0
  39. tests/container/validators/test_implements.py +0 -186
  40. tests/container/validators/test_is_abstract_class.py +0 -147
  41. tests/container/validators/test_is_callable.py +0 -102
  42. tests/container/validators/test_is_concrete_class.py +0 -160
  43. tests/container/validators/test_is_instance.py +0 -150
  44. tests/container/validators/test_is_not_subclass.py +0 -49
  45. tests/container/validators/test_is_subclass.py +0 -178
  46. tests/container/validators/test_is_valid_alias.py +0 -147
  47. tests/container/validators/test_lifetime.py +0 -106
  48. tests/example/__init__.py +0 -0
  49. tests/example/test_example.py +0 -725
  50. tests/foundation/__init__.py +0 -0
  51. tests/foundation/config/__init__.py +0 -0
  52. tests/foundation/config/app/__init__.py +0 -0
  53. tests/foundation/config/app/test_foundation_config_app.py +0 -262
  54. tests/foundation/config/auth/__init__.py +0 -0
  55. tests/foundation/config/auth/test_foundation_config_auth.py +0 -29
  56. tests/foundation/config/cache/__init__.py +0 -0
  57. tests/foundation/config/cache/test_foundation_config_cache.py +0 -143
  58. tests/foundation/config/cache/test_foundation_config_cache_file.py +0 -126
  59. tests/foundation/config/cache/test_foundation_config_cache_stores.py +0 -156
  60. tests/foundation/config/cors/__init__.py +0 -0
  61. tests/foundation/config/cors/test_foundation_config_cors.py +0 -190
  62. tests/foundation/config/database/__init__.py +0 -0
  63. tests/foundation/config/database/test_foundation_config_database.py +0 -158
  64. tests/foundation/config/database/test_foundation_config_database_connections.py +0 -203
  65. tests/foundation/config/database/test_foundation_config_database_mysql.py +0 -354
  66. tests/foundation/config/database/test_foundation_config_database_oracle.py +0 -288
  67. tests/foundation/config/database/test_foundation_config_database_pgsql.py +0 -257
  68. tests/foundation/config/database/test_foundation_config_database_sqlite.py +0 -207
  69. tests/foundation/config/filesystems/__init__.py +0 -0
  70. tests/foundation/config/filesystems/test_foundation_config_filesystems.py +0 -160
  71. tests/foundation/config/filesystems/test_foundation_config_filesystems_aws.py +0 -189
  72. tests/foundation/config/filesystems/test_foundation_config_filesystems_disks.py +0 -184
  73. tests/foundation/config/filesystems/test_foundation_config_filesystems_local.py +0 -143
  74. tests/foundation/config/filesystems/test_foundation_config_filesystems_public.py +0 -184
  75. tests/foundation/config/logging/__init__.py +0 -0
  76. tests/foundation/config/logging/test_foundation_config_logging.py +0 -112
  77. tests/foundation/config/logging/test_foundation_config_logging_channels.py +0 -246
  78. tests/foundation/config/logging/test_foundation_config_logging_chunked.py +0 -217
  79. tests/foundation/config/logging/test_foundation_config_logging_daily.py +0 -220
  80. tests/foundation/config/logging/test_foundation_config_logging_hourly.py +0 -196
  81. tests/foundation/config/logging/test_foundation_config_logging_monthly.py +0 -214
  82. tests/foundation/config/logging/test_foundation_config_logging_stack.py +0 -178
  83. tests/foundation/config/logging/test_foundation_config_logging_weekly.py +0 -224
  84. tests/foundation/config/mail/__init__.py +0 -0
  85. tests/foundation/config/mail/test_foundation_config_mail.py +0 -145
  86. tests/foundation/config/mail/test_foundation_config_mail_file.py +0 -97
  87. tests/foundation/config/mail/test_foundation_config_mail_mailers.py +0 -106
  88. tests/foundation/config/mail/test_foundation_config_mail_smtp.py +0 -146
  89. tests/foundation/config/queue/__init__.py +0 -0
  90. tests/foundation/config/queue/test_foundation_config_queue.py +0 -88
  91. tests/foundation/config/queue/test_foundation_config_queue_brokers.py +0 -72
  92. tests/foundation/config/queue/test_foundation_config_queue_database.py +0 -134
  93. tests/foundation/config/root/__init__.py +0 -0
  94. tests/foundation/config/root/test_foundation_config_root_paths.py +0 -112
  95. tests/foundation/config/session/__init__.py +0 -0
  96. tests/foundation/config/session/test_foundation_config_session.py +0 -213
  97. tests/foundation/config/startup/__init__.py +0 -0
  98. tests/foundation/config/startup/test_foundation_config_startup.py +0 -202
  99. tests/foundation/config/testing/__init__.py +0 -0
  100. tests/foundation/config/testing/test_foundation_config_testing.py +0 -235
  101. tests/metadata/__init__.py +0 -0
  102. tests/metadata/test_metadata_framework.py +0 -140
  103. tests/metadata/test_metadata_package.py +0 -139
  104. tests/services/__init__.py +0 -0
  105. tests/services/asynchrony/__init__.py +0 -0
  106. tests/services/asynchrony/test_services_asynchrony_coroutine.py +0 -85
  107. tests/services/environment/__init__.py +0 -0
  108. tests/services/environment/test_services_environment.py +0 -226
  109. tests/services/introspection/__init__.py +0 -0
  110. tests/services/introspection/dependencies/__init__.py +0 -0
  111. tests/services/introspection/dependencies/mocks/__init__.py +0 -0
  112. tests/services/introspection/dependencies/mocks/mock_user.py +0 -30
  113. tests/services/introspection/dependencies/mocks/mock_user_controller.py +0 -27
  114. tests/services/introspection/dependencies/mocks/mock_users_permissions.py +0 -41
  115. tests/services/introspection/dependencies/test_reflect_dependencies.py +0 -261
  116. tests/services/introspection/reflection/__init__.py +0 -0
  117. tests/services/introspection/reflection/mock/__init__.py +0 -0
  118. tests/services/introspection/reflection/mock/fake_reflect_instance.py +0 -1115
  119. tests/services/introspection/reflection/test_reflection_abstract.py +0 -1011
  120. tests/services/introspection/reflection/test_reflection_callable.py +0 -206
  121. tests/services/introspection/reflection/test_reflection_concrete.py +0 -952
  122. tests/services/introspection/reflection/test_reflection_instance.py +0 -1233
  123. tests/services/introspection/reflection/test_reflection_module.py +0 -567
  124. tests/services/introspection/test_reflection.py +0 -462
  125. tests/services/log/__init__.py +0 -0
  126. tests/services/log/test_log.py +0 -97
  127. tests/services/system/__init__.py +0 -0
  128. tests/services/system/test_services_system_imports.py +0 -204
  129. tests/services/system/test_services_system_workers.py +0 -131
  130. tests/support/__init__.py +0 -0
  131. tests/support/entities/__init__.py +0 -0
  132. tests/support/entities/mock_dataclass.py +0 -40
  133. tests/support/entities/test_base.py +0 -64
  134. tests/support/patterns/__init__.py +0 -0
  135. tests/support/patterns/singleton/__init__.py +0 -0
  136. tests/support/patterns/singleton/test_patterns_singleton.py +0 -39
  137. tests/support/standard/__init__.py +0 -0
  138. tests/support/standard/test_services_std.py +0 -226
  139. tests/support/wrapper/__init__.py +0 -0
  140. tests/support/wrapper/test_services_wrapper_docdict.py +0 -202
  141. tests/testing/__init__.py +0 -0
  142. tests/testing/cases/__init__.py +0 -0
  143. tests/testing/cases/test_testing_asynchronous.py +0 -63
  144. tests/testing/cases/test_testing_synchronous.py +0 -57
  145. tests/testing/entities/__init__.py +0 -0
  146. tests/testing/entities/test_testing_result.py +0 -146
  147. tests/testing/enums/__init__.py +0 -0
  148. tests/testing/enums/test_testing_status.py +0 -63
  149. tests/testing/output/__init__.py +0 -0
  150. tests/testing/output/test_testing_dumper.py +0 -29
  151. tests/testing/output/test_testing_printer.py +0 -42
  152. tests/testing/records/__init__.py +0 -0
  153. tests/testing/records/test_testing_records.py +0 -171
  154. tests/testing/test_testing_unit.py +0 -164
  155. tests/testing/validators/__init__.py +0 -0
  156. tests/testing/validators/test_testing_validators.py +0 -392
  157. tests/testing/view/__init__.py +0 -0
  158. tests/testing/view/test_render.py +0 -30
  159. {orionis-0.546.0.dist-info → orionis-0.548.0.dist-info}/WHEEL +0 -0
  160. {orionis-0.546.0.dist-info → orionis-0.548.0.dist-info}/licenses/LICENCE +0 -0
@@ -1,725 +0,0 @@
1
- import asyncio
2
- import time
3
- from typing import Dict, List, Any
4
- from orionis.foundation.application import Application
5
- from orionis.services.system.contracts.workers import IWorkers
6
- from orionis.test.cases.asynchronous import AsyncTestCase
7
- from orionis.test.cases.synchronous import SyncTestCase
8
-
9
- class TestSynchronousExample(SyncTestCase):
10
- """
11
- Synchronous test example demonstrating Orionis framework capabilities.
12
-
13
- This class showcases various testing patterns including dependency injection,
14
- path resolution, container usage, and error handling in a synchronous context.
15
- The tests demonstrate best practices for writing maintainable and reliable
16
- test cases within the Orionis framework.
17
- """
18
-
19
- def setUp(self) -> None:
20
- """
21
- Set up test environment before each test method.
22
-
23
- Initializes test data dictionary with sample files and expected values
24
- that will be used across multiple test methods. This method is called
25
- automatically before each test method execution.
26
-
27
- Notes
28
- -----
29
- The test_data dictionary contains:
30
- - sample_file: Path to the current test file for path resolution tests
31
- - expected_values: List of integers used in assertion validation tests
32
- """
33
- self.test_data: Dict[str, Any] = {
34
- "sample_file": "tests/example/test_example.py",
35
- "expected_values": [1, 2, 3, 4, 5]
36
- }
37
-
38
- def tearDown(self) -> None:
39
- """
40
- Clean up resources after each test method completion.
41
-
42
- Resets the test_data attribute to None to ensure clean state
43
- between test method executions and prevent memory leaks.
44
- """
45
- self.test_data = None
46
-
47
- def testBasicAssertions(self) -> None:
48
- """
49
- Test basic assertion functionality and patterns.
50
-
51
- Validates the fundamental assertion methods provided by the testing
52
- framework, including equality checks, boolean assertions, and
53
- container membership validation.
54
-
55
- Tests
56
- -----
57
- - Equality assertions (assertEqual)
58
- - Boolean assertions (assertTrue, assertFalse)
59
- - Container membership (assertIn, assertNotIn)
60
-
61
- Raises
62
- ------
63
- AssertionError
64
- If any of the basic assertions fail, indicating a problem
65
- with the testing framework's assertion mechanisms.
66
- """
67
- # Test equality assertions
68
- self.assertEqual(2, 2, "Basic equality check failed")
69
- self.assertEqual(3, 3, "Second equality check failed")
70
-
71
- # Test boolean assertions
72
- self.assertTrue(True, "Boolean true assertion failed")
73
- self.assertFalse(False, "Boolean false assertion failed")
74
-
75
- # Test container assertions
76
- self.assertIn(
77
- 3,
78
- self.test_data["expected_values"],
79
- "Value not found in container"
80
- )
81
- self.assertNotIn(
82
- 10,
83
- self.test_data["expected_values"],
84
- "Unexpected value found in container"
85
- )
86
-
87
- def testMaxWorkers(self, worker: IWorkers) -> None:
88
- """
89
- Test worker service functionality with dependency injection.
90
-
91
- Validates the worker service's ability to calculate the maximum number
92
- of available workers in the system. This method demonstrates dependency
93
- injection capabilities with the IWorkers service and ensures proper
94
- worker count calculation functionality.
95
-
96
- Parameters
97
- ----------
98
- worker : IWorkers
99
- Injected worker service instance for testing worker calculation
100
- capabilities. The service provides methods for determining optimal
101
- worker counts based on system resources.
102
-
103
- Returns
104
- -------
105
- None
106
- This test method does not return any value. It performs assertions
107
- to validate the worker service functionality.
108
-
109
- Tests
110
- -----
111
- - Worker service instance validation
112
- - Worker count calculation functionality
113
- - Worker count positive value validation
114
- - Service method execution through dependency injection
115
-
116
- Raises
117
- ------
118
- AssertionError
119
- If worker count calculation fails, returns invalid values, or
120
- the calculated worker count is not greater than zero.
121
- """
122
-
123
- # Calculate maximum available workers using the injected service
124
- max_workers = worker.calculate()
125
-
126
- # Validate that worker count is greater than zero
127
- self.assertGreater(
128
- max_workers,
129
- 0,
130
- "Worker count should be greater than zero"
131
- )
132
-
133
- def testContainerIntegration(self, container: Application) -> None:
134
- """
135
- Test container dependency injection functionality.
136
-
137
- Validates the application container's ability to resolve services and manage
138
- dependencies correctly. This method demonstrates the dependency injection
139
- capabilities of the Orionis application container, including service
140
- registration, resolution, and lifecycle management. The test ensures that
141
- the container can successfully instantiate and provide service instances
142
- when requested through the dependency injection mechanism.
143
-
144
- Parameters
145
- ----------
146
- container : Application
147
- Injected application container instance for testing dependency
148
- injection capabilities. The container manages service resolution,
149
- dependency lifecycle, and provides access to registered services
150
- throughout the application.
151
-
152
- Returns
153
- -------
154
- None
155
- This test method does not return any value. It performs assertions
156
- to validate the container's dependency injection functionality.
157
-
158
- Tests
159
- -----
160
- - Container instance validation and null checking
161
- - Service resolution from container using interface contracts
162
- - Service functionality validation through container-resolved instances
163
- - Dependency lifecycle management and proper instantiation
164
- - Interface-to-implementation mapping verification
165
-
166
- Raises
167
- ------
168
- AssertionError
169
- If container operations fail, services cannot be resolved, or
170
- the container instance is invalid or None.
171
-
172
- Notes
173
- -----
174
- This test validates the core dependency injection functionality that
175
- is essential for the Orionis framework's service architecture. The
176
- container must be able to resolve services using their interface
177
- contracts and provide properly configured instances.
178
- """
179
-
180
- # Validate that the injected container instance is not None
181
- # This ensures the dependency injection framework is working correctly
182
- self.assertIsNotNone(container, "Container instance should not be None")
183
-
184
- # Attempt to resolve the IWorkers service from the container
185
- # This tests the container's ability to map interfaces to implementations
186
- workers: IWorkers = container.make(IWorkers)
187
-
188
- # Verify that the service resolution was successful
189
- # The container should return a valid instance implementing IWorkers
190
- self.assertIsNotNone(
191
- workers,
192
- "Service resolution should return valid instance"
193
- )
194
-
195
- def testErrorHandling(self) -> None:
196
- """
197
- Test error handling and exception management patterns.
198
-
199
- Validates the framework's ability to handle expected exceptions
200
- and provides examples of proper exception testing patterns.
201
- This method demonstrates both basic exception catching and
202
- regex-based exception message validation.
203
-
204
- Tests
205
- -----
206
- - Basic exception assertion with assertRaises
207
- - Exception message pattern matching with assertRaisesRegex
208
- - Proper exception type validation
209
- - Exception context management
210
-
211
- Raises
212
- ------
213
- AssertionError
214
- If expected exceptions are not raised or have incorrect types.
215
- """
216
- # Test basic exception assertion
217
- with self.assertRaises(ValueError):
218
- raise ValueError("Expected test exception")
219
-
220
- # Test exception message pattern matching
221
- with self.assertRaisesRegex(RuntimeError, r"test.*pattern"):
222
- raise RuntimeError("test error pattern match")
223
-
224
- def testDataValidation(self) -> None:
225
- """
226
- Test data validation and complex assertion patterns.
227
-
228
- Validates complex data structures and demonstrates advanced assertion
229
- techniques including list comparisons, dictionary operations, and
230
- length validation. This method showcases best practices for testing
231
- data integrity and structure validation.
232
-
233
- Tests
234
- -----
235
- - List length validation
236
- - List content comparison with assertListEqual
237
- - Dictionary key existence validation
238
- - Dictionary value validation
239
- - Complex data structure assertions
240
-
241
- Raises
242
- ------
243
- AssertionError
244
- If data validation fails or structures don't match expectations.
245
- """
246
- # Test list operations and validation
247
- test_list = [1, 2, 3, 4, 5]
248
- self.assertEqual(
249
- len(test_list),
250
- 5,
251
- "List length should match expected value"
252
- )
253
- self.assertListEqual(
254
- test_list,
255
- self.test_data["expected_values"],
256
- "List content should match expected values"
257
- )
258
-
259
- # Test dictionary operations and validation
260
- test_dict = {"key1": "value1", "key2": "value2"}
261
- self.assertIn(
262
- "key1",
263
- test_dict,
264
- "Dictionary should contain expected key"
265
- )
266
- self.assertEqual(
267
- test_dict["key1"],
268
- "value1",
269
- "Dictionary value should match expected value"
270
- )
271
-
272
- class TestAsynchronousExample(AsyncTestCase):
273
- """
274
- Asynchronous test example demonstrating async capabilities in Orionis framework.
275
-
276
- This class showcases asynchronous testing patterns including async dependency
277
- injection, concurrent operations, timing validation, and async error handling.
278
- The tests demonstrate best practices for writing async test cases that are
279
- both performant and reliable.
280
-
281
- Attributes
282
- ----------
283
- async_data : Dict[str, Any]
284
- Asynchronous test data dictionary containing timing parameters,
285
- task configuration, and expected results for async operations.
286
-
287
- Methods
288
- -------
289
- asyncSetUp()
290
- Initialize async test environment before each test method.
291
- asyncTearDown()
292
- Clean up async resources after each test method completion.
293
- testAsyncBasicOperations()
294
- Test basic async operations including timing and sleep validation.
295
- testAsyncPathResolution(paths)
296
- Test async path resolution with dependency injection.
297
- testConcurrentOperations()
298
- Test concurrent async operations and task management.
299
- testAsyncErrorHandling()
300
- Test async error handling and timeout management.
301
- testAsyncContainerIntegration(container)
302
- Test async container dependency injection functionality.
303
- testAsyncDataProcessing()
304
- Test async data processing and validation patterns.
305
-
306
- Examples
307
- --------
308
- Basic async usage:
309
- >>> test = TestAsynchronousExample()
310
- >>> await test.asyncSetUp()
311
- >>> await test.testAsyncBasicOperations()
312
- >>> await test.asyncTearDown()
313
-
314
- Concurrent operations:
315
- >>> test = TestAsynchronousExample()
316
- >>> await test.asyncSetUp()
317
- >>> await test.testConcurrentOperations()
318
- >>> await test.asyncTearDown()
319
- """
320
-
321
- async def asyncSetUp(self) -> None:
322
- """
323
- Set up async test environment before each test method.
324
-
325
- Initializes async test data dictionary with timing parameters,
326
- concurrent task configuration, and expected results for async
327
- operations. This method is called automatically before each
328
- async test method execution.
329
-
330
- Notes
331
- -----
332
- The async_data dictionary contains:
333
- - delay_time: Standard delay time for async operations testing
334
- - concurrent_tasks: Number of concurrent tasks for testing
335
- - expected_results: Expected results from concurrent operations
336
- """
337
- self.async_data: Dict[str, Any] = {
338
- "delay_time": 0.1,
339
- "concurrent_tasks": 3,
340
- "expected_results": ["result1", "result2", "result3"]
341
- }
342
-
343
- async def asyncTearDown(self) -> None:
344
- """
345
- Clean up async resources after each test method completion.
346
-
347
- Resets the async_data attribute to None to ensure clean state
348
- between async test method executions and prevent memory leaks.
349
- """
350
- self.async_data = None
351
-
352
- async def testAsyncBasicOperations(self) -> None:
353
- """
354
- Test basic async operations including timing and sleep validation.
355
-
356
- Validates the framework's ability to handle async operations
357
- correctly, including timing precision and sleep duration validation.
358
- This method demonstrates proper async timing testing patterns.
359
-
360
- Tests
361
- -----
362
- - Async sleep duration validation
363
- - Timing precision testing
364
- - Async operation timing boundaries
365
- - Time measurement accuracy
366
-
367
- Raises
368
- ------
369
- AssertionError
370
- If async timing operations don't meet expected constraints.
371
- """
372
- # Test async sleep and timing precision
373
- start_time = time.time()
374
- await asyncio.sleep(self.async_data["delay_time"])
375
- end_time = time.time()
376
-
377
- elapsed = end_time - start_time
378
- self.assertGreaterEqual(
379
- elapsed,
380
- self.async_data["delay_time"],
381
- "Async sleep duration should meet minimum time requirement"
382
- )
383
- self.assertLess(
384
- elapsed,
385
- self.async_data["delay_time"] + 0.05,
386
- "Async sleep duration should not exceed maximum time tolerance"
387
- )
388
-
389
- async def testAsyncMaxWorkers(self, worker: IWorkers) -> None:
390
- """
391
- Test async worker service functionality with dependency injection.
392
-
393
- Validates async worker operations by simulating async I/O
394
- operations and testing worker calculation in an asynchronous context.
395
- This method demonstrates async dependency injection patterns.
396
-
397
- Parameters
398
- ----------
399
- worker : IWorkers
400
- Injected worker service instance for async worker operations.
401
- This parameter is automatically injected by the async testing framework.
402
-
403
- Tests
404
- -----
405
- - Async worker calculation with simulated I/O delay
406
- - Worker count validation in async context
407
- - Worker validation in async operations
408
- - Async service method execution
409
-
410
- Raises
411
- ------
412
- AssertionError
413
- If async worker calculation fails or returns unexpected results.
414
- """
415
- async def calculate_workers_async() -> int:
416
- """
417
- Simulate async worker calculation with I/O delay.
418
-
419
- Returns
420
- -------
421
- int
422
- Calculated maximum workers count.
423
- """
424
- await asyncio.sleep(0.01) # Simulate async I/O operation
425
- return worker.calculate()
426
-
427
- # Test async worker calculation
428
- max_workers = await calculate_workers_async()
429
- self.assertGreater(
430
- max_workers,
431
- 0,
432
- "Async worker calculation should return positive value"
433
- )
434
-
435
- async def testConcurrentOperations(self) -> None:
436
- """
437
- Test concurrent async operations and task management.
438
-
439
- Validates the framework's ability to handle multiple concurrent
440
- async operations correctly, including task creation, execution,
441
- and result aggregation. This method demonstrates proper concurrent
442
- async testing patterns.
443
-
444
- Tests
445
- -----
446
- - Concurrent task creation and execution
447
- - Task result aggregation with asyncio.gather
448
- - Concurrent operation result validation
449
- - Task count and result verification
450
-
451
- Raises
452
- ------
453
- AssertionError
454
- If concurrent operations fail or results don't match expectations.
455
- """
456
- async def async_task(task_id: int) -> str:
457
- """
458
- Simulate async task with unique result.
459
-
460
- Parameters
461
- ----------
462
- task_id : int
463
- Unique identifier for the async task.
464
-
465
- Returns
466
- -------
467
- str
468
- Task result string with task ID.
469
- """
470
- await asyncio.sleep(0.05)
471
- return f"result{task_id}"
472
-
473
- # Create concurrent tasks
474
- tasks = [
475
- async_task(i)
476
- for i in range(1, self.async_data["concurrent_tasks"] + 1)
477
- ]
478
-
479
- # Execute tasks concurrently
480
- results = await asyncio.gather(*tasks)
481
-
482
- # Verify concurrent operation results
483
- self.assertEqual(
484
- len(results),
485
- self.async_data["concurrent_tasks"],
486
- "Concurrent task count should match expected value"
487
- )
488
- self.assertListEqual(
489
- results,
490
- self.async_data["expected_results"],
491
- "Concurrent task results should match expected values"
492
- )
493
-
494
- async def testAsyncErrorHandling(self) -> None:
495
- """
496
- Test async error handling and timeout management.
497
-
498
- Validates the framework's ability to handle async exceptions
499
- and timeout scenarios correctly. This method demonstrates proper
500
- async error handling patterns including exception catching and
501
- timeout management.
502
-
503
- Tests
504
- -----
505
- - Async exception assertion with assertRaises
506
- - Async timeout handling with asyncio.wait_for
507
- - Async exception type validation
508
- - Async context manager exception handling
509
-
510
- Raises
511
- ------
512
- AssertionError
513
- If async error handling doesn't work as expected.
514
- """
515
- async def failing_async_function() -> None:
516
- """
517
- Simulate async function that raises an exception.
518
-
519
- Raises
520
- ------
521
- ValueError
522
- Always raises ValueError for testing purposes.
523
- """
524
- await asyncio.sleep(0.01)
525
- raise ValueError("Async test exception")
526
-
527
- # Test async exception assertion
528
- with self.assertRaises(ValueError):
529
- await failing_async_function()
530
-
531
- async def slow_async_function() -> str:
532
- """
533
- Simulate slow async function for timeout testing.
534
-
535
- Returns
536
- -------
537
- str
538
- Result string after long delay.
539
- """
540
- await asyncio.sleep(1.0)
541
- return "slow result"
542
-
543
- # Test async timeout handling
544
- with self.assertRaises(asyncio.TimeoutError):
545
- await asyncio.wait_for(slow_async_function(), timeout=0.1)
546
-
547
- async def testAsyncContainerIntegration(self, container: Application) -> None:
548
- """
549
- Test async container dependency injection functionality.
550
-
551
- Validates the application container's ability to resolve services and manage
552
- dependencies in asynchronous contexts. This method demonstrates async dependency
553
- injection patterns, service resolution capabilities, and validates that the
554
- container can properly handle service lifecycle management in async environments.
555
- The test ensures that services resolved through the container maintain their
556
- functionality when used in asynchronous operations.
557
-
558
- Parameters
559
- ----------
560
- container : Application
561
- Injected application container instance for testing async dependency
562
- injection capabilities. The container manages service resolution,
563
- dependency lifecycle, and provides access to registered services
564
- throughout the async application context.
565
-
566
- Returns
567
- -------
568
- None
569
- This test method does not return any value. It performs assertions
570
- to validate the container's async dependency injection functionality
571
- and service resolution capabilities in asynchronous contexts.
572
-
573
- Tests
574
- -----
575
- - Async service resolution from container using interface contracts
576
- - Service instance validation after async resolution
577
- - Async service method execution and functionality verification
578
- - Dependency lifecycle management in async contexts
579
- - Interface-to-implementation mapping in async scenarios
580
-
581
- Raises
582
- ------
583
- AssertionError
584
- If async container operations fail, services cannot be resolved,
585
- service methods return invalid results, or the container instance
586
- fails to properly manage async dependencies.
587
-
588
- Notes
589
- -----
590
- This test validates the core async dependency injection functionality
591
- that is essential for the Orionis framework's async service architecture.
592
- The container must be able to resolve services using their interface
593
- contracts and provide properly configured instances that work correctly
594
- in asynchronous execution contexts.
595
- """
596
- async def resolve_service_async() -> IWorkers:
597
- """
598
- Simulate async service resolution with I/O delay.
599
-
600
- Demonstrates async service resolution from the container while
601
- simulating real-world async I/O operations that might occur
602
- during service instantiation or configuration.
603
-
604
- Returns
605
- -------
606
- IWorkers
607
- Resolved worker service instance implementing the IWorkers interface.
608
- """
609
- # Simulate async I/O operation that might occur during service resolution
610
- await asyncio.sleep(0.01)
611
- # Resolve the IWorkers service from the injected container
612
- return container.make(IWorkers)
613
-
614
- # Test async service resolution from the container
615
- # This validates that the container can resolve services in async contexts
616
- worker_service = await resolve_service_async()
617
-
618
- # Verify that the async service resolution was successful
619
- # The container should return a valid instance implementing IWorkers
620
- self.assertIsNotNone(
621
- worker_service,
622
- "Async service resolution should return valid instance"
623
- )
624
-
625
- async def use_service_async() -> int:
626
- """
627
- Simulate async service method execution with I/O delay.
628
-
629
- Demonstrates using a resolved service in an async context while
630
- simulating real-world async operations that might be performed
631
- by the service methods.
632
-
633
- Returns
634
- -------
635
- int
636
- Result from async service method call representing worker count.
637
- """
638
- # Simulate async I/O operation that might occur during service usage
639
- await asyncio.sleep(0.01)
640
- # Execute the calculate method on the resolved worker service
641
- return worker_service.calculate()
642
-
643
- # Test async service method execution after resolution
644
- # This validates that resolved services function properly in async contexts
645
- result = await use_service_async()
646
-
647
- # Verify that the async service method execution returns expected results
648
- # The worker calculation should return a positive integer representing available workers
649
- self.assertGreater(
650
- result,
651
- 0,
652
- "Async service method execution should return positive worker count"
653
- )
654
-
655
- async def testAsyncDataProcessing(self) -> None:
656
- """
657
- Test async data processing and validation patterns.
658
-
659
- Validates async data transformation, processing, and validation
660
- operations. This method demonstrates proper async data handling
661
- patterns and validation techniques.
662
-
663
- Tests
664
- -----
665
- - Async data transformation operations
666
- - Async data validation with type checking
667
- - Async list processing and comparison
668
- - Async data integrity validation
669
-
670
- Raises
671
- ------
672
- AssertionError
673
- If async data processing fails or results don't match expectations.
674
- """
675
- async def process_data_async(data: List[int]) -> List[int]:
676
- """
677
- Simulate async data processing with transformation.
678
-
679
- Parameters
680
- ----------
681
- data : List[int]
682
- Input data list for processing.
683
-
684
- Returns
685
- -------
686
- List[int]
687
- Processed data list with transformed values.
688
- """
689
- await asyncio.sleep(0.01)
690
- return [item * 2 for item in data]
691
-
692
- # Test async data transformation
693
- input_data = [1, 2, 3, 4, 5]
694
- processed_data = await process_data_async(input_data)
695
- expected_data = [2, 4, 6, 8, 10]
696
-
697
- self.assertListEqual(
698
- processed_data,
699
- expected_data,
700
- "Async data processing should transform values correctly"
701
- )
702
-
703
- async def validate_data_async(data: List[int]) -> bool:
704
- """
705
- Simulate async data validation.
706
-
707
- Parameters
708
- ----------
709
- data : List[int]
710
- Data list to validate.
711
-
712
- Returns
713
- -------
714
- bool
715
- True if all items are integers, False otherwise.
716
- """
717
- await asyncio.sleep(0.01)
718
- return all(isinstance(item, int) for item in data)
719
-
720
- # Test async data validation
721
- is_valid = await validate_data_async(processed_data)
722
- self.assertTrue(
723
- is_valid,
724
- "Async data validation should confirm data integrity"
725
- )