orionis 0.246.0__py3-none-any.whl → 0.248.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 (91) hide show
  1. orionis/framework.py +1 -1
  2. orionis/luminate/config/app/__init__.py +10 -0
  3. orionis/luminate/config/app/entities/app.py +205 -0
  4. orionis/luminate/config/app/enums/ciphers.py +34 -0
  5. orionis/luminate/config/app/enums/environments.py +15 -0
  6. orionis/luminate/config/auth/__init__.py +7 -0
  7. orionis/luminate/config/auth/entities/auth.py +11 -0
  8. orionis/luminate/config/cache/__init__.py +9 -0
  9. orionis/luminate/config/cache/entities/cache.py +58 -0
  10. orionis/luminate/config/cache/entities/file.py +29 -0
  11. orionis/luminate/config/cache/entities/stores.py +35 -0
  12. orionis/luminate/config/cache/enums/drivers.py +12 -0
  13. orionis/luminate/config/entities/testing.py +192 -14
  14. orionis/luminate/config/exceptions/integrity_exception.py +30 -0
  15. orionis/luminate/console/dumper/dump_die.py +418 -0
  16. orionis/luminate/contracts/facades/commands/scheduler_facade.py +1 -1
  17. orionis/luminate/facades/files/path_facade.py +1 -1
  18. orionis/luminate/patterns/__init__.py +4 -0
  19. orionis/luminate/patterns/singleton/__init__.py +10 -0
  20. orionis/luminate/patterns/singleton/meta_class.py +56 -0
  21. orionis/luminate/providers/commands/reactor_commands_service_provider.py +3 -3
  22. orionis/luminate/providers/commands/scheduler_provider.py +1 -1
  23. orionis/luminate/providers/config/config_service_provider.py +1 -1
  24. orionis/luminate/providers/environment/environment__service_provider.py +2 -2
  25. orionis/luminate/providers/files/paths_provider.py +1 -1
  26. orionis/luminate/providers/log/log_service_provider.py +2 -2
  27. orionis/luminate/services/environment/__init__.py +10 -0
  28. orionis/luminate/services/environment/contracts/__init__.py +5 -0
  29. orionis/luminate/services/environment/contracts/env.py +93 -0
  30. orionis/luminate/services/environment/dot_env.py +293 -0
  31. orionis/luminate/services/environment/env.py +77 -0
  32. orionis/luminate/services/paths/__init__.py +9 -0
  33. orionis/luminate/services/paths/contracts/resolver.py +67 -0
  34. orionis/luminate/services/paths/resolver.py +83 -0
  35. orionis/luminate/services/workers/__init__.py +10 -0
  36. orionis/luminate/services/workers/maximum_workers.py +36 -0
  37. orionis/luminate/services_/commands/__init__.py +0 -0
  38. orionis/luminate/services_/config/__init__.py +0 -0
  39. orionis/luminate/services_/log/__init__.py +0 -0
  40. orionis/luminate/test/__init__.py +11 -1
  41. orionis/luminate/test/cases/test_async.py +1 -10
  42. orionis/luminate/test/cases/test_case.py +8 -3
  43. orionis/luminate/test/cases/test_sync.py +1 -0
  44. orionis/luminate/test/core/contracts/test_suite.py +19 -31
  45. orionis/luminate/test/core/contracts/test_unit.py +4 -0
  46. orionis/luminate/test/core/test_suite.py +27 -26
  47. orionis/luminate/test/core/test_unit.py +28 -45
  48. orionis/luminate/test/entities/test_result.py +13 -16
  49. orionis/luminate/test/exceptions/test_exception.py +1 -1
  50. orionis/luminate/test/output/contracts/test_std_out.py +22 -11
  51. orionis/luminate/test/output/test_std_out.py +69 -80
  52. orionis/static/__init__.py +0 -0
  53. {orionis-0.246.0.dist-info → orionis-0.248.0.dist-info}/METADATA +4 -1
  54. {orionis-0.246.0.dist-info → orionis-0.248.0.dist-info}/RECORD +81 -51
  55. tests/config/__init__.py +0 -0
  56. tests/config/test_app.py +122 -0
  57. tests/config/test_auth.py +21 -0
  58. tests/config/test_cache.py +20 -0
  59. tests/patterns/__init__.py +0 -0
  60. tests/patterns/singleton/__init__.py +0 -0
  61. tests/patterns/singleton/test_singleton.py +18 -0
  62. tests/services/__init__.py +0 -0
  63. tests/services/environment/__init__.py +0 -0
  64. tests/services/environment/test_env.py +33 -0
  65. orionis/luminate/config/entities/app.py +0 -47
  66. orionis/luminate/config/entities/auth.py +0 -15
  67. orionis/luminate/config/entities/cache.py +0 -51
  68. orionis/luminate/support/environment/contracts/env.py +0 -68
  69. orionis/luminate/support/environment/env.py +0 -139
  70. orionis/luminate/support/environment/functions.py +0 -49
  71. orionis/luminate/support/environment/helper.py +0 -26
  72. orionis/luminate/support/patterns/singleton.py +0 -44
  73. tests/support/environment/test_env.py +0 -91
  74. tests/support/patterns/test_singleton.py +0 -18
  75. /orionis/luminate/config/{entities → app/entities}/__init__.py +0 -0
  76. /orionis/luminate/{services/commands → config/app/enums}/__init__.py +0 -0
  77. /orionis/luminate/{services/config → config/auth/entities}/__init__.py +0 -0
  78. /orionis/luminate/{services/log → config/cache/entities}/__init__.py +0 -0
  79. /orionis/luminate/{support/environment → config/cache/enums}/__init__.py +0 -0
  80. /orionis/luminate/{support/environment/contracts → config/exceptions}/__init__.py +0 -0
  81. /orionis/luminate/{support/patterns → console/dumper}/__init__.py +0 -0
  82. {tests/support/environment → orionis/luminate/services/paths/contracts}/__init__.py +0 -0
  83. {tests/support/patterns → orionis/luminate/services_}/__init__.py +0 -0
  84. /orionis/luminate/{services → services_}/commands/reactor_commands_service.py +0 -0
  85. /orionis/luminate/{services → services_}/commands/scheduler_service.py +0 -0
  86. /orionis/luminate/{services → services_}/config/config_service.py +0 -0
  87. /orionis/luminate/{services → services_}/log/log_service.py +0 -0
  88. {orionis-0.246.0.dist-info → orionis-0.248.0.dist-info}/LICENCE +0 -0
  89. {orionis-0.246.0.dist-info → orionis-0.248.0.dist-info}/WHEEL +0 -0
  90. {orionis-0.246.0.dist-info → orionis-0.248.0.dist-info}/entry_points.txt +0 -0
  91. {orionis-0.246.0.dist-info → orionis-0.248.0.dist-info}/top_level.txt +0 -0
