orionis 0.414.0__py3-none-any.whl → 0.416.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 (83) hide show
  1. orionis/metadata/framework.py +1 -1
  2. orionis/test/core/unit_test.py +26 -10
  3. orionis/test/output/dumper.py +1 -1
  4. {orionis-0.414.0.dist-info → orionis-0.416.0.dist-info}/METADATA +1 -1
  5. {orionis-0.414.0.dist-info → orionis-0.416.0.dist-info}/RECORD +81 -68
  6. orionis-0.416.0.dist-info/top_level.txt +4 -0
  7. tests/container/entities/test_binding.py +1 -1
  8. tests/container/test_thread_safety.py +0 -1
  9. tests/testing/cases/__init__.py +0 -0
  10. tests/testing/cases/test_testing_asynchronous.py +63 -0
  11. tests/testing/cases/test_testing_synchronous.py +59 -0
  12. tests/testing/entities/__init__.py +0 -0
  13. tests/testing/entities/test_testing_result.py +185 -0
  14. tests/testing/enums/__init__.py +0 -0
  15. tests/testing/enums/test_testing_status.py +68 -0
  16. tests/testing/output/__init__.py +0 -0
  17. tests/testing/output/test_testing_dumper.py +32 -0
  18. tests/testing/output/test_testing_printer.py +42 -0
  19. tests/testing/records/__init__.py +0 -0
  20. tests/testing/records/test_testing_records.py +181 -0
  21. tests/testing/test_testing_unit.py +110 -209
  22. tests/testing/validators/__init__.py +0 -0
  23. tests/testing/validators/test_testing_validators.py +449 -0
  24. orionis-0.414.0.dist-info/top_level.txt +0 -2
  25. tests/testing/test_testing_result.py +0 -131
  26. {tests/foundation → environment}/__init__.py +0 -0
  27. {tests/services/environment → environment}/test_services_environment.py +0 -0
  28. {tests/foundation/config → foundation}/__init__.py +0 -0
  29. {tests/foundation/config/app → foundation/config}/__init__.py +0 -0
  30. {tests/foundation/config/auth → foundation/config/app}/__init__.py +0 -0
  31. {tests/foundation → foundation}/config/app/test_foundation_config_app.py +0 -0
  32. {tests/foundation/config/cache → foundation/config/auth}/__init__.py +0 -0
  33. {tests/foundation → foundation}/config/auth/test_foundation_config_auth.py +0 -0
  34. {tests/foundation/config/cors → foundation/config/cache}/__init__.py +0 -0
  35. {tests/foundation → foundation}/config/cache/test_foundation_config_cache.py +0 -0
  36. {tests/foundation → foundation}/config/cache/test_foundation_config_cache_file.py +0 -0
  37. {tests/foundation → foundation}/config/cache/test_foundation_config_cache_stores.py +0 -0
  38. {tests/foundation/config/database → foundation/config/cors}/__init__.py +0 -0
  39. {tests/foundation → foundation}/config/cors/test_foundation_config_cors.py +0 -0
  40. {tests/foundation/config/filesystems → foundation/config/database}/__init__.py +0 -0
  41. {tests/foundation → foundation}/config/database/test_foundation_config_database.py +0 -0
  42. {tests/foundation → foundation}/config/database/test_foundation_config_database_connections.py +0 -0
  43. {tests/foundation → foundation}/config/database/test_foundation_config_database_mysql.py +0 -0
  44. {tests/foundation → foundation}/config/database/test_foundation_config_database_oracle.py +0 -0
  45. {tests/foundation → foundation}/config/database/test_foundation_config_database_pgsql.py +0 -0
  46. {tests/foundation → foundation}/config/database/test_foundation_config_database_sqlite.py +0 -0
  47. {tests/foundation/config/logging → foundation/config/filesystems}/__init__.py +0 -0
  48. {tests/foundation → foundation}/config/filesystems/test_foundation_config_filesystems.py +0 -0
  49. {tests/foundation → foundation}/config/filesystems/test_foundation_config_filesystems_aws.py +0 -0
  50. {tests/foundation → foundation}/config/filesystems/test_foundation_config_filesystems_disks.py +0 -0
  51. {tests/foundation → foundation}/config/filesystems/test_foundation_config_filesystems_local.py +0 -0
  52. {tests/foundation → foundation}/config/filesystems/test_foundation_config_filesystems_public.py +0 -0
  53. {tests/foundation/config/mail → foundation/config/logging}/__init__.py +0 -0
  54. {tests/foundation → foundation}/config/logging/test_foundation_config_logging.py +0 -0
  55. {tests/foundation → foundation}/config/logging/test_foundation_config_logging_channels.py +0 -0
  56. {tests/foundation → foundation}/config/logging/test_foundation_config_logging_chunked.py +0 -0
  57. {tests/foundation → foundation}/config/logging/test_foundation_config_logging_daily.py +0 -0
  58. {tests/foundation → foundation}/config/logging/test_foundation_config_logging_hourly.py +0 -0
  59. {tests/foundation → foundation}/config/logging/test_foundation_config_logging_monthly.py +0 -0
  60. {tests/foundation → foundation}/config/logging/test_foundation_config_logging_stack.py +0 -0
  61. {tests/foundation → foundation}/config/logging/test_foundation_config_logging_weekly.py +0 -0
  62. {tests/foundation/config/queue → foundation/config/mail}/__init__.py +0 -0
  63. {tests/foundation → foundation}/config/mail/test_foundation_config_mail.py +0 -0
  64. {tests/foundation → foundation}/config/mail/test_foundation_config_mail_file.py +0 -0
  65. {tests/foundation → foundation}/config/mail/test_foundation_config_mail_mailers.py +0 -0
  66. {tests/foundation → foundation}/config/mail/test_foundation_config_mail_smtp.py +0 -0
  67. {tests/foundation/config/root → foundation/config/queue}/__init__.py +0 -0
  68. {tests/foundation → foundation}/config/queue/test_foundation_config_queue.py +0 -0
  69. {tests/foundation → foundation}/config/queue/test_foundation_config_queue_brokers.py +0 -0
  70. {tests/foundation → foundation}/config/queue/test_foundation_config_queue_database.py +0 -0
  71. {tests/foundation/config/session → foundation/config/root}/__init__.py +0 -0
  72. {tests/foundation → foundation}/config/root/test_foundation_config_root_paths.py +0 -0
  73. {tests/foundation/config/startup → foundation/config/session}/__init__.py +0 -0
  74. {tests/foundation → foundation}/config/session/test_foundation_config_session.py +0 -0
  75. {tests/foundation/config/testing → foundation/config/startup}/__init__.py +0 -0
  76. {tests/foundation → foundation}/config/startup/test_foundation_config_startup.py +0 -0
  77. {tests/foundation/exceptions → foundation/config/testing}/__init__.py +0 -0
  78. {tests/foundation → foundation}/config/testing/test_foundation_config_testing.py +0 -0
  79. {tests/services/environment → foundation/exceptions}/__init__.py +0 -0
  80. {tests/foundation → foundation}/exceptions/test_foundation_config_exceptions.py +0 -0
  81. {orionis-0.414.0.dist-info → orionis-0.416.0.dist-info}/WHEEL +0 -0
  82. {orionis-0.414.0.dist-info → orionis-0.416.0.dist-info}/licenses/LICENCE +0 -0
  83. {orionis-0.414.0.dist-info → orionis-0.416.0.dist-info}/zip-safe +0 -0
