orionis 0.292.0__py3-none-any.whl → 0.293.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.
@@ -5,7 +5,7 @@
5
5
  NAME = "orionis"
6
6
 
7
7
  # Current version of the framework
8
- VERSION = "0.292.0"
8
+ VERSION = "0.293.0"
9
9
 
10
10
  # Full name of the author or maintainer of the project
11
11
  AUTHOR = "Raul Mauricio Uñate Castro"
@@ -25,6 +25,8 @@ from orionis.test.exceptions.test_failure_exception import OrionisTestFailureExc
25
25
  from orionis.test.exceptions.test_value_error import OrionisTestValueError
26
26
  from orionis.test.logs.history import TestHistory
27
27
  from orionis.test.suites.contracts.test_unit import IUnitTest
28
+ from orionis.test.view.render import TestingResultRender
29
+ from rich.text import Text
28
30
 
29
31
  class UnitTest(IUnitTest):
30
32
  """
@@ -757,6 +759,15 @@ class UnitTest(IUnitTest):
757
759
  if self.persistent:
758
760
  self._persistTestResults(report)
759
761
 
762
+ # Handle Web Report Rendering
763
+ path = self._webReport(report)
764
+
765
+ # Elegant invitation to view the results, with underlined path
766
+ invite_text = Text("Test results saved. ", style="green")
767
+ invite_text.append("View report: ", style="bold green")
768
+ invite_text.append(str(path), style="underline blue")
769
+ self.rich_console.print(invite_text)
770
+
760
771
  # Return the summary
761
772
  return {
762
773
  "total_tests": result.testsRun,
@@ -769,6 +780,45 @@ class UnitTest(IUnitTest):
769
780
  "test_details": test_details
770
781
  }
771
782
 
783
+ def _webReport(self, summary: Dict[str, Any]) -> None:
784
+ """
785
+ Generates a web report for the test results summary.
786
+
787
+ Parameters
788
+ ----------
789
+ summary : dict
790
+ The summary of test results to generate a web report for.
791
+
792
+ Returns
793
+ -------
794
+ str
795
+ The path to the generated web report.
796
+
797
+ Notes
798
+ -----
799
+ - Determines the storage path based on the current working directory and base_path.
800
+ - Uses TestingResultRender to generate the report.
801
+ - If persistence is enabled and the driver is 'sqlite', the report is marked as persistent.
802
+ - Returns the path to the generated report for further use.
803
+ """
804
+ # Determine the absolute path for storing results
805
+ project = os.path.basename(os.getcwd())
806
+ storage_path = os.path.abspath(os.path.join(os.getcwd(), self.base_path))
807
+
808
+ # Only use storage_path if project is recognized
809
+ if project not in ['framework', 'orionis']:
810
+ storage_path = None
811
+
812
+ # Create the TestingResultRender instance with the storage path and summary
813
+ render = TestingResultRender(
814
+ storage_path=storage_path,
815
+ result=summary,
816
+ persist=self.persistent and self.persistent_driver == 'sqlite'
817
+ )
818
+
819
+ # Render the report and return the path
820
+ return render.render()
821
+
772
822
  def _persistTestResults(self, summary: Dict[str, Any]) -> None:
773
823
  """
774
824
  Persist the test results summary using the configured persistent driver.
