orionis 0.283.0__py3-none-any.whl → 0.285.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 (44) hide show
  1. orionis/foundation/config/testing/entities/testing.py +25 -0
  2. orionis/metadata/framework.py +1 -1
  3. orionis/services/asynchrony/{async_io.py → coroutines.py} +2 -1
  4. orionis/services/asynchrony/exceptions/__init__.py +0 -0
  5. orionis/services/asynchrony/exceptions/coroutine_exception.py +26 -0
  6. orionis/services/environment/dot_env.py +7 -7
  7. orionis/services/environment/env.py +56 -8
  8. orionis/services/environment/exceptions/__init__.py +0 -0
  9. orionis/services/environment/exceptions/value_exception.py +27 -0
  10. orionis/services/introspection/exceptions/__init__.py +0 -0
  11. orionis/services/introspection/exceptions/types.py +0 -0
  12. orionis/services/introspection/helpers/__init__.py +0 -0
  13. orionis/services/introspection/helpers/functions.py +285 -0
  14. orionis/services/introspection/reflection.py +216 -0
  15. orionis/services/parsers/exceptions/__init__.py +0 -0
  16. orionis/services/parsers/serializer.py +1 -1
  17. orionis/services/paths/exceptions/__init__.py +0 -0
  18. orionis/services/paths/exceptions/not_found_exceptions.py +28 -0
  19. orionis/services/paths/exceptions/path_value_exceptions.py +28 -0
  20. orionis/services/paths/resolver.py +6 -4
  21. orionis/services/standard/exceptions/__init__.py +0 -0
  22. orionis/services/standard/exceptions/path_value_exceptions.py +28 -0
  23. orionis/services/standard/std.py +4 -3
  24. orionis/test/entities/test_result.py +14 -1
  25. orionis/test/exceptions/test_persistence_error.py +34 -0
  26. orionis/test/exceptions/test_runtime_error.py +26 -0
  27. orionis/test/exceptions/test_value_error.py +26 -0
  28. orionis/test/logs/contracts/history.py +29 -56
  29. orionis/test/logs/history.py +309 -188
  30. orionis/test/output/contracts/dumper.py +24 -8
  31. orionis/test/output/dumper.py +52 -21
  32. orionis/test/suites/contracts/test_suite.py +27 -13
  33. orionis/test/suites/contracts/test_unit.py +101 -61
  34. orionis/test/suites/test_suite.py +45 -24
  35. orionis/test/suites/test_unit.py +559 -290
  36. orionis/unittesting.py +8 -0
  37. {orionis-0.283.0.dist-info → orionis-0.285.0.dist-info}/METADATA +1 -1
  38. {orionis-0.283.0.dist-info → orionis-0.285.0.dist-info}/RECORD +44 -26
  39. tests/services/asynchrony/test_async_io.py +3 -2
  40. /orionis/services/parsers/{exception.py → exceptions/exception_parser.py} +0 -0
  41. {orionis-0.283.0.dist-info → orionis-0.285.0.dist-info}/WHEEL +0 -0
  42. {orionis-0.283.0.dist-info → orionis-0.285.0.dist-info}/licenses/LICENCE +0 -0
  43. {orionis-0.283.0.dist-info → orionis-0.285.0.dist-info}/top_level.txt +0 -0
  44. {orionis-0.283.0.dist-info → orionis-0.285.0.dist-info}/zip-safe +0 -0
@@ -1,27 +1,46 @@
1
1
  import os
2
2
  import sys
3
+ from orionis.test.exceptions.test_runtime_error import OrionisTestRuntimeError
3
4
  from orionis.test.output.contracts.dumper import ITestDumper
4
5
 
5
6
  class TestDumper(ITestDumper):
6
7
  """
7
8
  TestDumper provides utility methods for debugging and outputting information during test execution.
8
- This class implements methods to determine if an object is a test case instance and to output debugging
9
- information using the Debug class. It ensures that standard output and error streams are properly managed
10
- during debugging dumps, and captures the caller's file and line number for context.
9
+
10
+ This class implements methods to:
11
+ - Determine if an object is a test case instance.
12
+ - Output debugging information using the Debug class.
13
+ - Manage standard output and error streams during debugging dumps.
14
+ - Capture the caller's file and line number for context.
15
+
16
+ Attributes
17
+ ----------
18
+ None
19
+
20
+ Methods
21
+ -------
22
+ __isTestCaseClass(value)
23
+ Determines if the given value is an instance of a test case class.
24
+ dd(*args)
25
+ Dumps debugging information using the Debug class.
26
+ dump(*args)
27
+ Dumps debugging information using the Debug class.
11
28
  """