@@ -10,4 +10,14 @@ __all__ = [
10
10
  "AsyncTestCase",
11
11
  "TestCase",
12
12
  "SyncTestCase",
13
- ]
13
+ ]
14
+ __author__ = "Raúl Mauricio Uñate Castro"
15
+ __description__ = (
16
+ "Orionis Framework - Component Test Suites is a microframework "
17
+ "for creating unit and integration tests. "
18
+ "It allows you to write tests quickly and easily, "
19
+ "using a clear and concise syntax. "
20
+ "Supports both asynchronous and synchronous tests, "
21
+ "as well as the creation of test suites and parallel test execution. "
22
+ "It uses Python's native unittest module for test creation."
23
+ )
@@ -6,17 +6,8 @@ class AsyncTestCase(unittest.IsolatedAsyncioTestCase, TestStdOut):
6
6
  AsyncTestCase is a test case class designed for asynchronous unit testing.
7
7
  It inherits from `unittest.IsolatedAsyncioTestCase` to provide support for
8
8
  async test methods and `TestStdOut` for additional functionality.
9
- Methods
10
- -------
11
- asyncSetUp()
12
- Asynchronous setup method called before each test. It ensures that the
13
- parent class's asyncSetUp method is invoked to initialize any required
14
- resources.
15
- asyncTearDown()
16
- Asynchronous teardown method called after each test. It ensures that the
17
- parent class's asyncTearDown method is invoked to clean up any resources
18
- used during the test.
19
9
  """
10
+
20
11
  async def asyncSetUp(self):
21
12
  """
22
13
  Asynchronous setup method called before each test.
@@ -3,9 +3,14 @@ from orionis.luminate.test.output.test_std_out import TestStdOut
3
3
 
4
4
  class TestCase(unittest.IsolatedAsyncioTestCase, TestStdOut):
