orionis 0.406.0__py3-none-any.whl → 0.407.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/metadata/framework.py +1 -1
- orionis/services/asynchrony/contracts/coroutines.py +13 -5
- orionis/services/asynchrony/coroutines.py +33 -29
- orionis/services/asynchrony/exceptions/exception.py +9 -1
- orionis/services/environment/core/dot_env.py +46 -34
- orionis/services/environment/enums/__init__.py +0 -0
- orionis/services/environment/enums/cast_type.py +42 -0
- orionis/services/environment/serializer/__init__.py +0 -0
- orionis/services/environment/serializer/values.py +21 -0
- orionis/services/environment/validators/__init__.py +0 -0
- orionis/services/environment/validators/key_name.py +46 -0
- orionis/services/environment/validators/types.py +45 -0
- orionis/services/system/contracts/imports.py +38 -18
- orionis/services/system/contracts/workers.py +29 -12
- orionis/services/system/imports.py +65 -25
- orionis/services/system/runtime/imports.py +18 -9
- orionis/services/system/workers.py +49 -16
- orionis/test/output/dumper.py +1 -0
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/METADATA +1 -1
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/RECORD +30 -23
- tests/example/test_example.py +2 -2
- tests/metadata/test_metadata_framework.py +71 -6
- tests/metadata/test_metadata_package.py +55 -10
- tests/services/asynchrony/test_services_asynchrony_coroutine.py +52 -7
- tests/services/system/test_services_system_imports.py +119 -16
- tests/services/system/test_services_system_workers.py +71 -30
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/WHEEL +0 -0
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/top_level.txt +0 -0
- {orionis-0.406.0.dist-info → orionis-0.407.0.dist-info}/zip-safe +0 -0
|
@@ -13,13 +13,23 @@ class TestMetadataFramework(AsyncTestCase):
|
|
|
13
13
|
|
|
14
14
|
async def testConstantsExistAndAreStr(self):
|
|
15
15
|
"""
|
|
16
|
-
|
|
16
|
+
Validate that all metadata constants exist and are of type `str`.
|
|
17
|
+
|
|
18
|
+
This test iterates over a predefined list of metadata constants and checks
|
|
19
|
+
that each constant is present and its type is `str`.
|
|
17
20
|
|
|
18
21
|
Raises
|
|
19
22
|
------
|
|
20
23
|
AssertionError
|
|
21
24
|
If any constant is not a string.
|
|
25
|
+
|
|
26
|
+
Returns
|
|
27
|
+
-------
|
|
28
|
+
None
|
|
29
|
+
This method does not return any value.
|
|
22
30
|
"""
|
|
31
|
+
|
|
32
|
+
# Check each metadata constant for type str
|
|
23
33
|
for const in [
|
|
24
34
|
NAME, VERSION, AUTHOR, AUTHOR_EMAIL, DESCRIPTION,
|
|
25
35
|
SKELETON, FRAMEWORK, DOCS, API, PYTHON_REQUIRES
|
|
@@ -28,27 +38,49 @@ class TestMetadataFramework(AsyncTestCase):
|
|
|
28
38
|
|
|
29
39
|
async def testClassifiersStructure(self):
|
|
30
40
|
"""
|
|
31
|
-
|
|
41
|
+
Ensure that `CLASSIFIERS` is a list of tuples containing strings.
|
|
42
|
+
|
|
43
|
+
This test verifies the structure of the `CLASSIFIERS` constant, ensuring
|
|
44
|
+
it is a list where each element is a tuple, and each tuple contains only strings.
|
|
32
45
|
|
|
33
46
|
Raises
|
|
34
47
|
------
|
|
35
48
|
AssertionError
|
|
36
49
|
If `CLASSIFIERS` is not a list of tuples of strings.
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
None
|
|
54
|
+
This method does not return any value.
|
|
37
55
|
"""
|
|
56
|
+
|
|
57
|
+
# Confirm CLASSIFIERS is a list
|
|
38
58
|
self.assertIsInstance(CLASSIFIERS, list)
|
|
59
|
+
|
|
60
|
+
# Check each item in CLASSIFIERS for tuple of strings
|
|
39
61
|
for item in CLASSIFIERS:
|
|
40
62
|
self.assertIsInstance(item, tuple)
|
|
41
63
|
self.assertTrue(all(isinstance(part, str) for part in item))
|
|
42
64
|
|
|
43
65
|
async def testGetClassifiers(self):
|
|
44
66
|
"""
|
|
45
|
-
|
|
67
|
+
Verify that `get_classifiers` returns a list of classifier strings.
|
|
68
|
+
|
|
69
|
+
This test calls the `get_classifiers` utility function and checks that
|
|
70
|
+
the returned value is a list of strings, each representing a classifier.
|
|
46
71
|
|
|
47
72
|
Raises
|
|
48
73
|
------
|
|
49
74
|
AssertionError
|
|
50
75
|
If the returned value is not a list of strings containing '::'.
|
|
76
|
+
|
|
77
|
+
Returns
|
|
78
|
+
-------
|
|
79
|
+
None
|
|
80
|
+
This method does not return any value.
|
|
51
81
|
"""
|
|
82
|
+
|
|
83
|
+
# Retrieve classifiers and validate their format
|
|
52
84
|
classifiers = get_classifiers()
|
|
53
85
|
self.assertIsInstance(classifiers, list)
|
|
54
86
|
for c in classifiers:
|
|
@@ -57,28 +89,50 @@ class TestMetadataFramework(AsyncTestCase):
|
|
|
57
89
|
|
|
58
90
|
async def testKeywords(self):
|
|
59
91
|
"""
|
|
60
|
-
|
|
92
|
+
Check that `KEYWORDS` is a list of strings and contains required keywords.
|
|
93
|
+
|
|
94
|
+
This test ensures that the `KEYWORDS` constant is a list of strings and
|
|
95
|
+
verifies the presence of specific keywords relevant to the framework.
|
|
61
96
|
|
|
62
97
|
Raises
|
|
63
98
|
------
|
|
64
99
|
AssertionError
|
|
65
100
|
If `KEYWORDS` is not a list of strings or required keywords are missing.
|
|
101
|
+
|
|
102
|
+
Returns
|
|
103
|
+
-------
|
|
104
|
+
None
|
|
105
|
+
This method does not return any value.
|
|
66
106
|
"""
|
|
107
|
+
|
|
108
|
+
# Confirm KEYWORDS is a list of strings
|
|
67
109
|
self.assertIsInstance(KEYWORDS, list)
|
|
68
110
|
for kw in KEYWORDS:
|
|
69
111
|
self.assertIsInstance(kw, str)
|
|
112
|
+
|
|
113
|
+
# Check for required keywords
|
|
70
114
|
self.assertIn("orionis", KEYWORDS)
|
|
71
115
|
self.assertIn("framework", KEYWORDS)
|
|
72
116
|
|
|
73
117
|
async def testRequiresStructure(self):
|
|
74
118
|
"""
|
|
75
|
-
|
|
119
|
+
Validate that `REQUIRES` is a list of 2-element tuples of strings.
|
|
120
|
+
|
|
121
|
+
This test checks the structure of the `REQUIRES` constant, ensuring it is
|
|
122
|
+
a list where each element is a tuple of length 2, and both elements are strings.
|
|
76
123
|
|
|
77
124
|
Raises
|
|
78
125
|
------
|
|
79
126
|
AssertionError
|
|
80
127
|
If `REQUIRES` is not a list of 2-element tuples of strings.
|
|
128
|
+
|
|
129
|
+
Returns
|
|
130
|
+
-------
|
|
131
|
+
None
|
|
132
|
+
This method does not return any value.
|
|
81
133
|
"""
|
|
134
|
+
|
|
135
|
+
# Confirm REQUIRES is a list of 2-element tuples of strings
|
|
82
136
|
self.assertIsInstance(REQUIRES, list)
|
|
83
137
|
for req in REQUIRES:
|
|
84
138
|
self.assertIsInstance(req, tuple)
|
|
@@ -87,13 +141,24 @@ class TestMetadataFramework(AsyncTestCase):
|
|
|
87
141
|
|
|
88
142
|
async def testGetRequires(self):
|
|
89
143
|
"""
|
|
90
|
-
|
|
144
|
+
Ensure that `get_requires` returns a list of requirement strings.
|
|
145
|
+
|
|
146
|
+
This test calls the `get_requires` utility function and checks that the
|
|
147
|
+
returned value is a list of strings, each representing a requirement and
|
|
148
|
+
containing the '>=' version specifier.
|
|
91
149
|
|
|
92
150
|
Raises
|
|
93
151
|
------
|
|
94
152
|
AssertionError
|
|
95
153
|
If the returned value is not a list of strings containing '>='.
|
|
154
|
+
|
|
155
|
+
Returns
|
|
156
|
+
-------
|
|
157
|
+
None
|
|
158
|
+
This method does not return any value.
|
|
96
159
|
"""
|
|
160
|
+
|
|
161
|
+
# Retrieve requirements and validate their format
|
|
97
162
|
requires = get_requires()
|
|
98
163
|
self.assertIsInstance(requires, list)
|
|
99
164
|
for req in requires:
|
|
@@ -6,89 +6,134 @@ class TestPypiPackageApi(AsyncTestCase):
|
|
|
6
6
|
@patch("orionis.metadata.package.PypiPackageApi")
|
|
7
7
|
async def testGetName(self, MockPypiPackageApi):
|
|
8
8
|
"""
|
|
9
|
-
|
|
9
|
+
Tests the `getName` method of the `PypiPackageApi` class.
|
|
10
|
+
|
|
11
|
+
This test verifies that the mocked `getName` method returns the expected package name.
|
|
10
12
|
|
|
11
13
|
Parameters
|
|
12
14
|
----------
|
|
13
15
|
MockPypiPackageApi : MagicMock
|
|
14
|
-
Mocked PypiPackageApi class.
|
|
16
|
+
Mocked `PypiPackageApi` class.
|
|
15
17
|
|
|
16
18
|
Returns
|
|
17
19
|
-------
|
|
18
20
|
None
|
|
21
|
+
This method does not return anything. It asserts the expected behavior.
|
|
19
22
|
"""
|
|
23
|
+
|
|
24
|
+
# Get the mocked API instance
|
|
20
25
|
api = MockPypiPackageApi.return_value
|
|
26
|
+
|
|
27
|
+
# Set the return value for getName
|
|
21
28
|
api.getName.return_value = "orionis"
|
|
29
|
+
|
|
30
|
+
# Assert that getName returns the expected value
|
|
22
31
|
self.assertEqual(api.getName(), "orionis")
|
|
23
32
|
|
|
24
33
|
@patch("orionis.metadata.package.PypiPackageApi")
|
|
25
34
|
async def testGetAuthor(self, MockPypiPackageApi):
|
|
26
35
|
"""
|
|
27
|
-
|
|
36
|
+
Tests the `getAuthor` method of the `PypiPackageApi` class.
|
|
37
|
+
|
|
38
|
+
This test checks that the mocked `getAuthor` method returns the correct author name.
|
|
28
39
|
|
|
29
40
|
Parameters
|
|
30
41
|
----------
|
|
31
42
|
MockPypiPackageApi : MagicMock
|
|
32
|
-
Mocked PypiPackageApi class.
|
|
43
|
+
Mocked `PypiPackageApi` class.
|
|
33
44
|
|
|
34
45
|
Returns
|
|
35
46
|
-------
|
|
36
47
|
None
|
|
48
|
+
This method does not return anything. It asserts the expected behavior.
|
|
37
49
|
"""
|
|
50
|
+
|
|
51
|
+
# Get the mocked API instance
|
|
38
52
|
api = MockPypiPackageApi.return_value
|
|
53
|
+
|
|
54
|
+
# Set the return value for getAuthor
|
|
39
55
|
api.getAuthor.return_value = "Raul Mauricio Uñate Castro"
|
|
56
|
+
|
|
57
|
+
# Assert that getAuthor returns the expected value
|
|
40
58
|
self.assertEqual(api.getAuthor(), "Raul Mauricio Uñate Castro")
|
|
41
59
|
|
|
42
60
|
@patch("orionis.metadata.package.PypiPackageApi")
|
|
43
61
|
async def testGetAuthorEmail(self, MockPypiPackageApi):
|
|
44
62
|
"""
|
|
45
|
-
|
|
63
|
+
Tests the `getAuthorEmail` method of the `PypiPackageApi` class.
|
|
64
|
+
|
|
65
|
+
This test ensures that the mocked `getAuthorEmail` method returns the correct author email address.
|
|
46
66
|
|
|
47
67
|
Parameters
|
|
48
68
|
----------
|
|
49
69
|
MockPypiPackageApi : MagicMock
|
|
50
|
-
Mocked PypiPackageApi class.
|
|
70
|
+
Mocked `PypiPackageApi` class.
|
|
51
71
|
|
|
52
72
|
Returns
|
|
53
73
|
-------
|
|
54
74
|
None
|
|
75
|
+
This method does not return anything. It asserts the expected behavior.
|
|
55
76
|
"""
|
|
77
|
+
|
|
78
|
+
# Get the mocked API instance
|
|
56
79
|
api = MockPypiPackageApi.return_value
|
|
80
|
+
|
|
81
|
+
# Set the return value for getAuthorEmail
|
|
57
82
|
api.getAuthorEmail.return_value = "raulmauriciounate@gmail.com"
|
|
83
|
+
|
|
84
|
+
# Assert that getAuthorEmail returns the expected value
|
|
58
85
|
self.assertEqual(api.getAuthorEmail(), "raulmauriciounate@gmail.com")
|
|
59
86
|
|
|
60
87
|
@patch("orionis.metadata.package.PypiPackageApi")
|
|
61
88
|
async def testGetDescription(self, MockPypiPackageApi):
|
|
62
89
|
"""
|
|
63
|
-
|
|
90
|
+
Tests the `getDescription` method of the `PypiPackageApi` class.
|
|
91
|
+
|
|
92
|
+
This test verifies that the mocked `getDescription` method returns the expected package description.
|
|
64
93
|
|
|
65
94
|
Parameters
|
|
66
95
|
----------
|
|
67
96
|
MockPypiPackageApi : MagicMock
|
|
68
|
-
Mocked PypiPackageApi class.
|
|
97
|
+
Mocked `PypiPackageApi` class.
|
|
69
98
|
|
|
70
99
|
Returns
|
|
71
100
|
-------
|
|
72
101
|
None
|
|
102
|
+
This method does not return anything. It asserts the expected behavior.
|
|
73
103
|
"""
|
|
104
|
+
|
|
105
|
+
# Get the mocked API instance
|
|
74
106
|
api = MockPypiPackageApi.return_value
|
|
107
|
+
|
|
108
|
+
# Set the return value for getDescription
|
|
75
109
|
api.getDescription.return_value = "Orionis Framework – Elegant, Fast, and Powerful."
|
|
110
|
+
|
|
111
|
+
# Assert that getDescription returns the expected value
|
|
76
112
|
self.assertEqual(api.getDescription(), "Orionis Framework – Elegant, Fast, and Powerful.")
|
|
77
113
|
|
|
78
114
|
@patch("orionis.metadata.package.PypiPackageApi")
|
|
79
115
|
async def testGetPythonVersion(self, MockPypiPackageApi):
|
|
80
116
|
"""
|
|
81
|
-
|
|
117
|
+
Tests the `getPythonVersion` method of the `PypiPackageApi` class.
|
|
118
|
+
|
|
119
|
+
This test checks that the mocked `getPythonVersion` method returns the correct Python version requirement.
|
|
82
120
|
|
|
83
121
|
Parameters
|
|
84
122
|
----------
|
|
85
123
|
MockPypiPackageApi : MagicMock
|
|
86
|
-
Mocked PypiPackageApi class.
|
|
124
|
+
Mocked `PypiPackageApi` class.
|
|
87
125
|
|
|
88
126
|
Returns
|
|
89
127
|
-------
|
|
90
128
|
None
|
|
129
|
+
This method does not return anything. It asserts the expected behavior.
|
|
91
130
|
"""
|
|
131
|
+
|
|
132
|
+
# Get the mocked API instance
|
|
92
133
|
api = MockPypiPackageApi.return_value
|
|
134
|
+
|
|
135
|
+
# Set the return value for getPythonVersion
|
|
93
136
|
api.getPythonVersion.return_value = ">=3.12"
|
|
137
|
+
|
|
138
|
+
# Assert that getPythonVersion returns the expected value
|
|
94
139
|
self.assertEqual(api.getPythonVersion(), ">=3.12")
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
|
+
import asyncio
|
|
2
3
|
from orionis.services.asynchrony.coroutines import Coroutine
|
|
3
4
|
from orionis.services.asynchrony.exceptions import OrionisCoroutineException
|
|
4
5
|
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
@@ -7,34 +8,78 @@ class TestServicesAsynchronyCoroutine(AsyncTestCase):
|
|
|
7
8
|
|
|
8
9
|
async def testExecuteWithActiveEventLoop(self):
|
|
9
10
|
"""
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
Tests coroutine execution within an active event loop.
|
|
12
|
+
|
|
13
|
+
This method verifies that a coroutine can be executed successfully when an event loop is already running,
|
|
14
|
+
such as in asynchronous environments (e.g., Jupyter notebooks or ASGI applications). It ensures that the
|
|
15
|
+
Coroutine wrapper correctly awaits and returns the result of the coroutine.
|
|
16
|
+
|
|
17
|
+
Returns
|
|
18
|
+
-------
|
|
19
|
+
None
|
|
20
|
+
This is a test method and does not return a value. It asserts that the coroutine result matches the expected output.
|
|
13
21
|
"""
|
|
22
|
+
|
|
23
|
+
# Simple coroutine that returns a string
|
|
14
24
|
async def sample_coroutine():
|
|
25
|
+
asyncio.sleep(0.1)
|
|
15
26
|
return "Hello, World!"
|
|
16
27
|
|
|
28
|
+
# Await the result of running the coroutine using the Coroutine wrapper
|
|
17
29
|
result = await Coroutine(sample_coroutine()).run()
|
|
30
|
+
|
|
31
|
+
# Assert that the result matches the expected output
|
|
18
32
|
self.assertEqual(result, "Hello, World!")
|
|
19
33
|
|
|
20
34
|
def testExecuteWithoutActiveEventLoop(self):
|
|
21
35
|
"""
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
Tests coroutine execution without an active event loop.
|
|
37
|
+
|
|
38
|
+
This method simulates the scenario where a coroutine is executed in a synchronous context,
|
|
39
|
+
such as a standard Python script, where no event loop is running. It verifies that the
|
|
40
|
+
Coroutine wrapper can correctly create and manage an event loop internally, execute the
|
|
41
|
+
coroutine, and return the expected result.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
None
|
|
46
|
+
This test method does not return a value. It asserts that the coroutine result matches the expected output.
|
|
24
47
|
"""
|
|
48
|
+
|
|
49
|
+
# Define a simple coroutine that returns a string
|
|
25
50
|
async def sample_coroutine():
|
|
51
|
+
asyncio.sleep(0.1)
|
|
26
52
|
return "Hello, World!"
|
|
27
53
|
|
|
54
|
+
# Run the coroutine using the Coroutine wrapper, which should handle event loop creation
|
|
28
55
|
result = Coroutine(sample_coroutine()).run()
|
|
56
|
+
|
|
57
|
+
# Assert that the result matches the expected output
|
|
29
58
|
self.assertEqual(result, "Hello, World!")
|
|
30
59
|
|
|
31
60
|
def testExecuteWithNonCoroutine(self):
|
|
32
61
|
"""
|
|
33
|
-
|
|
34
|
-
|
|
62
|
+
Tests execution of a non-coroutine object.
|
|
63
|
+
|
|
64
|
+
This method verifies that passing a non-coroutine object to the Coroutine wrapper
|
|
65
|
+
raises an OrionisCoroutineException. It ensures that the Coroutine class enforces
|
|
66
|
+
the requirement for coroutine objects and does not accept regular functions or other types.
|
|
67
|
+
|
|
68
|
+
Parameters
|
|
69
|
+
----------
|
|
70
|
+
self : TestServicesAsynchronyCoroutine
|
|
71
|
+
The test case instance.
|
|
72
|
+
|
|
73
|
+
Returns
|
|
74
|
+
-------
|
|
75
|
+
None
|
|
76
|
+
This test method does not return a value. It asserts that the appropriate exception is raised.
|
|
35
77
|
"""
|
|
78
|
+
|
|
79
|
+
# Define a regular function (not a coroutine)
|
|
36
80
|
def sample_no_coroutine():
|
|
37
81
|
return "Hello, World!"
|
|
38
82
|
|
|
83
|
+
# Assert that passing a non-coroutine raises OrionisCoroutineException
|
|
39
84
|
with self.assertRaises(OrionisCoroutineException):
|
|
40
85
|
Coroutine(sample_no_coroutine())
|
|
@@ -1,101 +1,204 @@
|
|
|
1
|
-
from orionis.services.system.imports import Imports
|
|
2
|
-
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
3
1
|
import sys
|
|
4
2
|
import types
|
|
3
|
+
from orionis.services.system.imports import Imports
|
|
4
|
+
from orionis.test.cases.asynchronous import AsyncTestCase
|
|
5
5
|
|
|
6
6
|
class TestServicesSystemImports(AsyncTestCase):
|
|
7
7
|
|
|
8
|
-
def testImportModule(self) -> None:
|
|
8
|
+
async def testImportModule(self) -> None:
|
|
9
9
|
"""
|
|
10
|
-
|
|
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.
|
|
11
15
|
|
|
12
16
|
Returns
|
|
13
17
|
-------
|
|
14
18
|
None
|
|
19
|
+
This method does not return any value.
|
|
15
20
|
"""
|
|
21
|
+
|
|
22
|
+
# Create an instance of Imports
|
|
16
23
|
imports = Imports()
|
|
24
|
+
|
|
25
|
+
# Populate the imports list
|
|
17
26
|
imports.collect()
|
|
27
|
+
|
|
28
|
+
# Assert that the instance is of type Imports
|
|
18
29
|
self.assertIsInstance(imports, Imports)
|
|
19
30
|
|
|
20
|
-
def testCollectPopulatesImports(self):
|
|
31
|
+
async def testCollectPopulatesImports(self):
|
|
21
32
|
"""
|
|
22
|
-
|
|
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.
|
|
23
42
|
|
|
24
43
|
Returns
|
|
25
44
|
-------
|
|
26
45
|
None
|
|
46
|
+
This method does not return any value.
|
|
27
47
|
"""
|
|
48
|
+
|
|
49
|
+
# Create a dummy module and set its __file__ attribute
|
|
28
50
|
dummy_mod = types.ModuleType("dummy_mod")
|
|
29
51
|
dummy_mod.__file__ = __file__
|
|
52
|
+
|
|
53
|
+
# Add a dummy function to the module and set its __module__ attribute
|
|
30
54
|
def dummy_func(): pass
|
|
31
55
|
dummy_mod.dummy_func = dummy_func
|
|
32
56
|
dummy_func.__module__ = "dummy_mod"
|
|
57
|
+
|
|
58
|
+
# Register the dummy module in sys.modules
|
|
33
59
|
sys.modules["dummy_mod"] = dummy_mod
|
|
34
60
|
|
|
61
|
+
# Create Imports instance and collect imports
|
|
35
62
|
imports = Imports()
|
|
36
63
|
imports.collect()
|
|
64
|
+
|
|
65
|
+
# Check if the dummy module was collected
|
|
37
66
|
found = any(imp["name"] == "dummy_mod" for imp in imports.imports)
|
|
38
67
|
self.assertTrue(found)
|
|
39
68
|
|
|
40
|
-
# Cleanup
|
|
69
|
+
# Cleanup: remove the dummy module from sys.modules
|
|
41
70
|
del sys.modules["dummy_mod"]
|
|
42
71
|
|
|
43
|
-
def testCollectExcludesStdlibAndSpecialModules(self):
|
|
72
|
+
async def testCollectExcludesStdlibAndSpecialModules(self):
|
|
44
73
|
"""
|
|
45
|
-
|
|
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.
|
|
46
84
|
|
|
47
85
|
Returns
|
|
48
86
|
-------
|
|
49
87
|
None
|
|
88
|
+
This method does not return any value.
|
|
50
89
|
"""
|
|
90
|
+
|
|
91
|
+
# Create Imports instance and collect imports
|
|
51
92
|
imports = Imports()
|
|
52
93
|
imports.collect()
|
|
94
|
+
|
|
95
|
+
# Extract the names of collected modules
|
|
53
96
|
names = [imp["name"] for imp in imports.imports]
|
|
97
|
+
|
|
98
|
+
# Assert that '__main__' is not in the collected imports
|
|
54
99
|
self.assertNotIn("__main__", names)
|
|
100
|
+
|
|
101
|
+
# Assert that modules starting with '_distutils' are not in the collected imports
|
|
55
102
|
self.assertFalse(any(n.startswith("_distutils") for n in names))
|
|
56
103
|
|
|
57
|
-
def testClearEmptiesImports(self):
|
|
104
|
+
async def testClearEmptiesImports(self):
|
|
58
105
|
"""
|
|
59
|
-
|
|
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.
|
|
60
115
|
|
|
61
116
|
Returns
|
|
62
117
|
-------
|
|
63
118
|
None
|
|
119
|
+
This method does not return any value.
|
|
64
120
|
"""
|
|
121
|
+
# Create Imports instance and manually populate the imports list
|
|
65
122
|
imports = Imports()
|
|
66
123
|
imports.imports = [{"name": "test", "file": "test.py", "symbols": ["a"]}]
|
|
124
|
+
|
|
125
|
+
# Call clear() to empty the imports list
|
|
67
126
|
imports.clear()
|
|
127
|
+
|
|
128
|
+
# Assert that the imports list is now empty
|
|
68
129
|
self.assertEqual(imports.imports, [])
|
|
69
130
|
|
|
70
|
-
def testCollectHandlesModulesWithoutFile(self):
|
|
131
|
+
async def testCollectHandlesModulesWithoutFile(self):
|
|
71
132
|
"""
|
|
72
|
-
|
|
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.
|
|
73
143
|
|
|
74
144
|
Returns
|
|
75
145
|
-------
|
|
76
146
|
None
|
|
147
|
+
This method does not return any value.
|
|
77
148
|
"""
|
|
149
|
+
# Create a dummy module without a __file__ attribute
|
|
78
150
|
mod = types.ModuleType("mod_without_file")
|
|
79
151
|
sys.modules["mod_without_file"] = mod
|
|
152
|
+
|
|
153
|
+
# Create Imports instance and collect imports
|
|
80
154
|
imports = Imports()
|
|
81
155
|
imports.collect()
|
|
156
|
+
|
|
157
|
+
# Extract the names of collected modules
|
|
82
158
|
names = [imp["name"] for imp in imports.imports]
|
|
159
|
+
|
|
160
|
+
# Assert that the dummy module is not in the collected imports
|
|
83
161
|
self.assertNotIn("mod_without_file", names)
|
|
162
|
+
|
|
163
|
+
# Cleanup: remove the dummy module from sys.modules
|
|
84
164
|
del sys.modules["mod_without_file"]
|
|
85
165
|
|
|
86
|
-
def testCollectSkipsBinaryExtensions(self):
|
|
166
|
+
async def testCollectSkipsBinaryExtensions(self):
|
|
87
167
|
"""
|
|
88
|
-
|
|
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.
|
|
89
179
|
|
|
90
180
|
Returns
|
|
91
181
|
-------
|
|
92
182
|
None
|
|
183
|
+
This method does not return any value.
|
|
93
184
|
"""
|
|
185
|
+
|
|
186
|
+
# Create a dummy module with a .pyd file extension to simulate a binary extension
|
|
94
187
|
mod = types.ModuleType("bin_mod")
|
|
95
188
|
mod.__file__ = "bin_mod.pyd"
|
|
189
|
+
|
|
190
|
+
# Register the dummy binary module in sys.modules
|
|
96
191
|
sys.modules["bin_mod"] = mod
|
|
192
|
+
|
|
193
|
+
# Create Imports instance and collect imports
|
|
97
194
|
imports = Imports()
|
|
98
195
|
imports.collect()
|
|
196
|
+
|
|
197
|
+
# Extract the names of collected modules
|
|
99
198
|
names = [imp["name"] for imp in imports.imports]
|
|
199
|
+
|
|
200
|
+
# Assert that the binary module is not in the collected imports
|
|
100
201
|
self.assertNotIn("bin_mod", names)
|
|
101
|
-
|
|
202
|
+
|
|
203
|
+
# Cleanup: remove the dummy binary module from sys.modules
|
|
204
|
+
del sys.modules["bin_mod"]
|