12
29
 
13
- def __isTestCaseClass(self, value):
30
+ def __isTestCaseClass(self, value) -> bool:
14
31
  """
15
- Determines if the given value is an instance of a test case class.
16
- This method checks whether the provided value is an instance of one of the
17
- predefined test case classes: AsyncTestCase, TestCase, or SyncTestCase.
18
- If the value is None or an ImportError occurs during the import of the
19
- test case classes, the method returns False.
20
- Args:
21
- value: The object to be checked.
22
- Returns:
23
- bool: True if the value is an instance of AsyncTestCase, TestCase,
24
- or SyncTestCase; False otherwise.
32
+ Check if the given value is an instance of a test case class.
33
+
34
+ Parameters
35
+ ----------
36
+ value : object
37
+ The object to check.
38
+
39
+ Returns
40
+ -------
41
+ bool
42
+ True if `value` is an instance of AsyncTestCase, TestCase, or SyncTestCase;
43
+ False otherwise.
25
44
  """
26
45
  try:
27
46
  if value is None:
@@ -33,13 +52,17 @@ class TestDumper(ITestDumper):
33
52
  except Exception:
34
53
  return False
35
54
 
36
- def dd(self, *args):
55
+ def dd(self, *args) -> None:
37
56
  """
38
57
  Dumps debugging information using the Debug class.
39
- This method captures the caller's file, method, and line number,
58
+
59
+ This method captures the caller's file and line number,
40
60
  and uses the Debug class to output debugging information.
41
- Args:
42
- *args: Variable length argument list to be dumped.
61
+
62
+ Parameters
63
+ ----------
64
+ *args : tuple
65
+ Variable length argument list to be dumped.
43
66
  """
44
67
  if not args:
45
68
  return
@@ -62,17 +85,23 @@ class TestDumper(ITestDumper):
62
85
  dumper.dd(*args[1:])
63
86
  else:
64
87
  dumper.dd(*args)
88
+ except Exception as e:
89
+ raise OrionisTestRuntimeError(f"An error occurred while dumping debug information: {e}")
65
90
  finally:
66
91
  sys.stdout = original_stdout
67
92
  sys.stderr = original_stderr
68
93
 
69
- def dump(self, *args):
94
+ def dump(self, *args) -> None:
70
95
  """
71
96
  Dumps debugging information using the Debug class.
97
+
72
98
  This method captures the caller's file, method, and line number,
73
99
  and uses the Debug class to output debugging information.
74
- Args:
75
- *args: Variable length argument list to be dumped.
100
+
101
+ Parameters
102
+ ----------
103
+ *args : tuple
104
+ Variable length argument list to be dumped.
76
105
  """
77
106
  if not args:
78
107
  return
@@ -95,6 +124,8 @@ class TestDumper(ITestDumper):
95
124
  dumper.dump(*args[1:])
96
125
  else:
97
126
  dumper.dump(*args)
127
+ except Exception as e:
128
+ raise OrionisTestRuntimeError(f"An error occurred while dumping debug information: {e}")
98
129
  finally:
99
130
  sys.stdout = original_stdout
100
131
  sys.stderr = original_stderr
@@ -1,23 +1,37 @@
1
1
  from abc import ABC, abstractmethod
2
- from orionis.foundation.config.testing.entities.testing import Testing as Configuration
3
2
  from orionis.test.suites.test_unit import UnitTest
4
3
 
5
4
  class ITestSuite(ABC):
6
- """
7
- Interface for configuring and running a UnitTest suite using a provided Configuration.
8
- Methods:
9
- run(config: Configuration = None) -> UnitTest
10
- """
11
5
 
12
6
  @abstractmethod
13
- def run(self, config: Configuration = None) -> UnitTest:
7
+ def run(self) -> UnitTest:
14
8
  """
15
9
  Runs the test suite based on the provided configuration.
16
- Args:
17
- config (Configuration, optional): An optional Configuration object for the test suite.
18
- Returns:
19
- UnitTest: The result of the executed test suite.
20
- Raises:
21
- OrionisTestConfigException: If the config parameter is not an instance of Configuration.
10
+
11
+ Initializes a UnitTest suite, configures it with parameters from the Configuration object,
12
+ discovers test folders matching the specified pattern, adds the discovered tests to the suite,
13
+ executes the test suite, and returns the results.
14
+
15
+ Returns
16
+ -------
17
+ UnitTest
18
+ The result of the executed test suite.
19
+
20
+ Raises
21
+ ------
22
+ OrionisTestConfigException
23
+ If the provided configuration is not an instance of Configuration.
22
24
  """