5
5
  """
6
- TestCase is a base class for unit tests that provides support for asynchronous
7
- testing using `unittest.IsolatedAsyncioTestCase` and additional functionality
8
- from `TestStdOut`."""
6
+ A base test case class for asynchronous unit tests.
7
+ Inherits from:
8
+ unittest.IsolatedAsyncioTestCase: Provides support for asynchronous test methods and setup/teardown.
9
+ TestStdOut: Mixin for capturing or testing standard output during tests.
10
+ This class defines asynchronous setup and teardown methods to ensure proper initialization and cleanup
11
+ of resources before and after each test case.
12
+ """
13
+
9
14
  async def asyncSetUp(self):
10
15
  """
11
16
  Asynchronous setup method called before each test.
@@ -7,4 +7,5 @@ class SyncTestCase(unittest.TestCase, TestStdOut):
7
7
  It inherits from `unittest.TestCase` to provide support for standard test methods
8
8
  and `TestStdOut` for additional functionality.
9
9
  """
10
+
10
11
  pass
@@ -1,42 +1,30 @@
1
1
  from abc import ABC, abstractmethod
2
+ from orionis.luminate.config.entities.testing import Testing
3
+ from orionis.luminate.test.core.test_unit import UnitTest
2
4
 
3
5
  class ITestSuite(ABC):
4
6
  """
5
- Provides utility methods to configure and execute unit tests from specified folders.
7
+ Interface for configuring and initializing a UnitTest suite using a provided Testing configuration.
8
+ Methods:
9
+ config(config: Testing) -> UnitTest:
6
10
  """
7
11
 
8
12
  @staticmethod
9
13
  @abstractmethod
10
- def load(
11
- base_path: str = 'tests',
12
- folder_path: list | str = '*',
13
- pattern: str = 'test_*.py'
14
- ):
14
+ def config(config:Testing) -> UnitTest:
15
15
  """
16
- Discover and initialize a test suite from the specified folder(s).
17
-
18
- This method scans the provided folder(s) for test files matching the given pattern
19
- and initializes a test suite with the discovered files.
20
-
21
- Parameters
22
- ----------
23
- base_path : str, optional
24
- The base path for the tests. Defaults to 'tests'.
25
- folder_path : str or list of str, optional
26
- Path(s) to the folder(s) containing test files. Use '*' to scan all folders
27
- under the base path. Defaults to '*'.
28
- pattern : str, optional
29
- File pattern to match test files. Defaults to 'test_*.py'.
30
-
31
- Returns
32
- -------
33
- UnitTestClass
34
- An initialized test suite containing the discovered test files.
35
-
36
- Raises
37
- ------
38
- TypeError
39
- If `base_path` is not a string, `folder_path` is not a string or list, or
40
- `pattern` is not a string.
16
+ Configures and initializes a UnitTest suite based on the provided Testing configuration.
17
+ Args:
18
+ config (Testing): An instance of the Testing class containing configuration options for the test suite.
19
+ Returns:
20
+ UnitTest: An initialized UnitTest suite configured according to the provided settings.
21
+ Raises:
22
+ OrionisTestConfigException: If the config parameter is not an instance of the Testing class.
23
+ The function performs the following steps:
24
+ - Validates the type of the config parameter.
25
+ - Initializes a UnitTest suite and applies configuration values from the Testing instance.
26
+ - Discovers folders containing test files based on the specified base path, folder path(s), and filename pattern.
27
+ - Adds discovered test folders to the UnitTest suite, applying optional test name patterns and tags.
28
+ - Returns the configured UnitTest suite ready for execution.
41
29
  """
42
30
  pass
@@ -3,6 +3,10 @@ from typing import Any, Dict, List, Optional
3
3
  from orionis.luminate.test.enums.test_mode import ExecutionMode
4
4
 
5
5
  class IUnitTest(ABC):
6
+ """
7
+ IUnitTest is an abstract base class that defines the contract for a unit testing interface within the Orionis framework.
8
+ This interface provides methods for configuring the test runner, discovering tests in folders or modules, executing tests, retrieving test information, and managing the test suite. Implementations of this interface are expected to provide mechanisms for flexible test discovery, execution, and result handling, supporting features such as verbosity control, parallel execution, test filtering, and result reporting.
9
+ """
6
10
 
7
11
  @abstractmethod
8
12
  def configure(
@@ -1,38 +1,39 @@
1
1
  import re
2
2
  from os import walk
3
3
  from orionis.luminate.config.entities.testing import Testing
4
+ from orionis.luminate.test.core.contracts.test_suite import ITestSuite
4
5
  from orionis.luminate.test.core.test_unit import UnitTest
5
6
  from orionis.luminate.test.exceptions.test_config_exception import OrionisTestConfigException
6
7
 
7
- class TestSuite:
8
+ class TestSuite(ITestSuite):
9
+ """
10
+ TestSuite provides static configuration and initialization of a unit test suite based on a given Testing configuration.
11
+ Methods:
12
+ config(config: Testing) -> UnitTest
13
+ Configures and initializes a test suite using the provided Testing configuration.
14
+ - Validates the type of the configuration object.
15
+ - Sets up the UnitTest suite with parameters such as verbosity, execution mode, worker count, and error handling.
16
+ - Discovers test folders based on base path, folder path(s), and filename pattern, supporting wildcards.
17
+ - Adds discovered test folders to the suite, optionally filtering by test name pattern and tags.
18
+ OrionisTestConfigException: If the provided config is not an instance of the Testing class.
19
+ """
8
20
 
9
21
  @staticmethod
10
22
  def config(config:Testing) -> UnitTest:
11
23
  """
