orionis 0.546.0__py3-none-any.whl → 0.547.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orionis/console/base/scheduler_event_listener.py +0 -17
- orionis/console/contracts/schedule_event_listener.py +0 -18
- orionis/foundation/config/app/entities/app.py +3 -2
- orionis/foundation/config/app/enums/ciphers.py +5 -19
- orionis/foundation/config/session/entities/session.py +2 -2
- orionis/metadata/framework.py +1 -1
- orionis/services/encrypter/encrypter.py +115 -0
- orionis/services/environment/dynamic/caster.py +35 -27
- orionis/services/environment/key/key_generator.py +32 -11
- {orionis-0.546.0.dist-info → orionis-0.547.0.dist-info}/METADATA +1 -1
- {orionis-0.546.0.dist-info → orionis-0.547.0.dist-info}/RECORD +15 -159
- {orionis-0.546.0.dist-info → orionis-0.547.0.dist-info}/top_level.txt +0 -1
- tests/container/__init__.py +0 -0
- tests/container/context/__init__.py +0 -0
- tests/container/context/test_manager.py +0 -38
- tests/container/context/test_scope.py +0 -32
- tests/container/core/__init__.py +0 -0
- tests/container/core/test_advanced_async.py +0 -234
- tests/container/core/test_async_optimizations.py +0 -268
- tests/container/core/test_container.py +0 -453
- tests/container/core/test_singleton.py +0 -122
- tests/container/core/test_thread_safety.py +0 -90
- tests/container/entities/__init__.py +0 -0
- tests/container/entities/test_binding.py +0 -242
- tests/container/enums/__init__.py +0 -0
- tests/container/enums/test_lifetimes.py +0 -97
- tests/container/facades/__init__.py +0 -0
- tests/container/facades/test_facade.py +0 -78
- tests/container/mocks/__init__.py +0 -0
- tests/container/mocks/mock_advanced_async.py +0 -332
- tests/container/mocks/mock_async_optimizations.py +0 -407
- tests/container/mocks/mock_auto_resolution.py +0 -192
- tests/container/mocks/mock_complex_classes.py +0 -792
- tests/container/mocks/mock_simple_classes.py +0 -98
- tests/container/providers/__init__.py +0 -0
- tests/container/providers/test_providers.py +0 -55
- tests/container/validators/__init__.py +0 -0
- tests/container/validators/test_implements.py +0 -186
- tests/container/validators/test_is_abstract_class.py +0 -147
- tests/container/validators/test_is_callable.py +0 -102
- tests/container/validators/test_is_concrete_class.py +0 -160
- tests/container/validators/test_is_instance.py +0 -150
- tests/container/validators/test_is_not_subclass.py +0 -49
- tests/container/validators/test_is_subclass.py +0 -178
- tests/container/validators/test_is_valid_alias.py +0 -147
- tests/container/validators/test_lifetime.py +0 -106
- tests/example/__init__.py +0 -0
- tests/example/test_example.py +0 -725
- tests/foundation/__init__.py +0 -0
- tests/foundation/config/__init__.py +0 -0
- tests/foundation/config/app/__init__.py +0 -0
- tests/foundation/config/app/test_foundation_config_app.py +0 -262
- tests/foundation/config/auth/__init__.py +0 -0
- tests/foundation/config/auth/test_foundation_config_auth.py +0 -29
- tests/foundation/config/cache/__init__.py +0 -0
- tests/foundation/config/cache/test_foundation_config_cache.py +0 -143
- tests/foundation/config/cache/test_foundation_config_cache_file.py +0 -126
- tests/foundation/config/cache/test_foundation_config_cache_stores.py +0 -156
- tests/foundation/config/cors/__init__.py +0 -0
- tests/foundation/config/cors/test_foundation_config_cors.py +0 -190
- tests/foundation/config/database/__init__.py +0 -0
- tests/foundation/config/database/test_foundation_config_database.py +0 -158
- tests/foundation/config/database/test_foundation_config_database_connections.py +0 -203
- tests/foundation/config/database/test_foundation_config_database_mysql.py +0 -354
- tests/foundation/config/database/test_foundation_config_database_oracle.py +0 -288
- tests/foundation/config/database/test_foundation_config_database_pgsql.py +0 -257
- tests/foundation/config/database/test_foundation_config_database_sqlite.py +0 -207
- tests/foundation/config/filesystems/__init__.py +0 -0
- tests/foundation/config/filesystems/test_foundation_config_filesystems.py +0 -160
- tests/foundation/config/filesystems/test_foundation_config_filesystems_aws.py +0 -189
- tests/foundation/config/filesystems/test_foundation_config_filesystems_disks.py +0 -184
- tests/foundation/config/filesystems/test_foundation_config_filesystems_local.py +0 -143
- tests/foundation/config/filesystems/test_foundation_config_filesystems_public.py +0 -184
- tests/foundation/config/logging/__init__.py +0 -0
- tests/foundation/config/logging/test_foundation_config_logging.py +0 -112
- tests/foundation/config/logging/test_foundation_config_logging_channels.py +0 -246
- tests/foundation/config/logging/test_foundation_config_logging_chunked.py +0 -217
- tests/foundation/config/logging/test_foundation_config_logging_daily.py +0 -220
- tests/foundation/config/logging/test_foundation_config_logging_hourly.py +0 -196
- tests/foundation/config/logging/test_foundation_config_logging_monthly.py +0 -214
- tests/foundation/config/logging/test_foundation_config_logging_stack.py +0 -178
- tests/foundation/config/logging/test_foundation_config_logging_weekly.py +0 -224
- tests/foundation/config/mail/__init__.py +0 -0
- tests/foundation/config/mail/test_foundation_config_mail.py +0 -145
- tests/foundation/config/mail/test_foundation_config_mail_file.py +0 -97
- tests/foundation/config/mail/test_foundation_config_mail_mailers.py +0 -106
- tests/foundation/config/mail/test_foundation_config_mail_smtp.py +0 -146
- tests/foundation/config/queue/__init__.py +0 -0
- tests/foundation/config/queue/test_foundation_config_queue.py +0 -88
- tests/foundation/config/queue/test_foundation_config_queue_brokers.py +0 -72
- tests/foundation/config/queue/test_foundation_config_queue_database.py +0 -134
- tests/foundation/config/root/__init__.py +0 -0
- tests/foundation/config/root/test_foundation_config_root_paths.py +0 -112
- tests/foundation/config/session/__init__.py +0 -0
- tests/foundation/config/session/test_foundation_config_session.py +0 -213
- tests/foundation/config/startup/__init__.py +0 -0
- tests/foundation/config/startup/test_foundation_config_startup.py +0 -202
- tests/foundation/config/testing/__init__.py +0 -0
- tests/foundation/config/testing/test_foundation_config_testing.py +0 -235
- tests/metadata/__init__.py +0 -0
- tests/metadata/test_metadata_framework.py +0 -140
- tests/metadata/test_metadata_package.py +0 -139
- tests/services/__init__.py +0 -0
- tests/services/asynchrony/__init__.py +0 -0
- tests/services/asynchrony/test_services_asynchrony_coroutine.py +0 -85
- tests/services/environment/__init__.py +0 -0
- tests/services/environment/test_services_environment.py +0 -226
- tests/services/introspection/__init__.py +0 -0
- tests/services/introspection/dependencies/__init__.py +0 -0
- tests/services/introspection/dependencies/mocks/__init__.py +0 -0
- tests/services/introspection/dependencies/mocks/mock_user.py +0 -30
- tests/services/introspection/dependencies/mocks/mock_user_controller.py +0 -27
- tests/services/introspection/dependencies/mocks/mock_users_permissions.py +0 -41
- tests/services/introspection/dependencies/test_reflect_dependencies.py +0 -261
- tests/services/introspection/reflection/__init__.py +0 -0
- tests/services/introspection/reflection/mock/__init__.py +0 -0
- tests/services/introspection/reflection/mock/fake_reflect_instance.py +0 -1115
- tests/services/introspection/reflection/test_reflection_abstract.py +0 -1011
- tests/services/introspection/reflection/test_reflection_callable.py +0 -206
- tests/services/introspection/reflection/test_reflection_concrete.py +0 -952
- tests/services/introspection/reflection/test_reflection_instance.py +0 -1233
- tests/services/introspection/reflection/test_reflection_module.py +0 -567
- tests/services/introspection/test_reflection.py +0 -462
- tests/services/log/__init__.py +0 -0
- tests/services/log/test_log.py +0 -97
- tests/services/system/__init__.py +0 -0
- tests/services/system/test_services_system_imports.py +0 -204
- tests/services/system/test_services_system_workers.py +0 -131
- tests/support/__init__.py +0 -0
- tests/support/entities/__init__.py +0 -0
- tests/support/entities/mock_dataclass.py +0 -40
- tests/support/entities/test_base.py +0 -64
- tests/support/patterns/__init__.py +0 -0
- tests/support/patterns/singleton/__init__.py +0 -0
- tests/support/patterns/singleton/test_patterns_singleton.py +0 -39
- tests/support/standard/__init__.py +0 -0
- tests/support/standard/test_services_std.py +0 -226
- tests/support/wrapper/__init__.py +0 -0
- tests/support/wrapper/test_services_wrapper_docdict.py +0 -202
- tests/testing/__init__.py +0 -0
- tests/testing/cases/__init__.py +0 -0
- tests/testing/cases/test_testing_asynchronous.py +0 -63
- tests/testing/cases/test_testing_synchronous.py +0 -57
- tests/testing/entities/__init__.py +0 -0
- tests/testing/entities/test_testing_result.py +0 -146
- tests/testing/enums/__init__.py +0 -0
- tests/testing/enums/test_testing_status.py +0 -63
- tests/testing/output/__init__.py +0 -0
- tests/testing/output/test_testing_dumper.py +0 -29
- tests/testing/output/test_testing_printer.py +0 -42
- tests/testing/records/__init__.py +0 -0
- tests/testing/records/test_testing_records.py +0 -171
- tests/testing/test_testing_unit.py +0 -164
- tests/testing/validators/__init__.py +0 -0
- tests/testing/validators/test_testing_validators.py +0 -392
- tests/testing/view/__init__.py +0 -0
- tests/testing/view/test_render.py +0 -30
- {orionis-0.546.0.dist-info → orionis-0.547.0.dist-info}/WHEEL +0 -0
- {orionis-0.546.0.dist-info → orionis-0.547.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.546.0.dist-info → orionis-0.547.0.dist-info}/zip-safe +0 -0
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import types
|
|
3
|
-
from orionis.services.system.imports import Imports
|
|
4
|
-
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
5
|
-
|
|
6
|
-
class TestServicesSystemImports(AsyncTestCase):
|
|
7
|
-
|
|
8
|
-
async def testImportModule(self) -> None:
|
|
9
|
-
"""
|
|
10
|
-
Tests that an Imports instance can be created and that the collect() method
|
|
11
|
-
successfully populates its imports list.
|
|
12
|
-
|
|
13
|
-
This test verifies the basic instantiation of the Imports class and ensures
|
|
14
|
-
that the collect() method executes without errors.
|
|
15
|
-
|
|
16
|
-
Returns
|
|
17
|
-
-------
|
|
18
|
-
None
|
|
19
|
-
This method does not return any value.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
# Create an instance of Imports
|
|
23
|
-
imports = Imports()
|
|
24
|
-
|
|
25
|
-
# Populate the imports list
|
|
26
|
-
imports.collect()
|
|
27
|
-
|
|
28
|
-
# Assert that the instance is of type Imports
|
|
29
|
-
self.assertIsInstance(imports, Imports)
|
|
30
|
-
|
|
31
|
-
async def testCollectPopulatesImports(self):
|
|
32
|
-
"""
|
|
33
|
-
Tests that the `collect()` method of the Imports class populates the imports list with modules.
|
|
34
|
-
|
|
35
|
-
This test creates a dummy module, adds it to `sys.modules`, and verifies that after calling
|
|
36
|
-
`collect()`, the dummy module appears in the `imports` list of the Imports instance.
|
|
37
|
-
|
|
38
|
-
Parameters
|
|
39
|
-
----------
|
|
40
|
-
self : TestServicesSystemImports
|
|
41
|
-
The test case instance.
|
|
42
|
-
|
|
43
|
-
Returns
|
|
44
|
-
-------
|
|
45
|
-
None
|
|
46
|
-
This method does not return any value.
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
# Create a dummy module and set its __file__ attribute
|
|
50
|
-
dummy_mod = types.ModuleType("dummy_mod")
|
|
51
|
-
dummy_mod.__file__ = __file__
|
|
52
|
-
|
|
53
|
-
# Add a dummy function to the module and set its __module__ attribute
|
|
54
|
-
def dummy_func(): pass
|
|
55
|
-
dummy_mod.dummy_func = dummy_func
|
|
56
|
-
dummy_func.__module__ = "dummy_mod"
|
|
57
|
-
|
|
58
|
-
# Register the dummy module in sys.modules
|
|
59
|
-
sys.modules["dummy_mod"] = dummy_mod
|
|
60
|
-
|
|
61
|
-
# Create Imports instance and collect imports
|
|
62
|
-
imports = Imports()
|
|
63
|
-
imports.collect()
|
|
64
|
-
|
|
65
|
-
# Check if the dummy module was collected
|
|
66
|
-
found = any(imp["name"] == "dummy_mod" for imp in imports.imports)
|
|
67
|
-
self.assertTrue(found)
|
|
68
|
-
|
|
69
|
-
# Cleanup: remove the dummy module from sys.modules
|
|
70
|
-
del sys.modules["dummy_mod"]
|
|
71
|
-
|
|
72
|
-
async def testCollectExcludesStdlibAndSpecialModules(self):
|
|
73
|
-
"""
|
|
74
|
-
Tests that the `collect()` method of the Imports class excludes standard library modules and special modules.
|
|
75
|
-
|
|
76
|
-
This test verifies that after calling `collect()`, the resulting imports list does not contain entries for
|
|
77
|
-
standard library modules such as `__main__` or modules whose names start with `_distutils`. This ensures
|
|
78
|
-
that the Imports class correctly filters out modules that should not be included in the imports list.
|
|
79
|
-
|
|
80
|
-
Parameters
|
|
81
|
-
----------
|
|
82
|
-
self : TestServicesSystemImports
|
|
83
|
-
The test case instance.
|
|
84
|
-
|
|
85
|
-
Returns
|
|
86
|
-
-------
|
|
87
|
-
None
|
|
88
|
-
This method does not return any value.
|
|
89
|
-
"""
|
|
90
|
-
|
|
91
|
-
# Create Imports instance and collect imports
|
|
92
|
-
imports = Imports()
|
|
93
|
-
imports.collect()
|
|
94
|
-
|
|
95
|
-
# Extract the names of collected modules
|
|
96
|
-
names = [imp["name"] for imp in imports.imports]
|
|
97
|
-
|
|
98
|
-
# Assert that '__main__' is not in the collected imports
|
|
99
|
-
self.assertNotIn("__main__", names)
|
|
100
|
-
|
|
101
|
-
# Assert that modules starting with '_distutils' are not in the collected imports
|
|
102
|
-
self.assertFalse(any(n.startswith("_distutils") for n in names))
|
|
103
|
-
|
|
104
|
-
async def testClearEmptiesImports(self):
|
|
105
|
-
"""
|
|
106
|
-
Tests that the `clear()` method of the Imports class empties the imports list.
|
|
107
|
-
|
|
108
|
-
This test manually populates the `imports` attribute of an Imports instance,
|
|
109
|
-
calls the `clear()` method, and verifies that the imports list is empty afterward.
|
|
110
|
-
|
|
111
|
-
Parameters
|
|
112
|
-
----------
|
|
113
|
-
self : TestServicesSystemImports
|
|
114
|
-
The test case instance.
|
|
115
|
-
|
|
116
|
-
Returns
|
|
117
|
-
-------
|
|
118
|
-
None
|
|
119
|
-
This method does not return any value.
|
|
120
|
-
"""
|
|
121
|
-
# Create Imports instance and manually populate the imports list
|
|
122
|
-
imports = Imports()
|
|
123
|
-
imports.imports = [{"name": "test", "file": "test.py", "symbols": ["a"]}]
|
|
124
|
-
|
|
125
|
-
# Call clear() to empty the imports list
|
|
126
|
-
imports.clear()
|
|
127
|
-
|
|
128
|
-
# Assert that the imports list is now empty
|
|
129
|
-
self.assertEqual(imports.imports, [])
|
|
130
|
-
|
|
131
|
-
async def testCollectHandlesModulesWithoutFile(self):
|
|
132
|
-
"""
|
|
133
|
-
Tests that the `collect()` method of the Imports class correctly handles modules that do not have a `__file__` attribute.
|
|
134
|
-
|
|
135
|
-
This test creates a dummy module without a `__file__` attribute, registers it in `sys.modules`, and verifies that after calling
|
|
136
|
-
`collect()`, the module does not appear in the `imports` list of the Imports instance. This ensures that the Imports class
|
|
137
|
-
properly skips modules lacking a `__file__` attribute, which are typically built-in or dynamically created modules.
|
|
138
|
-
|
|
139
|
-
Parameters
|
|
140
|
-
----------
|
|
141
|
-
self : TestServicesSystemImports
|
|
142
|
-
The test case instance.
|
|
143
|
-
|
|
144
|
-
Returns
|
|
145
|
-
-------
|
|
146
|
-
None
|
|
147
|
-
This method does not return any value.
|
|
148
|
-
"""
|
|
149
|
-
# Create a dummy module without a __file__ attribute
|
|
150
|
-
mod = types.ModuleType("mod_without_file")
|
|
151
|
-
sys.modules["mod_without_file"] = mod
|
|
152
|
-
|
|
153
|
-
# Create Imports instance and collect imports
|
|
154
|
-
imports = Imports()
|
|
155
|
-
imports.collect()
|
|
156
|
-
|
|
157
|
-
# Extract the names of collected modules
|
|
158
|
-
names = [imp["name"] for imp in imports.imports]
|
|
159
|
-
|
|
160
|
-
# Assert that the dummy module is not in the collected imports
|
|
161
|
-
self.assertNotIn("mod_without_file", names)
|
|
162
|
-
|
|
163
|
-
# Cleanup: remove the dummy module from sys.modules
|
|
164
|
-
del sys.modules["mod_without_file"]
|
|
165
|
-
|
|
166
|
-
async def testCollectSkipsBinaryExtensions(self):
|
|
167
|
-
"""
|
|
168
|
-
Tests that the `collect()` method of the Imports class skips binary extension modules.
|
|
169
|
-
|
|
170
|
-
This test creates a dummy module with a `.pyd` file extension (representing a binary extension),
|
|
171
|
-
registers it in `sys.modules`, and verifies that after calling `collect()`, the module does not
|
|
172
|
-
appear in the `imports` list of the Imports instance. This ensures that the Imports class
|
|
173
|
-
properly excludes binary extension modules from its collected imports.
|
|
174
|
-
|
|
175
|
-
Parameters
|
|
176
|
-
----------
|
|
177
|
-
self : TestServicesSystemImports
|
|
178
|
-
The test case instance.
|
|
179
|
-
|
|
180
|
-
Returns
|
|
181
|
-
-------
|
|
182
|
-
None
|
|
183
|
-
This method does not return any value.
|
|
184
|
-
"""
|
|
185
|
-
|
|
186
|
-
# Create a dummy module with a .pyd file extension to simulate a binary extension
|
|
187
|
-
mod = types.ModuleType("bin_mod")
|
|
188
|
-
mod.__file__ = "bin_mod.pyd"
|
|
189
|
-
|
|
190
|
-
# Register the dummy binary module in sys.modules
|
|
191
|
-
sys.modules["bin_mod"] = mod
|
|
192
|
-
|
|
193
|
-
# Create Imports instance and collect imports
|
|
194
|
-
imports = Imports()
|
|
195
|
-
imports.collect()
|
|
196
|
-
|
|
197
|
-
# Extract the names of collected modules
|
|
198
|
-
names = [imp["name"] for imp in imports.imports]
|
|
199
|
-
|
|
200
|
-
# Assert that the binary module is not in the collected imports
|
|
201
|
-
self.assertNotIn("bin_mod", names)
|
|
202
|
-
|
|
203
|
-
# Cleanup: remove the dummy binary module from sys.modules
|
|
204
|
-
del sys.modules["bin_mod"]
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
from unittest.mock import patch
|
|
2
|
-
from orionis.services.system.workers import Workers
|
|
3
|
-
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
4
|
-
|
|
5
|
-
class TestServicesSystemWorkers(AsyncTestCase):
|
|
6
|
-
|
|
7
|
-
@patch('multiprocessing.cpu_count', return_value=8)
|
|
8
|
-
@patch('psutil.virtual_memory')
|
|
9
|
-
def testCalculateCpuLimited(self, mockVm, mockCpuCount):
|
|
10
|
-
"""
|
|
11
|
-
Tests worker calculation when CPU count is the limiting factor.
|
|
12
|
-
|
|
13
|
-
Simulates a system with 8 CPUs and 16 GB RAM, where each worker requires 1 GB of RAM.
|
|
14
|
-
Although the available RAM could support up to 16 workers, the CPU count restricts the number
|
|
15
|
-
of workers to 8.
|
|
16
|
-
|
|
17
|
-
Parameters
|
|
18
|
-
----------
|
|
19
|
-
mockVm : unittest.mock.Mock
|
|
20
|
-
Mock object for `psutil.virtual_memory`.
|
|
21
|
-
mockCpuCount : unittest.mock.Mock
|
|
22
|
-
Mock object for `multiprocessing.cpu_count`.
|
|
23
|
-
|
|
24
|
-
Returns
|
|
25
|
-
-------
|
|
26
|
-
None
|
|
27
|
-
Asserts that the calculated number of workers is limited by CPU count.
|
|
28
|
-
"""
|
|
29
|
-
|
|
30
|
-
# Set the mocked total RAM to 16 GB
|
|
31
|
-
mockVm.return_value.total = 16 * 1024 ** 3
|
|
32
|
-
|
|
33
|
-
# Create Workers instance with 1 GB RAM required per worker
|
|
34
|
-
workers = Workers(ram_per_worker=1)
|
|
35
|
-
|
|
36
|
-
# Assert that the number of workers is limited to 8 by CPU count
|
|
37
|
-
self.assertEqual(workers.calculate(), 8)
|
|
38
|
-
|
|
39
|
-
@patch('multiprocessing.cpu_count', return_value=32)
|
|
40
|
-
@patch('psutil.virtual_memory')
|
|
41
|
-
def testCalculateRamLimited(self, mockVm, mockCpuCount):
|
|
42
|
-
"""
|
|
43
|
-
Tests worker calculation when RAM is the limiting factor.
|
|
44
|
-
|
|
45
|
-
Simulates a system with 32 CPUs and 4 GB RAM, where each worker requires 1 GB of RAM.
|
|
46
|
-
Although the CPU count could support up to 32 workers, the available RAM restricts the number
|
|
47
|
-
of workers to 4.
|
|
48
|
-
|
|
49
|
-
Parameters
|
|
50
|
-
----------
|
|
51
|
-
mockVm : unittest.mock.Mock
|
|
52
|
-
Mock object for `psutil.virtual_memory`.
|
|
53
|
-
mockCpuCount : unittest.mock.Mock
|
|
54
|
-
Mock object for `multiprocessing.cpu_count`.
|
|
55
|
-
|
|
56
|
-
Returns
|
|
57
|
-
-------
|
|
58
|
-
None
|
|
59
|
-
Asserts that the calculated number of workers is limited by available RAM.
|
|
60
|
-
"""
|
|
61
|
-
|
|
62
|
-
# Set the mocked total RAM to 4 GB
|
|
63
|
-
mockVm.return_value.total = 4 * 1024 ** 3
|
|
64
|
-
|
|
65
|
-
# Create Workers instance with 1 GB RAM required per worker
|
|
66
|
-
workers = Workers(ram_per_worker=1)
|
|
67
|
-
|
|
68
|
-
# Assert that the number of workers is limited to 4 by available RAM
|
|
69
|
-
self.assertEqual(workers.calculate(), 4)
|
|
70
|
-
|
|
71
|
-
@patch('multiprocessing.cpu_count', return_value=4)
|
|
72
|
-
@patch('psutil.virtual_memory')
|
|
73
|
-
def testCalculateExactFit(self, mockVm, mockCpuCount):
|
|
74
|
-
"""
|
|
75
|
-
Tests worker calculation when both CPU count and available RAM allow for the same number of workers.
|
|
76
|
-
|
|
77
|
-
Simulates a system with 4 CPUs and 2 GB RAM, where each worker requires 0.5 GB of RAM.
|
|
78
|
-
Both CPU and RAM resources permit exactly 4 workers, so the calculation should return 4.
|
|
79
|
-
|
|
80
|
-
Parameters
|
|
81
|
-
----------
|
|
82
|
-
mockVm : unittest.mock.Mock
|
|
83
|
-
Mock object for `psutil.virtual_memory`.
|
|
84
|
-
mockCpuCount : unittest.mock.Mock
|
|
85
|
-
Mock object for `multiprocessing.cpu_count`.
|
|
86
|
-
|
|
87
|
-
Returns
|
|
88
|
-
-------
|
|
89
|
-
None
|
|
90
|
-
Asserts that the calculated number of workers is 4, matching both CPU and RAM constraints.
|
|
91
|
-
"""
|
|
92
|
-
# Set the mocked total RAM to 2 GB
|
|
93
|
-
mockVm.return_value.total = 2 * 1024 ** 3
|
|
94
|
-
|
|
95
|
-
# Create Workers instance with 0.5 GB RAM required per worker
|
|
96
|
-
workers = Workers(ram_per_worker=0.5)
|
|
97
|
-
|
|
98
|
-
# Assert that the number of workers is limited to 4 by both CPU and RAM
|
|
99
|
-
self.assertEqual(workers.calculate(), 4)
|
|
100
|
-
|
|
101
|
-
@patch('multiprocessing.cpu_count', return_value=2)
|
|
102
|
-
@patch('psutil.virtual_memory')
|
|
103
|
-
def testCalculateLowRam(self, mockVm, mockCpuCount):
|
|
104
|
-
"""
|
|
105
|
-
Tests worker calculation when available RAM is lower than CPU count, restricting the number of workers.
|
|
106
|
-
|
|
107
|
-
Simulates a system with 2 CPUs and 0.7 GB RAM, where each worker requires 0.5 GB of RAM.
|
|
108
|
-
Although the CPU count could support up to 2 workers, the available RAM restricts the number
|
|
109
|
-
of workers to 1.
|
|
110
|
-
|
|
111
|
-
Parameters
|
|
112
|
-
----------
|
|
113
|
-
mockVm : unittest.mock.Mock
|
|
114
|
-
Mock object for `psutil.virtual_memory`.
|
|
115
|
-
mockCpuCount : unittest.mock.Mock
|
|
116
|
-
Mock object for `multiprocessing.cpu_count`.
|
|
117
|
-
|
|
118
|
-
Returns
|
|
119
|
-
-------
|
|
120
|
-
None
|
|
121
|
-
Asserts that the calculated number of workers is limited to 1 by available RAM.
|
|
122
|
-
"""
|
|
123
|
-
|
|
124
|
-
# Set the mocked total RAM to 0.7 GB
|
|
125
|
-
mockVm.return_value.total = 0.7 * 1024 ** 3
|
|
126
|
-
|
|
127
|
-
# Create Workers instance with 0.5 GB RAM required per worker
|
|
128
|
-
workers = Workers(ram_per_worker=0.5)
|
|
129
|
-
|
|
130
|
-
# Assert that the number of workers is limited to 1 by available RAM
|
|
131
|
-
self.assertEqual(workers.calculate(), 1)
|
tests/support/__init__.py
DELETED
|
File without changes
|
|
File without changes
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass, field
|
|
2
|
-
from enum import Enum
|
|
3
|
-
from orionis.support.entities.base import BaseEntity
|
|
4
|
-
|
|
5
|
-
class Color(Enum):
|
|
6
|
-
"""Enumeration for available colors."""
|
|
7
|
-
RED = 1
|
|
8
|
-
GREEN = 2
|
|
9
|
-
|
|
10
|
-
@dataclass
|
|
11
|
-
class ExampleEntity(BaseEntity):
|
|
12
|
-
"""
|
|
13
|
-
Data structure representing an example entity with an identifier, name, color, and tags.
|
|
14
|
-
|
|
15
|
-
Parameters
|
|
16
|
-
----------
|
|
17
|
-
id : int, optional
|
|
18
|
-
Unique identifier for the entity. Default is 0.
|
|
19
|
-
name : str, optional
|
|
20
|
-
Name of the entity. Default is 'default'.
|
|
21
|
-
color : Color, optional
|
|
22
|
-
Color associated with the entity. Default is Color.RED.
|
|
23
|
-
tags : list, optional
|
|
24
|
-
List of tags associated with the entity. Default is an empty list.
|
|
25
|
-
|
|
26
|
-
Attributes
|
|
27
|
-
----------
|
|
28
|
-
id : int
|
|
29
|
-
Unique identifier for the entity.
|
|
30
|
-
name : str
|
|
31
|
-
Name of the entity.
|
|
32
|
-
color : Color
|
|
33
|
-
Color associated with the entity.
|
|
34
|
-
tags : list
|
|
35
|
-
List of tags associated with the entity.
|
|
36
|
-
"""
|
|
37
|
-
id: int = 0 # Default id is 0
|
|
38
|
-
name: str = "default" # Default name is 'default'
|
|
39
|
-
color: Color = Color.RED # Default color is RED
|
|
40
|
-
tags: list = field(default_factory=list, metadata={"default": ["tag1", "tag2"]}) # Default tags list
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
2
|
-
from tests.support.entities.mock_dataclass import Color, ExampleEntity
|
|
3
|
-
|
|
4
|
-
class TestBaseEntity(AsyncTestCase):
|
|
5
|
-
|
|
6
|
-
async def asyncSetUp(self):
|
|
7
|
-
"""
|
|
8
|
-
Asynchronously initializes the test environment before each test.
|
|
9
|
-
|
|
10
|
-
Initializes an ExampleEntity instance with predefined attributes and assigns it to self.entity.
|
|
11
|
-
|
|
12
|
-
Returns
|
|
13
|
-
-------
|
|
14
|
-
None
|
|
15
|
-
"""
|
|
16
|
-
# Create an ExampleEntity instance for use in tests
|
|
17
|
-
self.entity = ExampleEntity(id=42, name="test", color=Color.GREEN, tags=["a", "b"])
|
|
18
|
-
|
|
19
|
-
async def testToDict(self):
|
|
20
|
-
"""
|
|
21
|
-
Tests the toDict method of ExampleEntity.
|
|
22
|
-
|
|
23
|
-
Verifies that toDict returns a dictionary with correct field values for the entity.
|
|
24
|
-
|
|
25
|
-
Returns
|
|
26
|
-
-------
|
|
27
|
-
None
|
|
28
|
-
"""
|
|
29
|
-
# Convert entity to dictionary
|
|
30
|
-
result = self.entity.toDict()
|
|
31
|
-
self.assertIsInstance(result, dict)
|
|
32
|
-
|
|
33
|
-
# Check individual field values
|
|
34
|
-
self.assertEqual(result["id"], 42)
|
|
35
|
-
self.assertEqual(result["name"], "test")
|
|
36
|
-
self.assertEqual(result["color"], Color.GREEN)
|
|
37
|
-
self.assertEqual(result["tags"], ["a", "b"])
|
|
38
|
-
|
|
39
|
-
async def testGetFields(self):
|
|
40
|
-
"""
|
|
41
|
-
Tests the getFields method of ExampleEntity.
|
|
42
|
-
|
|
43
|
-
Ensures getFields returns a list of dictionaries, each containing field name, types, default value, and metadata.
|
|
44
|
-
|
|
45
|
-
Returns
|
|
46
|
-
-------
|
|
47
|
-
None
|
|
48
|
-
"""
|
|
49
|
-
# Retrieve field information from entity
|
|
50
|
-
fields_info = self.entity.getFields()
|
|
51
|
-
self.assertIsInstance(fields_info, list)
|
|
52
|
-
|
|
53
|
-
# Extract field names for verification
|
|
54
|
-
names = [f["name"] for f in fields_info]
|
|
55
|
-
self.assertIn("id", names)
|
|
56
|
-
self.assertIn("name", names)
|
|
57
|
-
self.assertIn("color", names)
|
|
58
|
-
self.assertIn("tags", names)
|
|
59
|
-
|
|
60
|
-
# Check that each field info contains required keys
|
|
61
|
-
for f in fields_info:
|
|
62
|
-
self.assertIn("types", f)
|
|
63
|
-
self.assertIn("default", f)
|
|
64
|
-
self.assertIn("metadata", f)
|
|
File without changes
|
|
File without changes
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
from orionis.support.patterns.singleton import Singleton
|
|
2
|
-
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
3
|
-
|
|
4
|
-
class TestPatternsSingleton(AsyncTestCase):
|
|
5
|
-
|
|
6
|
-
async def testSingleton(self):
|
|
7
|
-
"""
|
|
8
|
-
Test the Singleton metaclass to ensure only one instance is created.
|
|
9
|
-
|
|
10
|
-
This test verifies that a class using the Singleton metaclass will always return
|
|
11
|
-
the same instance, regardless of how many times it is instantiated. It also checks
|
|
12
|
-
that the initial state of the singleton instance does not change after subsequent
|
|
13
|
-
instantiations with different arguments.
|
|
14
|
-
|
|
15
|
-
Parameters
|
|
16
|
-
----------
|
|
17
|
-
self : TestPatternsSingleton
|
|
18
|
-
Instance of the test case.
|
|
19
|
-
|
|
20
|
-
Returns
|
|
21
|
-
-------
|
|
22
|
-
None
|
|
23
|
-
"""
|
|
24
|
-
# Define a class using the Singleton metaclass
|
|
25
|
-
class SingletonClass(metaclass=Singleton):
|
|
26
|
-
def __init__(self, value):
|
|
27
|
-
self.value = value
|
|
28
|
-
|
|
29
|
-
# Create the first instance of SingletonClass
|
|
30
|
-
instance1 = SingletonClass(1)
|
|
31
|
-
|
|
32
|
-
# Attempt to create a second instance with a different value
|
|
33
|
-
instance2 = SingletonClass(2)
|
|
34
|
-
|
|
35
|
-
# Assert that both instances are actually the same object
|
|
36
|
-
self.assertIs(instance1, instance2)
|
|
37
|
-
|
|
38
|
-
# Assert that the value remains as set by the first instantiation
|
|
39
|
-
self.assertEqual(instance1.value, 1)
|
|
File without changes
|