@@ -0,0 +1,68 @@
1
+ from enum import Enum
2
+ from orionis.test.cases.asynchronous import AsyncTestCase
3
+ from orionis.test.enums.status import TestStatus
4
+
5
+ class TestTestStatus(AsyncTestCase):
6
+
7
+ async def testHasEnumMembers(self):
8
+ """
9
+ Checks that the TestStatus enum contains the expected members.
10
+
11
+ This test verifies the presence of the following enum members:
12
+ 'PASSED', 'FAILED', 'ERRORED', and 'SKIPPED'.
13
+
14
+ Returns
15
+ -------
16
+ None
17
+ This method does not return a value. It asserts the existence of enum members.
18
+ """
19
+ # Assert that each expected member exists in TestStatus
20
+ self.assertTrue(hasattr(TestStatus, "PASSED"))
21
+ self.assertTrue(hasattr(TestStatus, "FAILED"))
22
+ self.assertTrue(hasattr(TestStatus, "ERRORED"))
23
+ self.assertTrue(hasattr(TestStatus, "SKIPPED"))
24
+
25
+ async def testEnumValuesAreUnique(self):
26
+ """
27
+ Ensures that all TestStatus enum member values are unique.
28
+
29
+ This test collects all values from the TestStatus enum and checks for uniqueness.
30
+
31
+ Returns
32
+ -------
33
+ None
34
+ This method does not return a value. It asserts the uniqueness of enum values.
35
+ """
36
+ # Gather all enum values
37
+ values = [status.value for status in TestStatus]
38
+ # Assert that the number of values equals the number of unique values
39
+ self.assertEqual(len(values), len(set(values)))
40
+
41
+ async def testEnumIsInstanceOfEnum(self):
42
+ """
43
+ Validates that TestStatus is a subclass of Enum.
44
+
45
+ This test checks the inheritance of TestStatus from the Enum base class.
46
+
47
+ Returns
48
+ -------
49
+ None
50
+ This method does not return a value. It asserts the subclass relationship.
51
+ """
52
+ # Assert that TestStatus inherits from Enum
53
+ self.assertTrue(issubclass(TestStatus, Enum))
54
+
55
+ async def testEnumMembersType(self):
56
+ """
57
+ Confirms that each member of TestStatus is an instance of TestStatus.
58
+
59
+ This test iterates through all members of TestStatus and checks their type.
60
+
61
+ Returns
62
+ -------
63
+ None
64
+ This method does not return a value. It asserts the type of each enum member.
65
+ """
66
+ # Assert that each enum member is an instance of TestStatus
67
+ for status in TestStatus:
68
+ self.assertIsInstance(status, TestStatus)
File without changes
@@ -0,0 +1,32 @@
1
+ from orionis.test.cases.asynchronous import AsyncTestCase
2
+ from orionis.test.output.dumper import TestDumper
3
+
4
+ class TestTestingDumper(AsyncTestCase):
5
+
6
+ async def testMethodsExist(self):
7
+ """
8
+ Checks if the required methods are present in the TestDumper class.
9
+
10
+ This test verifies that the `TestDumper` class contains all methods
11
+ specified in the `required_methods` list. It asserts the existence of
12
+ each method using `hasattr`.
13
+
14
+ Returns
15
+ -------
16
+ None
17
+ This method does not return any value. It raises an assertion error if any required method is missing.
18
+ """
19
+
20
+ required_methods = [
21
+ "dd",
22
+ "dump"
23
+ ]
24
+
25
+ # Iterate over the list of required method names
26
+ for method_name in required_methods:
27
+
28
+ # Assert that each required method exists in TestDumper
29
+ self.assertTrue(
30
+ hasattr(TestDumper, method_name),
31
+ f"{method_name} does not exist"
32
+ )
@@ -0,0 +1,42 @@
1
+ from orionis.test.cases.asynchronous import AsyncTestCase
2
+ from orionis.test.output.printer import TestPrinter
3
+
4
+ class TestTestingPrinter(AsyncTestCase):
5
+
6
+ async def testMethodsExist(self):
7
+ """
8
+ Checks for the existence of required methods in the TestPrinter class.
9
+
10
+ This test ensures that all methods listed in `required_methods` are present
11
+ in the `TestPrinter` class by asserting their existence using `hasattr`.
12
+
13
+ Parameters
14
+ ----------
15
+ self : TestTestingPrinter
16
+ The test case instance.
17
+
18
+ Returns
19
+ -------
20
+ None
21
+ Raises an AssertionError if any required method is missing.
22
+ """
23
+ # List of method names that must exist in TestPrinter
24
+ required_methods = [
25
+ "print",
26
+ "startMessage",
27
+ "finishMessage",
28
+ "executePanel",
29
+ "linkWebReport",
30
+ "summaryTable",
31
+ "displayResults",
32
+ "unittestResult"
33
+ ]
34
+
35
+ # Check each required method for existence in TestPrinter
36
+ for method_name in required_methods:
37
+
38
+ # Assert that the method exists in TestPrinter
39
+ self.assertTrue(
40
+ hasattr(TestPrinter, method_name),
41
+ f"{method_name} does not exist"
42
+ )
File without changes
@@ -0,0 +1,181 @@
1
+ import json
2
+ import tempfile
3
+ from orionis.test.cases.asynchronous import AsyncTestCase
4
+ from orionis.test.exceptions import OrionisTestValueError
5
+ from orionis.test.records.logs import TestLogs
6
+
7
+ class TestTestingRecords(AsyncTestCase):
8
+
9
+ async def testCreateAndGetReport(self):
10
+ """
11
+ Tests the creation of a test report and retrieval of the most recent report.
12
+
13
+ This method creates a test report with all required fields, stores it using
14
+ the `TestLogs` class, and then retrieves the most recent report to verify
15
+ its contents.
16
+
17
+ Returns
18
+ -------
19
+ None
20
+ This is a test method and does not return any value. Assertions are used
21
+ to validate expected behavior.
22
+ """
23
+ with tempfile.TemporaryDirectory() as tmpdir:
24
+ logs = TestLogs(tmpdir)
25
+
26
+ # Prepare a complete test report dictionary
27
+ report = {
28
+ "total_tests": 5,
29
+ "passed": 4,
30
+ "failed": 1,
31
+ "errors": 0,
32
+ "skipped": 0,
33
+ "total_time": 1.23,
34
+ "success_rate": 0.8,
35
+ "timestamp": "2024-06-01T12:00:00"
36
+ }
37
+
38
+ # Serialize the report to JSON and add to the dictionary
39
+ report["json"] = json.dumps(report)
40
+
41
+ # Store the report in the logs
42
+ result = logs.create(report)
43
+ self.assertTrue(result)
44
+
45
+ # Retrieve the most recent report
46
+ reports = logs.get(first=1)
47
+ self.assertEqual(len(reports), 1)
48
+
49
+ # Validate the contents of the retrieved report
50
+ self.assertEqual(json.loads(reports[0][1])["total_tests"], 5)
51
+
52
+ async def testCreateMissingFields(self):
53
+ """
54
+ Tests error handling when creating a report with missing required fields.
55
+
56
+ This method attempts to create a report without the required 'timestamp'
57
+ field and expects an `OrionisTestValueError` to be raised.
58
+
59
+ Returns
60
+ -------
61
+ None
62
+ This is a test method and does not return any value. Assertions are used
63
+ to validate expected behavior.
64
+ """
65
+ with tempfile.TemporaryDirectory() as tmpdir:
66
+ logs = TestLogs(tmpdir)
67
+
68
+ # Prepare a report missing the 'timestamp' field
69
+ report = {
70
+ "total_tests": 5,
71
+ "passed": 4,
72
+ "failed": 1,
73
+ "errors": 0,
74
+ "skipped": 0,
75
+ "total_time": 1.23,
76
+ "success_rate": 0.8,
77
+ }
78
+ report["json"] = json.dumps(report)
79
+
80
+ # Expect an error when creating the report
81
+ with self.assertRaises(OrionisTestValueError):
82
+ logs.create(report)
83
+
84
+ async def testResetDatabase(self):
85
+ """
86
+ Tests the reset functionality of the test logs database.
87
+
88
+ This method creates a report, stores it, and then resets the logs database.
89
+ It verifies that the reset operation returns True.
90
+
91
+ Returns
92
+ -------
93
+ None
94
+ This is a test method and does not return any value. Assertions are used
95
+ to validate expected behavior.
96
+ """
97
+ with tempfile.TemporaryDirectory() as tmpdir:
98
+ logs = TestLogs(tmpdir)
99
+
100
+ # Create and store a single report
101
+ report = {
102
+ "total_tests": 1,
103
+ "passed": 1,
104
+ "failed": 0,
105
+ "errors": 0,
106
+ "skipped": 0,
107
+ "total_time": 0.1,
108
+ "success_rate": 1.0,
109
+ "timestamp": "2024-06-01T12:00:00"
110
+ }
111
+ report["json"] = json.dumps(report)
112
+ logs.create(report)
113
+
114
+ # Reset the logs database and verify success
115
+ self.assertTrue(logs.reset())
116
+
117
+ async def testGetReportsInvalidParams(self):
118
+ """
119
+ Tests error handling for invalid parameters passed to `TestLogs.get()`.
120
+
121
+ This method checks that passing mutually exclusive or invalid values to
122
+ `get()` raises an `OrionisTestValueError`.
123
+
124
+ Returns
125
+ -------
126
+ None
127
+ This is a test method and does not return any value. Assertions are used
128
+ to validate expected behavior.
129
+ """
130
+ with tempfile.TemporaryDirectory() as tmpdir:
131
+ logs = TestLogs(tmpdir)
132
+
133
+ # Both 'first' and 'last' should not be provided together
134
+ with self.assertRaises(OrionisTestValueError):
135
+ logs.get(first=1, last=1)
136
+
137
+ # 'first' must be greater than zero
138
+ with self.assertRaises(OrionisTestValueError):
139
+ logs.get(first=0)
140
+
141
+ # 'last' must be greater than zero
142
+ with self.assertRaises(OrionisTestValueError):
143
+ logs.get(last=-1)
144
+
145
+ async def testGetLastReports(self):
146
+ """
147
+ Tests retrieval of the last N reports and verifies their order.
148
+
149
+ This method creates multiple reports, retrieves the last two, and checks
150
+ that the reports are returned in descending order by their identifier.
151
+
152
+ Returns
153
+ -------
154
+ None
155
+ This is a test method and does not return any value. Assertions are used
156
+ to validate expected behavior.
157
+ """
158
+ with tempfile.TemporaryDirectory() as tmpdir:
159
+ logs = TestLogs(tmpdir)
160
+
161
+ # Create and store three reports with increasing 'total_tests'
162
+ for i in range(3):
163
+ report = {
164
+ "total_tests": i+1,
165
+ "passed": i,
166
+ "failed": 1,
167
+ "errors": 0,
168
+ "skipped": 0,
169
+ "total_time": 0.1 * (i+1),
170
+ "success_rate": 0.5,
171
+ "timestamp": f"2024-06-01T12:00:0{i}"
172
+ }
173
+ report["json"] = json.dumps(report)
174
+ logs.create(report)
175
+
176
+ # Retrieve the last two reports
177
+ reports = logs.get(last=2)
178
+ self.assertEqual(len(reports), 2)
179
+
180
+ # Ensure the reports are ordered by descending identifier
181
+ self.assertTrue(reports[0][0] > reports[1][0])
@@ -1,209 +1,110 @@
1
- # from unittest import TestLoader
2
- # from unittest.mock import MagicMock, patch
3
- # from orionis.test.cases.asynchronous import AsyncTestCase
4
- # from orionis.test.core.unit_test import UnitTest
5
- # from orionis.test.enums import ExecutionMode
6
- # from unittest import (
7
- # TestSuite as StandardTestSuite,
8
- # TestResult as StandardTestResult
9
- # )
10
-
11
- # class TestTestingUnit(AsyncTestCase):
12
-
13
- # async def testDefaultConfiguration(self) -> None:
14
- # """
15
- # Test that UnitTest initializes with correct default configuration values.
16
-
17
- # Notes
18
- # -----
19
- # Verifies that all default attributes are set as expected upon initialization.
20
- # """
21
- # unit_test = UnitTest()
22
- # self.assertIsInstance(unit_test.loader, TestLoader)
23
- # self.assertIsInstance(unit_test.suite, StandardTestSuite)
24
-
25
- # async def testConfigureMethod(self) -> None:
26
- # """
27
- # Test the `configure` method for correct configuration updates.
28
- # This test verifies that all configuration parameters of the `UnitTest` class
29
- # can be updated through the `configure` method and that the changes are
30
- # reflected in the instance attributes.
31
-
32
- # Parameters
33
- # ----------
34
- # self : TestCase
35
- # The test case instance.
36
-
37
- # Notes
38
- # -----
39
- # The test checks the following configuration parameters:
40
- # - verbosity
41
- # - execution_mode
42
- # - max_workers
43
- # - fail_fast
44
- # - print_result
45
- # - throw_exception
46
- # It also asserts that the `configure` method returns the instance itself.
47
- # """
48
- # unit_test = UnitTest()
49
- # configured = unit_test.configure(
50
- # verbosity=1,
51
- # execution_mode=ExecutionMode.PARALLEL,
52
- # max_workers=8,
53
- # fail_fast=True,
54
- # print_result=False,
55
- # throw_exception=True
56
- # )
57
-
58
- # self.assertEqual(unit_test.verbosity, 1)
59
- # self.assertEqual(unit_test.execution_mode, ExecutionMode.PARALLEL.value)
60
- # self.assertEqual(unit_test.max_workers, 8)
61
- # self.assertTrue(unit_test.fail_fast)
62
- # self.assertFalse(unit_test.print_result)
63
- # self.assertTrue(unit_test.throw_exception)
64
- # self.assertEqual(configured, unit_test)
65
-
66
- # async def testDiscoverTestsInModule(self) -> None:
67
- # """
68
- # Test that `discoverTestsInModule` correctly loads tests from a module.
69
-
70
- # Verifies that tests can be discovered from a module and added to the test suite.
71
-
72
- # Notes
73
- # -----
74
- # This test mocks the loader's `loadTestsFromName` method to ensure that
75
- # `discoverTestsInModule` calls it with the correct arguments and that the
76
- # returned suite is handled as expected.
77
- # """
78
- # unit_test = UnitTest()
79
- # with patch.object(unit_test.loader, 'loadTestsFromName') as mock_load:
80
- # mock_load.return_value = StandardTestSuite()
81
- # result = unit_test.discoverTestsInModule(module_name='test_module')
82
-
83
- # mock_load.assert_called_once_with(name='test_module')
84
- # self.assertEqual(result, unit_test)
85
- # self.assertEqual(len(unit_test.suite._tests), 0)
86
-
87
- # async def testFlattenTestSuite(self) -> None:
88
- # """
89
- # Test the _flattenTestSuite method for correct flattening of nested test suites.
90
- # This test verifies that the _flattenTestSuite method of the UnitTest class
91
- # correctly flattens both simple and nested unittest suites into a single list
92
- # of test cases.
93
-
94
- # Parameters
95
- # ----------
96
- # self : TestCase
97
- # The test case instance.
98
-
99
- # Notes
100
- # -----
101
- # - Ensures that nested suites are recursively flattened.
102
- # - Asserts that all test cases from nested suites are present in the flattened result.
103
- # """
104
- # unit_test = UnitTest()
105
- # test_case1 = MagicMock()
106
- # test_case2 = MagicMock()
107
-
108
- # nested_suite = StandardTestSuite()
109
- # nested_suite.addTest(test_case1)
110
- # nested_suite.addTest(test_case2)
111
-
112
- # main_suite = StandardTestSuite()
113
- # main_suite.addTest(nested_suite)
114
-
115
- # flattened = unit_test._UnitTest__flattenTestSuite(main_suite)
116
- # self.assertEqual(len(flattened), 2)
117
- # self.assertIn(test_case1, flattened)
118
- # self.assertIn(test_case2, flattened)
119
-
120
- # async def testMergeTestResults(self) -> None:
121
- # """
122
- # Test the _mergeTestResults method for correct merging of test results.
123
- # Ensures that the method accurately combines the number of tests run,
124
- # as well as the lists of failures and errors from individual test results.
125
-
126
- # Notes
127
- # -----
128
- # - Verifies that the total number of tests run is updated correctly.
129
- # - Checks that failures and errors are merged without loss of information.
130
- # """
131
- # unit_test = UnitTest()
132
- # combined = StandardTestResult()
133
- # individual = StandardTestResult()
134
-
135
- # individual.testsRun = 2
136
- # individual.failures = [('test1', 'failure')]
137
- # individual.errors = [('test2', 'error')]
138
-
139
- # unit_test._UnitTest__mergeTestResults(combined, individual)
140
- # self.assertEqual(combined.testsRun, 2)
141
- # self.assertEqual(len(combined.failures), 1)
142
- # self.assertEqual(len(combined.errors), 1)
143
-
144
- # async def testClearTests(self) -> None:
145
- # """
146
- # Test the clearTests method to ensure it resets the test suite.
147
- # This test verifies that after adding a mock test to the suite and calling
148
- # the clearTests method, the suite is emptied as expected.
149
-
150
- # Steps
151
- # -----
152
- # 1. Create an instance of UnitTest.
153
- # 2. Add a mock test to the test suite.
154
- # 3. Call the clearTests method.
155
- # 4. Assert that the test suite is empty.
156
-
157
- # Assertions
158
- # ----------
159
- # - The length of the test suite should be zero after calling clearTests.
160
- # """
161
- # unit_test = UnitTest()
162
- # mock_test = MagicMock()
163
- # unit_test.suite.addTest(mock_test)
164
-
165
- # unit_test.clearTests()
166
- # self.assertEqual(len(unit_test.suite._tests), 0)
167
-
168
- # async def testGetTestNames(self) -> None:
169
- # """
170
- # This test verifies that the `getTestNames` method of the `UnitTest` class
171
- # correctly extracts and returns the identifiers of tests present in the test suite.
172
-
173
- # Notes
174
- # -----
175
- # - Mocks a test case with a predefined identifier.
176
- # - Adds the mock test to the test suite.
177
- # - Asserts that the returned list of test names matches the expected value.
178
- # """
179
- # unit_test = UnitTest()
180
- # mock_test = MagicMock()
181
- # mock_test.id.return_value = 'test_id'
182
- # unit_test.suite.addTest(mock_test)
183
-
184
- # names = unit_test.getTestNames()
185
- # self.assertEqual(names, ['test_id'])
186
-
187
- # async def testGetTestCount(self) -> None:
188
- # """
189
- # Test that `getTestCount` returns the correct number of tests.
190
-
191
- # Verifies that the count matches the number of tests in the suite.
192
-
193
- # Notes
194
- # -----
195
- # - Adds two mock tests to the suite.
196
- # - Asserts that `getTestCount` returns 2.
197
-
198
- # Returns
199
- # -------
200
- # None
201
- # """
202
- # unit_test = UnitTest()
203
- # mock_test1 = MagicMock()
204
- # mock_test2 = MagicMock()
205
- # unit_test.suite.addTest(mock_test1)
206
- # unit_test.suite.addTest(mock_test2)
207
-
208
- # count = unit_test.getTestCount()
209
- # self.assertEqual(count, 2)
1
+ import unittest
2
+ from unittest.mock import MagicMock
3
+ from orionis.foundation.config.testing.enums.drivers import PersistentDrivers
4
+ from orionis.foundation.config.testing.enums.mode import ExecutionMode
5
+ from orionis.test.cases.asynchronous import AsyncTestCase
6
+ from orionis.test.core.unit_test import UnitTest
7
+
8
+ class TestTestingUnit(AsyncTestCase):
9
+
10
+ async def testDefaultConfiguration(self) -> None:
11
+ """
12
+ Test that the `UnitTest` class initializes with correct default configuration values.
13
+ """
14
+ unit_test = UnitTest()
15
+ self.assertIsInstance(unit_test._UnitTest__loader, unittest.TestLoader)
16
+ self.assertIsInstance(unit_test._UnitTest__suite, unittest.TestSuite)
17
+
18
+ async def testConfigureMethod(self) -> None:
19
+ """
20
+ Tests the `configure` method of the `UnitTest` class for correct configuration updates.
21
+ """
22
+ unit_test = UnitTest()
23
+ configured = unit_test.configure(
24
+ verbosity=1,
25
+ execution_mode=ExecutionMode.PARALLEL,
26
+ max_workers=8,
27
+ fail_fast=True,
28
+ print_result=False,
29
+ throw_exception=True,
30
+ persistent=False,
31
+ persistent_driver=PersistentDrivers.JSON,
32
+ web_report=False
33
+ )
34
+ self.assertEqual(unit_test._UnitTest__verbosity, 1)
35
+ self.assertEqual(unit_test._UnitTest__execution_mode, ExecutionMode.PARALLEL.value)
36
+ self.assertEqual(unit_test._UnitTest__max_workers, 8)
37
+ self.assertTrue(unit_test._UnitTest__fail_fast)
38
+ self.assertTrue(unit_test._UnitTest__throw_exception)
39
+ self.assertFalse(unit_test._UnitTest__persistent)
40
+ self.assertEqual(unit_test._UnitTest__persistent_driver, PersistentDrivers.JSON.value)
41
+ self.assertFalse(unit_test._UnitTest__web_report)
42
+ self.assertIs(configured, unit_test)
43
+
44
+ async def testFlattenTestSuite(self) -> None:
45
+ """
46
+ Tests the `_flattenTestSuite` method of the `UnitTest` class for correct flattening of nested test suites.
47
+ """
48
+ unit_test = UnitTest()
49
+ test_case1 = MagicMock()
50
+ test_case2 = MagicMock()
51
+ nested_suite = unittest.TestSuite()
52
+ nested_suite.addTest(test_case1)
53
+ nested_suite.addTest(test_case2)
54
+ main_suite = unittest.TestSuite()
55
+ main_suite.addTest(nested_suite)
56
+ flattened = unit_test._UnitTest__flattenTestSuite(main_suite)
57
+ self.assertEqual(len(flattened), 2)
58
+ self.assertIn(test_case1, flattened)
59
+ self.assertIn(test_case2, flattened)
60
+
61
+ async def testMergeTestResults(self) -> None:
62
+ """
63
+ Tests the `_mergeTestResults` method of the `UnitTest` class for correct aggregation of test results.
64
+ """
65
+ unit_test = UnitTest()
66
+ combined = unittest.TestResult()
67
+ individual = unittest.TestResult()
68
+ individual.testsRun = 2
69
+ individual.failures = [('test1', 'failure')]
70
+ individual.errors = [('test2', 'error')]
71
+ individual.skipped = []
72
+ individual.expectedFailures = []
73
+ individual.unexpectedSuccesses = []
74
+ unit_test._UnitTest__mergeTestResults(combined, individual)
75
+ self.assertEqual(combined.testsRun, 2)
76
+ self.assertEqual(len(combined.failures), 1)
77
+ self.assertEqual(len(combined.errors), 1)
78
+
79
+ async def testClearTests(self) -> None:
80
+ """
81
+ Tests the `clearTests` method of the `UnitTest` class to ensure it properly resets the test suite.
82
+ """
83
+ unit_test = UnitTest()
84
+ mock_test = MagicMock()
85
+ unit_test._UnitTest__suite.addTest(mock_test)
86
+ unit_test.clearTests()
87
+ self.assertEqual(len(unit_test._UnitTest__suite._tests), 0)
88
+
89
+ async def testGetTestNames(self) -> None:
90
+ """
91
+ Tests the `getTestNames` method of the `UnitTest` class for correct extraction of test identifiers.
92
+ """
93
+ unit_test = UnitTest()
94
+ mock_test = MagicMock()
95
+ mock_test.id.return_value = 'test_id'
96
+ unit_test._UnitTest__suite.addTest(mock_test)
97
+ names = unit_test.getTestNames()
98
+ self.assertEqual(names, ['test_id'])
99
+
100
+ async def testGetTestCount(self) -> None:
101
+ """
102
+ Tests the `getTestCount` method of the `UnitTest` class for accurate test counting.
103
+ """
104
+ unit_test = UnitTest()
105
+ mock_test1 = MagicMock()
106
+ mock_test2 = MagicMock()
107
+ unit_test._UnitTest__suite.addTest(mock_test1)
108
+ unit_test._UnitTest__suite.addTest(mock_test2)
109
+ count = unit_test.getTestCount()
110
+ self.assertEqual(count, 2)
File without changes