12
- Configures and initializes a test suite based on the provided configuration.
13
- Args:
14
- config (Testing): An instance of the `Testing` class containing configuration
15
- parameters for the test suite.
16
- Returns:
17
- UnitTest: An initialized test suite configured with the provided settings.
18
- Raises:
19
- OrionisTestConfigException: If the `config` parameter is not an instance of
20
- the `Testing` class.
21
- The function performs the following steps:
22
- 1. Validates that the `config` parameter is an instance of the `Testing` class.
23
- 2. Initializes a `UnitTest` object and assigns configuration values to it.
24
- 3. Extracts configuration values such as `base_path`, `folder_path`, and `pattern`.
25
- 4. Discovers folders matching the specified `folder_path` and `pattern`:
26
- - If `folder_path` is '*', all matching folders in the `base_path` are discovered.
27
- - If `folder_path` is a list, matching folders in each path are discovered.
28
- - Otherwise, matching folders in the specified `folder_path` are discovered.
29
- 5. Adds discovered folders to the test suite by calling `discoverTestsInFolder`.
30
- Notes:
31
- - The `list_matching_folders` helper function is used to find folders matching
32
- the specified pattern.
33
- - The `pattern` supports wildcard characters (`*` and `?`) for flexible matching.
34
- - The `test_name_pattern` and `tags` from the `config` are used when adding
35
- folders to the test suite.
24
+ Configures and initializes a UnitTest suite based on the provided Testing configuration.
25
+ Args:
26
+ config (Testing): An instance of the Testing class containing configuration options for the test suite.
27
+ Returns:
28
+ UnitTest: An initialized UnitTest suite configured according to the provided settings.
29
+ Raises:
30
+ OrionisTestConfigException: If the config parameter is not an instance of the Testing class.
31
+ The function performs the following steps:
32
+ - Validates the type of the config parameter.
33
+ - Initializes a UnitTest suite and applies configuration values from the Testing instance.
34
+ - Discovers folders containing test files based on the specified base path, folder path(s), and filename pattern.
35
+ - Adds discovered test folders to the UnitTest suite, applying optional test name patterns and tags.
36
+ - Returns the configured UnitTest suite ready for execution.
36
37
  """
37
38
 
38
39
  # Check if the config is an instance of Testing
@@ -74,7 +75,7 @@ class TestSuite:
74
75
  discovered_folders.extend(list_matching_folders(base_path, pattern))
75
76
  elif isinstance(folder_path, list):
76
77
  for custom_path in folder_path:
77
- discovered_folders.extend(list_matching_folders(custom_path, pattern))
78
+ discovered_folders.extend(list_matching_folders(f"{base_path}/{custom_path}", pattern))
78
79
  else:
79
80
  discovered_folders.extend(list_matching_folders(folder_path, pattern))
80
81
 
@@ -27,38 +27,6 @@ class UnitTest(IUnitTest):
27
27
  customizable verbosity, fail-fast behavior, and rich output formatting using the `rich` library.
28
28
  loader (unittest.TestLoader): The test loader used to discover and load tests.
29
29
  suite (unittest.TestSuite): The test suite containing the discovered tests.
30
- Methods:
31
- configure(verbosity, execution_mode, max_workers, fail_fast, print_result):
32
- discoverTestsInFolder(folder_path, base_path, pattern, test_name_pattern, tags):
33
- discoverTestsInModule(module_name, test_name_pattern):
34
- Discovers and loads tests from a specified module, optionally filtering them by a test name pattern.
35
- run(print_result, throw_exception):
36
- getTestNames():
37
- getTestCount():
38
- Calculates the total number of tests in the test suite.
39
- clearTests():
40
- Private Methods:
41
- _startMessage():
42
- _runTestsSequentially(output_buffer, error_buffer):
43
- _runTestsInParallel(output_buffer, error_buffer):
44
- Executes tests in parallel using a thread pool.
45
- _mergeTestResults(combined_result, individual_result):
46
- _createCustomResultClass():
47
- Creates a custom test result class that extends `unittest.TextTestResult` for enhanced functionality.
48
- _generateSummary(result, execution_time):
49
- Generates a summary of the test results, including details about each test and overall statistics.
50
- _printSummaryTable(summary):
51
- _filterTestsByName(suite, pattern):
52
- _filterTestsByTags(suite, tags):
53
- _flattenTestSuite(suite):
54
- _sanitizeTraceback(test_path, traceback_test):
55
- Sanitizes a traceback string to extract and display the most relevant parts related to a specific test file.
56
- _displayResults(summary, result):
57
- Displays the results of the test execution, including a summary table and detailed information about failed or errored tests.
58
- _extractErrorInfo(traceback_str):
59
- Extracts error information from a traceback string, including the file path and cleaned-up traceback.
60
- _finishMessage(summary):
61
- Displays a formatted message indicating the completion of the test suite execution.
62
30
  """