@@ -793,13 +843,13 @@ class UnitTest(IUnitTest):
793
843
  """
794
844
 
795
845
  try:
796
- if self.persistent_driver == 'sqlite':
846
+ # Determine the absolute path for storing results
847
+ project = os.getcwd().split(os.sep)[-1]
848
+ storage_path = None
849
+ if project in ['framework', 'orionis']:
850
+ storage_path = os.path.abspath(os.path.join(os.getcwd(), self.base_path))
797
851
 
798
- # Determine the absolute path for storing results
799
- project = os.getcwd().split(os.sep)[-1]
800
- storage_path = None
801
- if project in ['framework', 'orionis']:
802
- storage_path = os.path.abspath(os.path.join(os.getcwd(), self.base_path))
852
+ if self.persistent_driver == 'sqlite':
803
853
 
804
854
  # Initialize the TestHistory class for database operations
805
855
  history = TestHistory(
@@ -813,14 +863,14 @@ class UnitTest(IUnitTest):
813
863
 
814
864
  elif self.persistent_driver == 'json':
815
865
 
866
+ # Ensure the base path exists and write the summary to a JSON file
867
+ os.makedirs(storage_path, exist_ok=True)
868
+
816
869
  # Get the current timestamp for the log file name
817
870
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
818
871
 
819
- # Ensure the base path exists and write the summary to a JSON file
820
- os.makedirs(self.base_path, exist_ok=True)
821
-
822
872
  # Create the log file path with the timestamp
823
- log_path = os.path.join(self.base_path, f'test_{timestamp}.json')
873
+ log_path = os.path.abspath(os.path.join(storage_path, f'test_{timestamp}.json'))
824
874
 
825
875
  # Write the summary to the JSON file
826
876
  with open(log_path, 'w', encoding='utf-8') as log:
@@ -0,0 +1,128 @@
1
+ import json
2
+ import os
3
+ from pathlib import Path
4
+ from orionis.services.environment.env import Env
5
+ from orionis.test.logs.history import TestHistory
6
+
7
+ class TestingResultRender:
8
+
9
+ def __init__(
10
+ self,
11
+ result,
12
+ storage_path:str = None,
13
+ persist=False
14
+ ):
15
+ """
16
+ Initialize the TestingResultRender object.
17
+
18
+ Parameters
19
+ ----------
20
+ result : Any
21
+ The test result data to be processed or stored.
22
+ storage_path : str, optional
23
+ Custom path to store the test report. If not provided, uses the environment variable
24
+ 'TEST_REPORT_PATH' or defaults to a local storage path.
25
+ persist : bool, optional
26
+ Whether to persist the report. Defaults to False.
27
+
28
+ Notes
29
+ -----
30
+ - Determines the file path for the test report based on the provided storage_path, environment variable,
31
+ or a default location.
32
+ - Ensures the parent directory for the report exists.
33
+ - Stores the resolved report path in the environment variable 'TEST_REPORT_PATH'.
34
+ """
35
+
36
+ # Initialize instance variables
37
+ self.__filename = 'test-results.html'
38
+ self.__result = result
39
+ self.__persist = persist
40
+
41
+ # Determine file path
42
+ db_path = None
43
+ if storage_path:
44
+ db_path = Path(storage_path).expanduser().resolve()
45
+ if db_path.is_dir():
46
+ db_path = db_path / self.__filename
47
+ else:
48
+ env_path = Env.get("TEST_REPORT_PATH", None)
49
+ if env_path:
50
+ db_path = Path(env_path).expanduser().resolve()
51
+ if db_path.is_dir():
52
+ db_path = db_path / self.__filename
53
+ else:
54
+ db_path = Path.cwd() / 'storage/framework/testing' / self.__filename
55
+
56
+ # Ensure parent directory exists
57
+ db_path.parent.mkdir(parents=True, exist_ok=True)
58
+
59
+ # Store path in environment
60
+ Env.set("TEST_REPORT_PATH", str(db_path), 'path')
61
+ self.__report_path = db_path
62
+
63
+ def render(self):
64
+ """
65
+ Otherwise, uses the current test result stored in memory. The method replaces placeholders in a
66
+ template file with the test results and the persistence mode, then writes the rendered content
67
+ to a report file.
68
+
69
+ Parameters
70
+ ----------
71
+ None
72
+
73
+ Returns
74
+ -------
75
+ str
76
+ The full path to the generated report file.
77
+
78
+ Notes
79
+ -----
80
+ - If persistence is enabled, the last 10 reports are fetched from the SQLite database.
81
+ - If persistence is not enabled, only the current test result in memory is used.
82
+ - The method reads a template file, replaces placeholders with the test results and persistence mode,
83
+ and writes the final content to the report file.
84
+ """
85
+
86
+ # Determine the source of test results based on persistence mode
87
+ if self.__persist:
88
+ # If persistence is enabled, fetch the last 10 reports from SQLite
89
+ logs = TestHistory()
90
+ reports = logs.get(last=10)
91
+ # Parse each report's JSON data into a list
92
+ results_list = [json.loads(report[1]) for report in reports]
93
+ else:
94
+ # If not persistent, use only the current in-memory result
95
+ results_list = [self.__result]
96
+
97
+ # Set placeholder values for the template
98
+ persistence_mode = 'SQLite' if self.__persist else 'Static'
99
+ test_results_json = json.dumps(results_list, ensure_ascii=False, indent=None)
100
+
101
+ # Locate the HTML template file
102
+ template_path = Path(__file__).parent / 'report.stub'
103
+
104
+ # Read the template content
105
+ with open(template_path, 'r', encoding='utf-8') as template_file:
106
+ template_content = template_file.read()
107
+
108
+ # Replace placeholders with actual values
109
+ rendered_content = template_content.replace(
110
+ '{{orionis-testing-result}}',
111
+ test_results_json
112
+ ).replace(
113
+ '{{orionis-testing-persistent}}',
114
+ persistence_mode
115
+ )
116
+
117
+ # Write the rendered HTML report to the specified path
118
+ with open(self.__report_path, 'w', encoding='utf-8') as report_file:
119
+ report_file.write(rendered_content)
120
+
121
+ # Open the generated report in the default web browser if running on Windows or macOS.
122
+ # This provides immediate feedback to the user after report generation.
123
+ if os.name == 'nt' or os.name == 'posix' and sys.platform == 'darwin':
124
+ import webbrowser
125
+ webbrowser.open(self.__report_path.as_uri())
126
+
127
+ # Return the absolute path to the generated report
128
+ return str(self.__report_path)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orionis
3
- Version: 0.292.0
3
+ Version: 0.293.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
@@ -226,7 +226,7 @@ orionis/foundation/config/testing/entities/testing.py,sha256=m_i9jZlOXs_AzNKNNf0
226
226
  orionis/foundation/config/testing/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
227
227
  orionis/foundation/config/testing/enums/test_mode.py,sha256=IbFpauu7J-iSAfmC8jDbmTEYl8eZr-AexL-lyOh8_74,337
228
228
  orionis/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
229
- orionis/metadata/framework.py,sha256=7Ko8j0LyRbf2F4ayJKqLau4RUwwdelswaW4ISf8MnFQ,4960
229
+ orionis/metadata/framework.py,sha256=QmC-g5i6UhTE0QWIF78bMyfW6Dm4d4521_PuYknYoGQ,4960
230
230
  orionis/metadata/package.py,sha256=tqLfBRo-w1j_GN4xvzUNFyweWYFS-qhSgAEc-AmCH1M,5452
231
231
  orionis/patterns/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
232
232
  orionis/patterns/singleton/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -345,16 +345,16 @@ orionis/test/output/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5N
345
345
  orionis/test/output/contracts/dumper.py,sha256=5OqGc4GEXCXX76sCX185giQMyKwwZvlOv3I7tTwV2fQ,1324
346
346
  orionis/test/suites/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
347
347
  orionis/test/suites/test_suite.py,sha256=fdVmC56PJfWDuYeekY7oN-04AEHMqxwLI5mZNJAuOZI,5261
348
- orionis/test/suites/test_unit.py,sha256=ZkpRyUEHsxnbto3FBmvPfFHHRyOgv4NBIcS2LF1-Y_s,49374
348
+ orionis/test/suites/test_unit.py,sha256=JAla82Uc2OEvvBTE8oI8BT0hxeb03FJB1bdKU7G2xlA,51293
349
349
  orionis/test/suites/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
350
350
  orionis/test/suites/contracts/test_suite.py,sha256=eluzYwkNBbKjxYStj_tHN_Fm3YDPpGQdqMu5eiluh-E,1059
351
351
  orionis/test/suites/contracts/test_unit.py,sha256=l1LQllODyvcSByXMl1lGrUkoLsXbBHZZLWZI4A-mlQg,5881
352
352
  orionis/test/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
353
- orionis/test/view/index.html,sha256=1qamNWmUjyOKcMnNiVfjvYMT_CHsmz7WDhBzp0dQkV8,25731
354
- orionis-0.292.0.dist-info/licenses/LICENCE,sha256=-_4cF2EBKuYVS_SQpy1uapq0oJPUU1vl_RUWSy2jJTo,1111
353
+ orionis/test/view/render.py,sha256=jXZkbITBknbUwm_mD8bcTiwLDvsFkrO9qrf0ZgPwqxc,4903
354
+ orionis-0.293.0.dist-info/licenses/LICENCE,sha256=-_4cF2EBKuYVS_SQpy1uapq0oJPUU1vl_RUWSy2jJTo,1111
355
355
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
356
356
  tests/example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
357
- tests/example/test_example.py,sha256=pGj3mn6HslmqVNEc_2cbMwbIEcCjT08fLsZ47sz5bvk,601
357
+ tests/example/test_example.py,sha256=byd_lI6tVDgGPEIrr7PLZbBu0UoZOymmdmyA_4u-QUw,601
358
358
  tests/foundation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
359
359
  tests/foundation/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
360
360
  tests/foundation/config/app/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -455,8 +455,8 @@ tests/support/inspection/fakes/fake_reflection_instance_with_abstract.py,sha256=
455
455
  tests/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
456
456
  tests/testing/test_testing_result.py,sha256=MrGK3ZimedL0b5Ydu69Dg8Iul017AzLTm7VPxpXlpfU,4315
457
457
  tests/testing/test_testing_unit.py,sha256=A6QkiOkP7GPC1Szh_GqsrV7GxjWjK8cIwFez6YfrzmM,7683
458
- orionis-0.292.0.dist-info/METADATA,sha256=4zAZQi8NiTjCdg0efqEfXRXRP_RTRfnScor13qqt_jY,4772
459
- orionis-0.292.0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
460
- orionis-0.292.0.dist-info/top_level.txt,sha256=2bdoHgyGZhOtLAXS6Om8OCTmL24dUMC_L1quMe_ETbk,14
461
- orionis-0.292.0.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
462
- orionis-0.292.0.dist-info/RECORD,,
458
+ orionis-0.293.0.dist-info/METADATA,sha256=VYamMjDShBXxI6Quu-380uo1bp772T2nDaTlWcmJdwI,4772
459
+ orionis-0.293.0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
460
+ orionis-0.293.0.dist-info/top_level.txt,sha256=2bdoHgyGZhOtLAXS6Om8OCTmL24dUMC_L1quMe_ETbk,14
461
+ orionis-0.293.0.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
462
+ orionis-0.293.0.dist-info/RECORD,,
@@ -17,7 +17,7 @@ class TestExample(TestCase):
17
17
  Ensures that the integer 2 is equal to itself.
18
18
  """