23
25
  pass
26
+
27
+ @abstractmethod
28
+ def getResult(self) -> UnitTest:
29
+ """
30
+ Returns the results of the executed test suite.
31
+
32
+ Returns
33
+ -------
34
+ UnitTest
35
+ The result of the executed test suite.
36
+ """
37
+ pass
@@ -3,32 +3,45 @@ from typing import Any, Dict, List, Optional
3
3
  from orionis.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
- """
10
6
 
11
7
  @abstractmethod
12
8
  def configure(
13
9
  self,
14
10
  verbosity: int = None,
15
- execution_mode: ExecutionMode = None,
11
+ execution_mode: str | ExecutionMode = None,
16
12
  max_workers: int = None,
17
13
  fail_fast: bool = None,
18
- print_result: bool = None
14
+ print_result: bool = None,
15
+ throw_exception: bool = False,
16
+ persistent: bool = False,
17
+ persistent_driver: str = 'sqlite'
19
18
  ):
20
19
  """
21
20
  Configures the UnitTest instance with the specified parameters.
22
21
 
23
- Parameters:
24
- verbosity (int, optional): The verbosity level for test output. Defaults to None.
25
- execution_mode (ExecutionMode, optional): The mode in which the tests will be executed. Defaults to None.
26
- max_workers (int, optional): The maximum number of workers to use for parallel execution. Defaults to None.
27
- fail_fast (bool, optional): Whether to stop execution upon the first failure. Defaults to None.
28
- print_result (bool, optional): Whether to print the test results after execution. Defaults to None.
22
+ Parameters
23
+ ----------
24
+ verbosity : int, optional
25
+ The verbosity level for test output. If None, the current setting is retained.
26
+ execution_mode : str or ExecutionMode, optional
27
+ The mode in which the tests will be executed ('SEQUENTIAL' or 'PARALLEL'). If None, the current setting is retained.
28
+ max_workers : int, optional
29
+ The maximum number of workers to use for parallel execution. If None, the current setting is retained.
30
+ fail_fast : bool, optional
31
+ Whether to stop execution upon the first failure. If None, the current setting is retained.
32
+ print_result : bool, optional
33
+ Whether to print the test results after execution. If None, the current setting is retained.
34
+ throw_exception : bool, optional
35
+ Whether to throw an exception if any test fails. Defaults to False.
36
+ persistent : bool, optional
37
+ Whether to persist the test results in a database. Defaults to False.
38
+ persistent_driver : str, optional
39
+ The driver to use for persistent storage. Defaults to 'sqlite'.
29
40
 
30
- Returns:
31
- UnitTest: The configured UnitTest instance.
41
+ Returns
42
+ -------
43
+ UnitTest
44
+ The configured UnitTest instance.
32
45
  """
33
46
  pass
34
47
 
@@ -42,85 +55,112 @@ class IUnitTest(ABC):
42
55
  tags: Optional[List[str]] = None
43
56
  ):
44
57
  """
45
- Discovers and loads unit tests from a specified folder.
46
- Args:
47
- folder_path (str): The relative path to the folder containing the tests.
48
- base_path (str, optional): The base directory where the test folder is located. Defaults to "tests".
49
- pattern (str, optional): The filename pattern to match test files. Defaults to "test_*.py".
50
- test_name_pattern (Optional[str], optional): A pattern to filter test names. Defaults to None.
51
- tags (Optional[List[str]], optional): A list of tags to filter tests. Defaults to None.
52
- Returns:
53
- UnitTest: The current instance of the UnitTest class with the discovered tests added.
54
- Raises:
55
- ValueError: If the test folder does not exist, no tests are found, or an error occurs during test discovery.
58
+ Parameters
59
+ ----------
60
+ folder_path : str
61
+ The relative path to the folder containing the tests.
62
+ base_path : str, optional
63
+ The base directory where the test folder is located. Defaults to "tests".
64
+ pattern : str, optional
65
+ The filename pattern to match test files. Defaults to "test_*.py".
66
+ test_name_pattern : str or None, optional
67
+ A pattern to filter test names. Defaults to None.
68
+ tags : list of str or None, optional
69
+ A list of tags to filter tests. Defaults to None.
70
+
71
+ Returns
72
+ -------
73
+ UnitTest
74
+ The current instance of the UnitTest class with the discovered tests added.
75
+
76
+ Raises
77
+ ------
78
+ OrionisTestValueError
79
+ If the test folder does not exist, no tests are found, or an error occurs during test discovery.
80
+
81
+ Notes
82
+ -----
83
+ This method updates the internal test suite with the discovered tests and tracks the number of tests found.
56
84
  """
57
85
  pass
58
86
 
59
87
  @abstractmethod
60
88
  def discoverTestsInModule(self, module_name: str, test_name_pattern: Optional[str] = None):
61
89
  """