63
31
 
64
32
  def __init__(self) -> None:
@@ -93,7 +61,7 @@ class UnitTest(IUnitTest):
93
61
  self.rich_console = RichConsole()
94
62
  self.orionis_console = Console()
95
63
  self.discovered_tests: List = []
96
- self.width_table: int = 0
64
+ self.width_output_component: int = int(self.rich_console.width * 0.75)
97
65
  self.throw_exception: bool = False
98
66
 
99
67
  def configure(
@@ -241,18 +209,25 @@ class UnitTest(IUnitTest):
241
209
  test_count = len(list(self._flattenTestSuite(self.suite)))
242
210
  mode_text = f"[stat]Parallel with {self.max_workers} workers[/stat]" if self.execution_mode == ExecutionMode.PARALLEL else "Sequential"
243
211
  textlines = [
244
- f"[bold]Total Tests:[/bold] [stat]{test_count}[/stat]",
245
- f"[bold]Mode:[/bold] {mode_text}",
212
+ f"[bold]Total Tests:[/bold] [dim]{test_count}[/dim]",
213
+ f"[bold]Mode:[/bold] [dim]{mode_text}[/dim]",
246
214
  f"[bold]Started at:[/bold] [dim]{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}[/dim]"
247
215
  ]
248
- text = ' | '.join(textlines).replace('[bold]', '').replace('[/bold]', '').replace('[stat]', '').replace('[/stat]', '').replace('[dim]', '').replace('[/dim]', '')
249
- self.width_table = len(text) + 4
250
216
 
251
217
  self.orionis_console.newLine()
252
- self.rich_console.print(Panel.fit(text, border_style="blue", title="🧪 Orionis Framework - Test Suite", title_align="left"))
218
+ self.rich_console.print(
219
+ Panel(
220
+ '\n'.join(textlines),
221
+ border_style="blue",
222
+ title="🧪 Orionis Framework - Component Test Suite",
223
+ title_align="center",
224
+ width=self.width_output_component,
225
+ padding=(0, 1)
226
+ )
227
+ )
253
228
  self.orionis_console.newLine()
254
229
 
255
- def run(self, print_result: bool = None, throw_exception: bool = False) -> Dict[str, Any]:
230
+ def run(self, print_result: bool = None, throw_exception: bool = None) -> Dict[str, Any]:
256
231
  """
257
232
  Executes the test suite and processes the results.
258
233
  Args:
@@ -593,7 +568,12 @@ class UnitTest(IUnitTest):
593
568
  Returns:
594
569
  None
595
570
  """
596
- table = Table(show_header=True, header_style="bold white", width=self.width_table, border_style="blue")
571
+ table = Table(
572
+ show_header=True,
573
+ header_style="bold white",
574
+ width=self.width_output_component,
575
+ border_style="blue"
576
+ )
597
577
  table.add_column("Total", justify="center")
598
578
  table.add_column("Passed", justify="center")
599
579
  table.add_column("Failed", justify="center")
@@ -789,6 +769,9 @@ class UnitTest(IUnitTest):
789
769
  icon = "❌" if test["status"] == TestStatus.FAILED.name else "💥"
790
770
  border_color = "yellow" if test["status"] == TestStatus.FAILED.name else "red"
791
771
 
772
+ if test['execution_time'] == 0:
773
+ test['execution_time'] = 0.001
774
+
792
775
  panel = Panel(
793
776
  syntax,
794
777
  title=f"{icon} {test['method']}",
@@ -796,7 +779,8 @@ class UnitTest(IUnitTest):
796
779
  border_style=border_color,
797
780
  title_align="left",
798
781
  padding=(1, 1),
799
- subtitle_align="right"
782
+ subtitle_align="right",
783
+ width=self.width_output_component
800
784
  )
801
785
  self.rich_console.print(panel)
802
786
  self.orionis_console.newLine()
@@ -859,14 +843,13 @@ class UnitTest(IUnitTest):
859
843
 
860
844
  status_icon = "✅" if (summary['failed'] + summary['errors']) == 0 else "❌"
861
845
  msg = f"Test suite completed in {summary['total_time']:.2f} seconds"
862
- len_spaces = max(0, int(self.width_table - len(msg)))
863
- spaces = ' ' * (len_spaces - 4)
864
846
  self.rich_console.print(
865
- Panel.fit(
866
- f"{msg}{spaces}",
847
+ Panel(
848
+ msg,
867
849
  border_style="blue",
868
850
  title=f"{status_icon} Test Suite Finished",
869
851
  title_align='left',
852
+ width=self.width_output_component,
870
853
  padding=(0, 1)
871
854
  )
872
855
  )
@@ -2,25 +2,22 @@ from dataclasses import dataclass
2
2
  from typing import Any, Optional
3
3
  from orionis.luminate.test.enums.test_status import TestStatus
4
4
 
5
- @dataclass(frozen=True)
5
+ @dataclass(frozen=True, kw_only=True)
6
6
  class TestResult:
7
7
  """
8
- Data class containing detailed information about a test result.
8
+ Represents the result of a test execution.
9
9
 
10
- Attributes
11
- ----------
12
- name : str
13
- The name of the test.
14
- status : TestStatus
15
- The status of the test, indicating whether it passed, failed, or was skipped.
16
- execution_time : float
17
- The time taken to execute the test, in seconds.
18
- error_message : str, optional
19
- The error message if the test failed, by default None.
20
- traceback : str, optional
21
- The traceback information if the test failed, by default None.
22
- file_path : str, optional
23
- The file path where the test is located, by default None.
10
+ Attributes:
11
+ id (Any): Unique identifier for the test result.
12
+ name (str): Name of the test.
13
+ status (TestStatus): Status of the test execution (e.g., passed, failed).
14
+ execution_time (float): Time taken to execute the test, in seconds.
15
+ error_message (Optional[str]): Error message if the test failed, otherwise None.
16
+ traceback (Optional[str]): Traceback information if an error occurred, otherwise None.
17
+ class_name (Optional[str]): Name of the class containing the test, if applicable.
18
+ method (Optional[str]): Name of the method representing the test, if applicable.
19
+ module (Optional[str]): Name of the module containing the test, if applicable.
20
+ file_path (Optional[str]): Path to the file containing the test, if applicable.
24
21
  """
25
22
  id: Any
26
23
  name: str
@@ -49,4 +49,4 @@ class OrionisTestFailureException(Exception):
49
49
  Returns:
50
50
  str: A formatted string describing the exception.
51
51
  """
52
- return f"OrionisTestFailureException: {self.args[0]}"
52
+ return f"{self.__class__.__name__}: {self.args[0]}"
@@ -1,17 +1,28 @@
1
- from typing import Any
2
-
3
- class ITestStdOut:
1
+ from abc import ABC, abstractmethod
2
+ class ITestStdOut(ABC):
4
3
  """
5
- Utility for printing debug info during tests, including caller context (file, line, method).
4
+ Interface for standard output debugging utilities.
5
+ This interface defines methods for dumping debugging information, capturing the caller's file, method, and line number, and utilizing a Debug class to output the information. Implementations should provide mechanisms to output or log the provided arguments for debugging purposes
6
6
  """
7
7
 
8
- @staticmethod
9
- def print(*args: Any) -> None:
8
+ @abstractmethod
9
+ def dd(self, *args):
10
+ """
11
+ Dumps debugging information using the Debug class.
12
+ This method captures the caller's file, method, and line number,
13
+ and uses the Debug class to output debugging information.
14
+ Args:
15
+ *args: Variable length argument list to be dumped.
10
16
  """
11
- Print arguments to the console with file, line, and method of the caller.
17
+ pass
12
18
 
13
- Parameters
14
- ----------
15
- *args : Any
16
- Any values to print. The first argument is ignored (typically the class or context).
19
+ @abstractmethod
20
+ def dump(self, *args):
21
+ """
22
+ Dumps debugging information using the Debug class.
23
+ This method captures the caller's file, method, and line number,
24
+ and uses the Debug class to output debugging information.
25
+ Args:
26
+ *args: Variable length argument list to be dumped.
17
27
  """
28
+ pass
@@ -1,108 +1,97 @@
1
1
  import os
2
2
  import sys
3
- from orionis.luminate.console.output.console import Console
4
3
  from orionis.luminate.test.output.contracts.test_std_out import ITestStdOut
4
+ from orionis.luminate.console.dumper.dump_die import Debug
5
5
 
6
6
  class TestStdOut(ITestStdOut):
7
7
  """
8
- TestStdOut is a class that provides methods for printing messages to the console
9
- and exiting the program. It is designed to be used in a testing environment where
10
- console output is important for debugging and reporting purposes.
11
- It includes methods for printing messages with contextual information about the
12
- file, line number, and method name of the caller. The class also provides a method
13
- for forcefully exiting the program with a specified exit code.
8
+ TestStdOut provides utility methods for debugging and outputting information during test execution.
9
+ This class implements methods to determine if an object is a test case instance and to output debugging
10
+ information using the Debug class. It ensures that standard output and error streams are properly managed
11
+ during debugging dumps, and captures the caller's file and line number for context.
14
12
  """
15
13
 
16
- def console(self):
14
+ def __isTestCaseClass(self, value):
17
15
  """
18
- Returns an instance of the Console class for printing messages to the console.
19
- Ensures that the original stdout and stderr streams are used during the operation.
16
+ Determines if the given value is an instance of a test case class.
17
+ This method checks whether the provided value is an instance of one of the
18
+ predefined test case classes: AsyncTestCase, TestCase, or SyncTestCase.
19
+ If the value is None or an ImportError occurs during the import of the
20
+ test case classes, the method returns False.
21
+ Args:
22
+ value: The object to be checked.
23
+ Returns:
24
+ bool: True if the value is an instance of AsyncTestCase, TestCase,
25
+ or SyncTestCase; False otherwise.
20
26
  """
27
+ try:
28
+ if value is None:
29
+ return False
30
+ from orionis.luminate.test.cases.test_async import AsyncTestCase
31
+ from orionis.luminate.test.cases.test_case import TestCase
32
+ from orionis.luminate.test.cases.test_sync import SyncTestCase
33
+ return isinstance(value, (AsyncTestCase, TestCase, SyncTestCase))
34
+ except Exception:
35
+ return False
36
+
37
+ def dd(self, *args):
38
+ """
39
+ Dumps debugging information using the Debug class.
40
+ This method captures the caller's file, method, and line number,
41
+ and uses the Debug class to output debugging information.
42
+ Args:
43
+ *args: Variable length argument list to be dumped.
44
+ """
45
+ if not args:
46
+ return
47
+
21
48
  original_stdout = sys.stdout
22
49
  original_stderr = sys.stderr
50
+
23
51
  try:
24
52
  sys.stdout = sys.__stdout__
25
53
  sys.stderr = sys.__stderr__
26
- return Console
54
+
55
+ caller_frame = sys._getframe(1)
56
+ _file = os.path.abspath(caller_frame.f_code.co_filename)
57
+ _line = caller_frame.f_lineno
58
+
59
+ dumper = Debug(f"{_file}:{_line}")
60
+ if self.__isTestCaseClass(args[0]):
61
+ dumper.dd(*args[1:])
62
+ else:
63
+ dumper.dd(*args)
27
64
  finally:
28
- # Restore the original stdout and stderr streams
29
65
  sys.stdout = original_stdout
30
66
  sys.stderr = original_stderr
31
67
 
32
- def exit(self) -> None:
68
+ def dump(self, *args):
33
69
  """
34
- Force close the program with the specified exit code. This method is a wrapper
35
- around `os._exit(1)` to ensure that the program terminates immediately without
36
- """
37
- os._exit(1)
38
-
39
- def dd(self, *args) -> None:
70
+ Dumps debugging information using the Debug class.
71
+ This method captures the caller's file, method, and line number,
72
+ and uses the Debug class to output debugging information.
73
+ Args:
74
+ *args: Variable length argument list to be dumped.
40
75
  """
41
- Prints the provided arguments to the console with contextual information
42
- about the file and line number of the caller, and then exits the program.
43
- Parameters
44
- ----------
45
- *args : tuple
46
- The arguments to be printed. The first argument is ignored, and the
47
- remaining arguments are printed. If no arguments are provided, the
48
- method does nothing.
49
- Notes
50
- -----
51
- - The method temporarily redirects `sys.stdout` and `sys.stderr` to their
52
- original states (`sys.__stdout__` and `sys.__stderr__`) to ensure proper
53
- console output.
54
- - The contextual information includes the file path and line number of the
55
- caller, which is displayed in a muted text format.
56
- - After printing, the method restores the original `sys.stdout` and
57
- `sys.stderr` streams.
58
- """
59
- self.dump(*args)
60
- self.exit()
61
-
62
- def dump(*args):
63
- """
64
- Prints the provided arguments to the console with contextual information
65
- about the file and line number of the caller. The output is formatted with
66
- muted text decorations for better readability.
67
- Parameters
68
- ----------
69
- *args : tuple
70
- The arguments to be printed. The first argument is ignored, and the
71
- remaining arguments are printed. If no arguments are provided, the
72
- method does nothing.
73
- Notes
74
- -----
75
- - The method temporarily redirects `sys.stdout` and `sys.stderr` to their
76
- original states (`sys.__stdout__` and `sys.__stderr__`) to ensure proper
77
- console output.
78
- - The contextual information includes the file path and line number of the
79
- caller, which is displayed in a muted text format.
80
- - After printing, the method restores the original `sys.stdout` and
81
- `sys.stderr` streams.
82
- """
83
-
84
- # Check if the first argument is a string and remove it from the args tuple
85
- if len(args) == 0:
76
+ if not args:
86
77
  return
87
78
 
88
- # Change the output stream to the original stdout and stderr
89
- # to avoid any issues with the console output
90
79
  original_stdout = sys.stdout
91
80
  original_stderr = sys.stderr
92
- sys.stdout = sys.__stdout__
93
- sys.stderr = sys.__stderr__
94
81
 
95
- # Get the file name and line number of the caller
96
- # using sys._getframe(1) to access the caller's frame
97
- _file = os.path.relpath(sys._getframe(1).f_code.co_filename, start=os.getcwd())
98
- _method = sys._getframe(1).f_code.co_name
99
- _line = sys._getframe(1).f_lineno
82
+ try:
83
+ sys.stdout = sys.__stdout__
84
+ sys.stderr = sys.__stderr__
100
85
 
101
- # Print the contextual information and the provided arguments
102
- Console.textMuted(f"File: {_file}, Line: {_line}, Method: {_method}")
103
- print(*args, end='\n')
104
- Console.newLine()
86
+ caller_frame = sys._getframe(1)
87
+ _file = os.path.abspath(caller_frame.f_code.co_filename)
88
+ _line = caller_frame.f_lineno
105
89
 
106
- # Restore the original stdout and stderr streams
107
- sys.stdout = original_stdout
108
- sys.stderr = original_stderr
90
+ dumper = Debug(f"{_file}:{_line}")
91
+ if self.__isTestCaseClass(args[0]):
92
+ dumper.dump(*args[1:])
93
+ else:
94
+ dumper.dump(*args)
95
+ finally:
96
+ sys.stdout = original_stdout
97
+ sys.stderr = original_stderr
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: orionis
3
- Version: 0.246.0
3
+ Version: 0.248.0
4
4
  Summary: Orionis Framework – Elegant, Fast, and Powerful.
5
5
  Home-page: https://github.com/orionis-framework/framework
6
6
  Author: Raul Mauricio Uñate Castro
@@ -14,6 +14,9 @@ License-File: LICENCE
14
14
  Requires-Dist: apscheduler>=3.11.0
15
15
  Requires-Dist: python-dotenv>=1.0.1
16
16
  Requires-Dist: requests>=2.32.3
17
+ Requires-Dist: rich>=13.9.4
18
+ Requires-Dist: psutil>=7.0.0
19
+ Requires-Dist: cryptography>=44.0.3
17
20
  Dynamic: author
18
21
  Dynamic: author-email
19
22
  Dynamic: classifier