19
19
  # Check if 1 equals 1
20
- self.assertEqual(1, 2)
20
+ self.assertEqual(1, 1)
21
21
 
22
22
  # Check if 2 equals 2
23
23
  self.assertEqual(2, 2)
@@ -1,533 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Orionis Test Dashboard</title>
8
- <script src="https://cdn.tailwindcss.com"></script>
9
- <link rel="icon" href="https://orionis-framework.com/svg/logo.svg" />
10
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
11
- <link href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css" rel="stylesheet" />
12
- <link href="https://fonts.googleapis.com/css2?family=Fira+Mono:wght@400;500;700&display=swap" rel="stylesheet">
13
- </head>
14
-
15
- <style>
16
- /* Use a monospaced font for the table */
17
- #test-table,
18
- #test-table .gridjs-td,
19
- #test-table .gridjs-th {
20
- font-family: 'Fira Mono', 'Consolas', 'Menlo', 'Monaco', 'Liberation Mono', monospace !important;
21
- }
22
-
23
- #test-table .gridjs-td,
24
- #test-table .gridjs-th {
25
- max-width: 220px;
26
- white-space: normal;
27
- overflow-wrap: anywhere;
28
- text-overflow: initial;
29
- vertical-align: middle;
30
- font-size: 0.85rem; /* más pequeño */
31
- line-height: 1.28;
32
- }
33
-
34
- #test-table .gridjs-th {
35
- font-size: 0.82rem !important; /* aún más pequeño para los títulos */
36
- font-weight: 600;
37
- letter-spacing: 0.01em;
38
- }
39
-
40
- #test-table .gridjs-td.status-cell {
41
- max-width: 90px;
42
- text-align: center;
43
- font-weight: 600;
44
- letter-spacing: 0.02em;
45
- white-space: nowrap;
46
- font-size: 0.75em;
47
- padding-top: 0.2em;
48
- padding-bottom: 0.2em;
49
- }
50
-
51
- #test-table .gridjs-td.doc-cell {
52
- max-width: 60px;
53
- text-align: center;
54
- white-space: nowrap;
55
- }
56
-
57
- #test-table {
58
- overflow-x: auto;
59
- }
60
-
61
- .badge-status {
62
- display: inline-flex;
63
- align-items: center;
64
- gap: 0.3em;
65
- padding: 0.13em 0.6em;
66
- border-radius: 9999px;
67
- font-size: 0.78em;
68
- font-weight: 600;
69
- letter-spacing: 0.01em;
70
- }
71
-
72
- .badge-passed {
73
- background: #d1fae5;
74
- color: #059669;
75
- }
76
-
77
- .badge-failed {
78
- background: #fee2e2;
79
- color: #dc2626;
80
- }
81
-
82
- .badge-errors {
83
- background: #fef9c3;
84
- color: #ca8a04;
85
- }
86
-
87
- .badge-skipped {
88
- background: #e0e7ff;
89
- color: #3730a3;
90
- }
91
-
92
- .doc-btn {
93
- background: #eef2ff;
94
- color: #3730a3;
95
- border: none;
96
- border-radius: 0.5em;
97
- padding: 0.2em 0.8em;
98
- font-size: 0.92em;
99
- font-weight: 500;
100
- cursor: pointer;
101
- transition: background 0.15s;
102
- font-family: inherit;
103
- }
104
-
105
- .doc-btn:hover {
106
- background: #c7d2fe;
107
- }
108
-
109
- /* Modal styles */
110
- .orionis-modal {
111
- position: fixed;
112
- left: 0;
113
- top: 0;
114
- width: 100vw;
115
- height: 100vh;
116
- background: rgba(30, 41, 59, 0.45);
117
- display: flex !important;
118
- align-items: center;
119
- justify-content: center;
120
- z-index: 10000;
121
- }
122
-
123
- .orionis-modal-content {
124
- background: white;
125
- max-width: 70vw;
126
- width: 70vw;
127
- padding: 2em 1.5em 1.2em 1.5em;
128
- border-radius: 1.2em;
129
- box-shadow: 0 8px 32px 0 rgba(31, 41, 55, 0.18);
130
- position: relative;
131
- }
132
-
133
- .orionis-modal-close {
134
- position: absolute;
135
- top: 0.7em;
136
- right: 1em;
137
- font-size: 1.3em;
138
- color: #64748b;
139
- background: none;
140
- border: none;
141
- cursor: pointer;
142
- }
143
-
144
- .orionis-modal-title {
145
- font-size: 0.98em; /* reducido de 1.08em */
146
- font-weight: 600;
147
- margin-bottom: 0.7em;
148
- color: #3730a3;
149
- display: flex;
150
- align-items: center;
151
- gap: 0.5em;
152
- font-family: inherit;
153
- }
154
-
155
- .orionis-modal-pre {
156
- white-space: pre-wrap;
157
- font-size: 0.92em;
158
- color: #334155;
159
- background: #f1f5f9;
160
- padding: 1em;
161
- border-radius: 0.7em;
162
- max-height: 320px;
163
- overflow: auto;
164
- font-family: 'Fira Mono', 'Consolas', 'Menlo', 'Monaco', 'Liberation Mono', monospace;
165
- }
166
- </style>
167
-
168
- <body class="bg-gray-100 text-gray-800 font-sans">
169
- <div class="max-w-7xl mx-auto px-4 sm:px-6 py-8">
170
-
171
- <!-- Header -->
172
- <header class="bg-gradient-to-r from-blue-900 to-cyan-400 text-white rounded-2xl shadow-xl p-6 mb-10">
173
- <div class="flex flex-col md:flex-row justify-between items-center gap-4">
174
- <div class="flex items-center gap-4">
175
- <img src="https://orionis-framework.com/svg/logo.svg" alt="Orionis Logo"
176
- class="h-10 brightness-0 invert" />
177
- <h1 class="text-2xl font-light tracking-wider">Orionis Testing Results Dashboard</h1>
178
- </div>
179
- <div id="timestamp" class="text-sm text-white/90"></div>
180
- </header>
181
-
182
- <!-- Execution Summary Card -->
183
- <div class="w-full mb-10">
184
- <div class="bg-white rounded-2xl shadow-lg p-6 border-t-4 border-indigo-500 flex flex-col sm:flex-row items-center justify-between gap-4">
185
- <div>
186
- <div class="text-xs font-semibold text-gray-500 uppercase">Resumen de Ejecución</div>
187
- <div class="text-lg font-bold text-gray-800 mt-2" id="execution-summary-title">Select an execution</div>
188
- <div class="text-sm text-gray-600 mt-1" id="execution-summary-desc">Select an execution to view the summary.</div>
189
- </div>
190
- <div class="flex items-center gap-4">
191
- <div class="flex items-center gap-1 text-gray-700">
192
- <span id="execution-time">Duration: --:--:--</span>
193
- </div>
194
- </div>
195
- </div>
196
- </div>
197
-
198
- <!-- Summary Cards -->
199
- <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6 mb-10">
200
-
201
- <div class="bg-white rounded-2xl shadow-lg p-6 border-t-4 border-green-500">
202
- <div class="text-xs font-semibold text-gray-500 uppercase">Passed</div>
203
- <div class="text-4xl font-bold text-gray-800 mt-2" id="passed">0</div>
204
- <div class="mt-4 bg-gray-200 rounded-full h-2">
205
- <div class="bg-green-500 h-2 rounded-full" id="passed-progress" style="width: 0%"></div>
206
- </div>
207
- </div>
208
-
209
- <div class="bg-white rounded-2xl shadow-lg p-6 border-t-4 border-red-500">
210
- <div class="text-xs font-semibold text-gray-500 uppercase">Failed</div>
211
- <div class="text-4xl font-bold text-gray-800 mt-2" id="failed">0</div>
212
- </div>
213
-
214
- <div class="bg-white rounded-2xl shadow-lg p-6 border-t-4 border-yellow-500">
215
- <div class="text-xs font-semibold text-gray-500 uppercase">Errors</div>
216
- <div class="text-4xl font-bold text-gray-800 mt-2" id="errors">0</div>
217
- </div>
218
-
219
- <div class="bg-white rounded-2xl shadow-lg p-6 border-t-4 border-blue-500">
220
- <div class="text-xs font-semibold text-gray-500 uppercase">Skipped</div>
221
- <div class="text-4xl font-bold text-gray-800 mt-2" id="skipped">0</div>
222
- </div>
223
-
224
- </div>
225
-
226
- <!-- Download Buttons & Select -->
227
- <div class="flex flex-wrap justify-between items-center mb-10 gap-4">
228
- <!-- Buttons to the left -->
229
- <div class="flex flex-wrap gap-4">
230
- <button disabled id="download-json" class="flex items-center gap-2 bg-blue-300 text-white px-4 py-2 rounded shadow cursor-not-allowed opacity-60">
231
- <i class="bi bi-file-earmark-code-fill text-lg"></i>
232
- <span>Download JSON</span>
233
- </button>
234
- </div>
235
- <!-- Elegant Select to the right -->
236
- <div>
237
- <select class="appearance-none bg-white border border-gray-300 text-gray-700 py-2 px-4 pr-10 rounded-lg shadow focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-blue-400 transition text-base font-medium" id="test-select">
238
- </select>
239
- </div>
240
- </div>
241
-
242
- <!-- Table Summary View with Grid.js -->
243
- <div class="bg-white rounded-xl shadow-md p-5 border border-indigo-100">
244
- <div class="flex items-center gap-2 mb-3">
245
- <i class="bi bi-table text-lg text-indigo-500"></i>
246
- <h2 class="text-lg font-semibold text-indigo-900">Execution Details</h2>
247
- </div>
248
- <div class="text-gray-500 mb-4 text-sm">
249
- See all test cases for the selected execution.<br>Click
250
- <span class="inline-flex items-center gap-1 px-1.5 py-0.5 bg-blue-50 text-blue-700 rounded text-xs font-mono">
251
- <i class="bi bi-journal-text"></i> View
252
- </span>
253
- to show the docstring.
254
- </div>
255
- <div id="test-table"></div>
256
- </div>
257
-
258
- <!-- Footer -->
259
- <footer class="mt-12 text-center text-gray-500 text-sm py-6">
260
- Developed with the power of
261
- <a href="https://orionis-framework.com/" target="_blank" rel="noopener"
262
- class="font-semibold text-blue-700 hover:underline">
263
- Orionis Framework
264
- </a>
265
- <i class="bi bi-stars text-yellow-400 align-middle ml-1"></i>
266
- </footer>
267
-
268
- <script src="https://unpkg.com/gridjs/dist/gridjs.umd.js"></script>
269
- <script>
270
-
271
- const data = $data;
272
-
273
- // Live Clock (Header Timestamp)
274
- function updateClock() {
275
- const now = new Date();
276
- const formatted = now.toLocaleString('en-US', {
277
- year: 'numeric',
278
- month: '2-digit',
279
- day: '2-digit',
280
- hour: '2-digit',
281
- minute: '2-digit',
282
- second: '2-digit',
283
- hour12: false
284
- });
285
- document.getElementById("timestamp").textContent = `Current time: ${formatted}`;
286
- }
287
- updateClock();
288
- setInterval(updateClock, 1000);
289
-
290
- // Populate Dropdown in English
291
- let html = '<option selected disabled>Select an execution</option>';
292
- data.forEach((item, i) => {
293
- const date = new Date(item.timestamp);
294
- const formattedDate = `${date.getFullYear()}-${(date.getMonth() + 1)
295
- .toString()
296
- .padStart(2, '0')}-${date.getDate()
297
- .toString()
298
- .padStart(2, '0')} ${date.getHours()
299
- .toString()
300
- .padStart(2, '0')}:${date.getMinutes()
301
- .toString()
302
- .padStart(2, '0')}:${date.getSeconds()
303
- .toString()
304
- .padStart(2, '0')}`;
305
- html += `<option value="${i}">Execution ${i + 1} - ${formattedDate}</option>`;
306
- });
307
- document.getElementById("test-select").innerHTML = html;
308
-
309
- // Event Listener for the dropdown
310
- document.getElementById("test-select").addEventListener("change", function () {
311
- const selectedIndex = this.value;
312
- const selectedData = data[selectedIndex];
313
-
314
- // Animate Counters
315
- function animateValue(id, start, end, duration) {
316
- const obj = document.getElementById(id);
317
- let startTimestamp = null;
318
- const step = (timestamp) => {
319
- if (!startTimestamp) startTimestamp = timestamp;
320
- const progress = Math.min((timestamp - startTimestamp) / duration, 1);
321
- obj.textContent = Math.floor(progress * (end - start) + start);
322
- if (progress < 1) {
323
- window.requestAnimationFrame(step);
324
- } else {
325
- obj.textContent = end;
326
- }
327
- };
328
- window.requestAnimationFrame(step);
329
- }
330
- animateValue("passed", Number(document.getElementById("passed").textContent), selectedData.passed, 500);
331
- animateValue("failed", Number(document.getElementById("failed").textContent), selectedData.failed, 500);
332
- animateValue("errors", Number(document.getElementById("errors").textContent), selectedData.errors, 500);
333
- animateValue("skipped", Number(document.getElementById("skipped").textContent), selectedData.skipped, 500);
334
-
335
- // Animate Progress Bar
336
- const passedBar = document.getElementById("passed-progress");
337
- passedBar.style.transition = "width 0.6s cubic-bezier(0.4,0,0.2,1)";
338
- const passedPercentage = (selectedData.passed / selectedData.total_tests) * 100;
339
- passedBar.style.width = `${passedPercentage}%`;
340
-
341
- // Update Execution Summary
342
- const date = new Date(selectedData.timestamp);
343
- const formattedDate = `${date.getFullYear()}-${(date.getMonth()+1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}`;
344
- document.getElementById("execution-summary-title").innerHTML = `<span class="inline-flex items-center gap-2"><i class="bi bi-activity text-indigo-500"></i> Execution - <span class="font-mono">${formattedDate}</span></span>`;
345
- document.getElementById("execution-summary-desc").innerHTML =
346
- `<span class="inline-flex gap-2 flex-wrap">
347
- <span class="bg-green-100 text-green-800 px-2 py-1 rounded text-xs font-semibold"><i class="bi bi-check-circle-fill"></i> Passed: ${selectedData.passed}</span>
348
- <span class="bg-red-100 text-red-800 px-2 py-1 rounded text-xs font-semibold"><i class="bi bi-x-circle-fill"></i> Failed: ${selectedData.failed}</span>
349
- <span class="bg-yellow-100 text-yellow-800 px-2 py-1 rounded text-xs font-semibold"><i class="bi bi-exclamation-triangle-fill"></i> Errors: ${selectedData.errors}</span>
350
- <span class="bg-blue-100 text-blue-800 px-2 py-1 rounded text-xs font-semibold"><i class="bi bi-skip-forward-fill"></i> Skipped: ${selectedData.skipped}</span>
351
- <span class="bg-gray-100 text-gray-800 px-2 py-1 rounded text-xs font-semibold"><i class="bi bi-list-ol"></i> Total: ${selectedData.total_tests}</span>
352
- <span class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded text-xs font-semibold"><i class="bi bi-bar-chart-fill"></i> Success: ${selectedData.success_rate.toFixed(2)}%</span>
353
- </span>`;
354
-
355
- // Update Duration
356
- function formatTime(seconds) {
357
- const h = Math.floor(seconds / 3600).toString().padStart(2, '0');
358
- const m = Math.floor((seconds % 3600) / 60).toString().padStart(2, '0');
359
- const s = Math.floor(seconds % 60).toString().padStart(2, '0');
360
- return `${h}:${m}:${s}`;
361
- }
362
- document.getElementById("execution-time").innerHTML = `<i class="bi bi-clock-history text-indigo-500"></i> Duration: <span class="font-mono">${formatTime(selectedData.total_time)}</span>`;
363
-
364
- // Enable Download Button
365
- document.getElementById("download-json").disabled = false;
366
- document.getElementById("download-json").classList.remove("bg-blue-300", "cursor-not-allowed", "opacity-60");
367
- document.getElementById("download-json").classList.add("bg-blue-600", "hover:bg-blue-700", "cursor-pointer", "opacity-100");
368
- });
369
-
370
- // Download JSON report with execution date and time in filename
371
- document.getElementById("download-json").addEventListener("click", function () {
372
- const select = document.getElementById("test-select");
373
- const selectedIndex = select.value;
374
- if (selectedIndex === "" || selectedIndex === null || isNaN(selectedIndex)) return;
375
- const selectedData = data[selectedIndex];
376
- const jsonString = JSON.stringify(selectedData, null, 2);
377
- const date = new Date(selectedData.timestamp);
378
- // Format: YYYYMMDD_HHMMSS
379
- const formattedDate = `${date.getFullYear()}${(date.getMonth()+1).toString().padStart(2,'0')}${date.getDate().toString().padStart(2,'0')}_${date.getHours().toString().padStart(2,'0')}${date.getMinutes().toString().padStart(2,'0')}${date.getSeconds().toString().padStart(2,'0')}`;
380
- const filename = `test_report_${formattedDate}.json`;
381
- const blob = new Blob([jsonString], { type: "application/json" });
382
- const url = URL.createObjectURL(blob);
383
- const a = document.createElement("a");
384
- a.href = url;
385
- a.download = filename;
386
- document.body.appendChild(a);
387
- a.click();
388
- document.body.removeChild(a);
389
- URL.revokeObjectURL(url);
390
- });
391
-
392
- // Show doc string in a modal dialog (event delegation)
393
- function showDocString(doc) {
394
- // Remove any existing modal
395
- const oldModal = document.querySelector('.orionis-modal');
396
- if (oldModal) oldModal.remove();
397
-
398
- // Create modal element
399
- const modal = document.createElement('div');
400
- modal.className = 'orionis-modal';
401
- modal.style.display = 'flex'; // Ensure modal is visible
402
-
403
- modal.innerHTML = `
404
- <div class="orionis-modal-content">
405
- <button class="orionis-modal-close" aria-label="Cerrar" type="button">&times;</button>
406
- <div class="orionis-modal-title">
407
- <i class="bi bi-journal-text"></i> Docstring
408
- </div>
409
- <pre class="orionis-modal-pre">${doc ? String(doc).replace(/</g, "&lt;").replace(/>/g, "&gt;") : 'No docstring.'}</pre>
410
- </div>
411
- `;
412
- // Close modal when clicking outside content
413
- modal.addEventListener('mousedown', function (e) {
414
- if (e.target === modal) modal.remove();
415
- });
416
- // Close modal when clicking close button
417
- modal.querySelector('.orionis-modal-close').onclick = () => modal.remove();
418
- document.body.appendChild(modal);
419
- }
420
-
421
- function renderTestTable(testDetails) {
422
- if (window.testGrid) {
423
- try { window.testGrid.destroy(); } catch (e) { }
424
- }
425
- const tableDiv = document.getElementById("test-table");
426
- tableDiv.innerHTML = "";
427
-
428
- try {
429
- window.testGrid = new gridjs.Grid({
430
- columns: [
431
- { name: "ID", width: "22%" },
432
- { name: "Class", width: "12%" },
433
- { name: "Method", width: "14%" },
434
- { name: "Status", width: "11%" },
435
- { name: "Time (s)", width: "9%" },
436
- { name: "File", width: "22%" },
437
- { name: "Doc", width: "10%" }
438
- ],
439
- data: testDetails.map((t, idx) => [
440
- gridjs.html(`<div title="${t.id}">${t.id}</div>`),
441
- gridjs.html(`<div title="${t.class}">${t.class}</div>`),
442
- gridjs.html(`<div title="${t.method}">${t.method}</div>`),
443
- gridjs.html(`
444
- <span class="badge-status ${
445
- t.status === 'PASSED' ? 'badge-passed' :
446
- t.status === 'FAILED' ? 'badge-failed' :
447
- t.status === 'ERRORS' ? 'badge-errors' : 'badge-skipped'
448
- } status-cell">
449
- ${
450
- t.status === 'PASSED' ? '<i class="bi bi-check-circle-fill"></i>' :
451
- t.status === 'FAILED' ? '<i class="bi bi-x-circle-fill"></i>' :
452
- t.status === 'ERRORS' ? '<i class="bi bi-exclamation-triangle-fill"></i>' :
453
- '<i class="bi bi-skip-forward-fill"></i>'
454
- }
455
- ${t.status}
456
- </span>
457
- `),
458
- t.execution_time,
459
- gridjs.html(`<div title="${t.file_path}">${t.file_path}</div>`),
460
- gridjs.html(`<button class="doc-btn doc-cell" data-doc-idx="${idx}" type="button"><i class="bi bi-journal-text"></i> Ver</button>`)
461
- ]),
462
- search: {
463
- enabled: true,
464
- placeholder: 'Buscar solo por clase...'
465
- },
466
- pagination: { limit: 8, summary: false },
467
- sort: false,
468
- resizable: true,
469
- style: {
470
- th: { 'text-align': 'left', 'background': '#f1f5f9', 'font-size': '1em' }
471
- }
472
- }).render(tableDiv);
473
-
474
- // Delegated event for doc buttons (always works, even after pagination)
475
- tableDiv.addEventListener('click', function (e) {
476
- const btn = e.target.closest('.doc-btn');
477
- if (!btn) return;
478
- const idx = Number(btn.getAttribute('data-doc-idx'));
479
- const t = testDetails[idx];
480
- if (!t) return;
481
-
482
- let html = '';
483
- html += `<div class="orionis-modal-title"><i class="bi bi-journal-text"></i> Docstring</div>`;
484
- html += `<pre class="orionis-modal-pre">${t.doc_string ? String(t.doc_string).replace(/</g, "&lt;").replace(/>/g, "&gt;") : 'No docstring.'}</pre>`;
485
- if (t.status === 'FAILED' || t.status === 'ERRORS') {
486
- html += `<div class="orionis-modal-title mt-4"><i class="bi bi-bug-fill"></i> Traceback</div>`;
487
- html += `<pre class="orionis-modal-pre" style="background:#fee2e2;color:#991b1b">${t.traceback ? String(t.traceback).replace(/</g, "&lt;").replace(/>/g, "&gt;") : 'No traceback.'}</pre>`;
488
- }
489
-
490
- // Remove any existing modal
491
- const oldModal = document.querySelector('.orionis-modal');
492
- if (oldModal) oldModal.remove();
493
-
494
- // Create modal element
495
- const modal = document.createElement('div');
496
- modal.className = 'orionis-modal';
497
- modal.style.display = 'flex';
498
-
499
- modal.innerHTML = `
500
- <div class="orionis-modal-content">
501
- <button class="orionis-modal-close" aria-label="Cerrar" type="button">&times;</button>
502
- ${html}
503
- </div>
504
- `;
505
-
506
- // Close modal when clicking outside content
507
- modal.addEventListener('mousedown', function (e) {
508
- if (e.target === modal) modal.remove();
509
- });
510
-
511
- // Close modal when clicking close button
512
- modal.querySelector('.orionis-modal-close').onclick = () => modal.remove();
513
- document.body.appendChild(modal);
514
- });
515
- } catch (err) {
516
- tableDiv.innerHTML = `<div class="text-red-600 font-mono text-sm py-4">Ocurrió un error al mostrar la tabla.<br>${err.message}</div>`;
517
- }
518
- }
519
-
520
- document.getElementById("test-select").addEventListener("change", function () {
521
- const selectedIndex = this.value;
522
- if (!data[selectedIndex]) return;
523
- renderTestTable(data[selectedIndex].test_details);
524
- });
525
-
526
- document.addEventListener("DOMContentLoaded", function () {
527
- renderTestTable([]);
528
- });
529
-
530
- </script>
531
- </body>
532
-
533
- </html>