62
- Discovers and loads tests from a specified module, optionally filtering them
63
- by a test name pattern, and adds them to the test suite.
64
- Args:
65
- module_name (str): The name of the module to discover tests from.
66
- test_name_pattern (Optional[str]): A pattern to filter test names. Only
67
- tests matching this pattern will be included. Defaults to None.
68
- Returns:
69
- UnitTest: The current instance of the UnitTest class, allowing method chaining.
70
- Raises:
71
- ValueError: If the specified module cannot be imported.
90
+ Discovers and loads tests from a specified module, optionally filtering by a test name pattern, and adds them to the test suite.
91
+
92
+ Parameters
93
+ ----------
94
+ module_name : str
95
+ Name of the module from which to discover tests.
96
+ test_name_pattern : str, optional
97
+ Pattern to filter test names. Only tests matching this pattern will be included. Defaults to None.
98
+
99
+ Returns
100
+ -------
101
+ UnitTest
102
+ The current instance of the UnitTest class, allowing method chaining.
103
+
104
+ Exceptions
105
+ ----------
106
+ OrionisTestValueError
107
+ If the specified module cannot be imported.
72
108
  """
73
109
  pass
74
110
 
75
111
  @abstractmethod
76
- def run(self, print_result: bool = None, throw_exception: bool = False) -> Dict[str, Any]:
112
+ def run(self, print_result: bool = None, throw_exception: bool = None) -> Dict[str, Any]:
77
113
  """
78
114
  Executes the test suite and processes the results.
79
- Args:
80
- print_result (bool, optional): If provided, overrides the instance's
81
- `print_result` attribute to determine whether to print the test results.
82
- throw_exception (bool, optional): If True, raises an exception if any
83
- test failures or errors are detected.
84
- Returns:
85
- Dict[str, Any]: A summary of the test execution, including details such as
86
- execution time, test results, and a timestamp.
87
- Raises:
88
- OrionisTestFailureException: If `throw_exception` is True and there are
89
- test failures or errors.
115
+
116
+ Parameters
117
+ ----------
118
+ print_result : bool, optional
119
+ If provided, overrides the instance's `print_result` attribute to determine whether to print results.
120
+ throw_exception : bool, optional
121
+ If True, raises an exception if any test failures or errors are detected.
122
+
123
+ Returns
124
+ -------
125
+ dict
126
+ A summary of the test execution, including details such as execution time, results, and timestamp.
127
+
128
+ Raises
129
+ ------
130
+ OrionisTestFailureException
131
+ If `throw_exception` is True and there are test failures or errors.
90
132
  """
91
133
  pass
92
134
 
93
135
  @abstractmethod
94
136
  def getTestNames(self) -> List[str]:
95
137
  """
96
- Retrieves a list of test names from the test suite.
138
+ Get a list of test names (unique identifiers) from the test suite.
97
139
 
98
- This method flattens the test suite and extracts the unique identifier
99
- (`id`) of each test case.
100
-
101
- Returns:
102
- List[str]: A list of test names (unique identifiers) from the test suite.
140
+ Returns
141
+ -------
142
+ List[str]
143
+ List of test names (unique identifiers) from the test suite.
103
144
  """
104
145
  pass
105
146
 
106
147
  @abstractmethod
107
148
  def getTestCount(self) -> int:
108
149
  """
109
- Calculate the total number of tests in the test suite.
110
-
111
- This method flattens the test suite structure and counts the total
112
- number of individual test cases.
150
+ Returns the total number of test cases in the test suite.
113
151
 
114
- Returns:
115
- int: The total number of test cases in the test suite.
152
+ Returns
153
+ -------
154
+ int
155
+ The total number of individual test cases in the suite.
116
156
  """
117
157
  pass
118
158
 
119
159
  @abstractmethod
120
160
  def clearTests(self) -> None:
121
161
  """
122
- Clears the current test suite by reinitializing it to an empty `unittest.TestSuite`.
162
+ Clear all tests from the current test suite.
123
163
 
124
- This method is used to reset the test suite, removing any previously added tests.
164
+ Resets the internal test suite to an empty `unittest.TestSuite`, removing any previously added tests.
125
165
  """
126
166
  pass
@@ -7,25 +7,36 @@ from orionis.test.suites.test_unit import UnitTest
7
7
 
8
8
  class TestSuite(ITestSuite):
9
9
  """
10
- TestSuite is a class responsible for managing and executing a suite of unit tests based on a configurable set of parameters.
11
- config (Configuration, optional): An optional Configuration object that specifies parameters for the test suite execution. If not provided, a new Configuration instance is created.
12
- _config (Configuration): The configuration object used to control test suite behavior, such as verbosity, execution mode, worker count, and test discovery patterns.
13
- Methods:
14
- __init__(config: Configuration = None):
15
- Initializes the TestSuite with the provided configuration or a default one.
16
- run() -> UnitTest:
17
- Executes the test suite according to the configuration. Discovers test folders matching the specified pattern, adds discovered tests to the suite, and runs them.
10
+ TestSuite manages and executes a suite of unit tests based on a configurable set of parameters.
11
+
12
+ Parameters
13
+ ----------
14
+ config : Configuration, optional
15
+ Configuration object specifying parameters for test suite execution. If not provided, a new Configuration instance is created.
16
+
17
+ Attributes
18
+ ----------
19
+ _config : Configuration
20
+ The configuration object controlling test suite behavior, such as verbosity, execution mode, worker count, and test discovery patterns.
21
+
22
+ Methods
23
+ -------
24
+ __init__(config=None)
25
+ Initializes the TestSuite with the provided configuration or a default one.
26
+ run()
27
+ Executes the test suite according to the configuration. Discovers test folders matching the specified pattern, adds discovered tests to the suite, and runs them.
28
+ getResult()
29
+ Returns the results of the executed test suite.
18
30
  """
19
31
 
20
32
  def __init__(self, config:Configuration = None):
21
33
  """
22
- Initializes the object with the given configuration.
23
-
24
- Args:
25
- config (Configuration, optional): An optional Configuration object to initialize with. Defaults to None.
34
+ Initializes the TestSuite with the provided configuration.
26
35
 
27
- Attributes:
28
- _config (Configuration): The configuration used by the object. If no configuration is provided, a new Configuration instance is created.
36
+ Parameters
37
+ ----------
38
+ config : Configuration, optional
39
+ Configuration object specifying parameters for test suite execution. If not provided, a new Configuration instance is created.
29
40
  """
30
41
  self.__config = config or Configuration()
31
42
  self.__result = None
@@ -33,13 +44,20 @@ class TestSuite(ITestSuite):
33
44
  def run(self) -> UnitTest:
34
45
  """
35
46
  Runs the test suite based on the provided configuration.
36
- This method initializes a UnitTest suite, configures it with parameters from the Configuration object,
37
- discovers test folders matching the specified pattern, and adds the discovered tests to the suite.
38
- Finally, it executes the test suite and returns the results.
39
- Returns:
40
- UnitTest: The result of the executed test suite.
41
- Raises:
42
- OrionisTestConfigException: If the provided configuration is not an instance of Configuration.
47
+
48
+ Initializes a UnitTest suite, configures it with parameters from the Configuration object,
49
+ discovers test folders matching the specified pattern, adds the discovered tests to the suite,
50
+ executes the test suite, and returns the results.
51
+
52
+ Returns
53
+ -------
54
+ UnitTest
55
+ The result of the executed test suite.
56
+
57
+ Raises
58
+ ------
59
+ OrionisTestConfigException
60
+ If the provided configuration is not an instance of Configuration.
43
61
  """
44
62
 
45
63
  # Check if the config is provided
@@ -61,6 +79,7 @@ class TestSuite(ITestSuite):
61
79
  print_result=config.print_result,
62
80
  throw_exception=config.throw_exception,
63
81
  persistent=config.persistent,
82
+ persistent_driver=config.persistent_driver,
64
83
  )
65
84
 
66
85
  # Extract configuration values
@@ -101,13 +120,15 @@ class TestSuite(ITestSuite):
101
120
 
102
121
  # Return the initialized test suite
103
122
  self.__result = tests.run()
104
- return self.__result
123
+ return self
105
124
 
106
125
  def getResult(self) -> UnitTest:
107
126
  """
108
127
  Returns the results of the executed test suite.
109
128
 
110
- Returns:
111
- UnitTest: The result of the executed test suite.
129
+ Returns
130
+ -------
131
+ UnitTest
132
+ The result of the executed test suite.
112
133
  """
113
134
  return self.__result