codecraftai-testbase 1.3.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.
- ccai/factories/py.typed +0 -0
- ccai/factories/testbasedefaulttypefactory.py +25 -0
- ccai/testbase/__init__.py +63 -0
- ccai/testbase/breakpoints.py +110 -0
- ccai/testbase/cli/__init__.py +13 -0
- ccai/testbase/cli/cmdtree/agents/__init__.py +28 -0
- ccai/testbase/cli/cmdtree/agents/config/__init__.py +24 -0
- ccai/testbase/cli/cmdtree/agents/config/extract.py +94 -0
- ccai/testbase/cli/cmdtree/agents/formatting.py +71 -0
- ccai/testbase/cli/cmdtree/agents/jsosparser.py +119 -0
- ccai/testbase/cli/cmdtree/agents/pathresolver.py +34 -0
- ccai/testbase/cli/cmdtree/agents/summary/__init__.py +26 -0
- ccai/testbase/cli/cmdtree/agents/summary/compare.py +128 -0
- ccai/testbase/cli/cmdtree/agents/summary/extract.py +91 -0
- ccai/testbase/cli/cmdtree/agents/testresult/__init__.py +28 -0
- ccai/testbase/cli/cmdtree/agents/testresult/extract.py +77 -0
- ccai/testbase/cli/cmdtree/agents/testresult/failures.py +73 -0
- ccai/testbase/cli/cmdtree/agents/testresult/list.py +63 -0
- ccai/testbase/cli/cmdtree/services/__init__.py +27 -0
- ccai/testbase/cli/cmdtree/services/results.py +66 -0
- ccai/testbase/cli/cmdtree/testing/__init__.py +30 -0
- ccai/testbase/cli/cmdtree/testing/jobs.py +175 -0
- ccai/testbase/cli/cmdtree/testing/query.py +131 -0
- ccai/testbase/cli/cmdtree/testing/run.py +263 -0
- ccai/testbase/cli/cmdtree/utilities/__init__.py +28 -0
- ccai/testbase/cli/cmdtree/utilities/timestamp.py +33 -0
- ccai/testbase/cli/options.py +370 -0
- ccai/testbase/cli/testbase_command.py +64 -0
- ccai/testbase/cli/utilities.py +31 -0
- ccai/testbase/configuration.py +324 -0
- ccai/testbase/constraints.py +998 -0
- ccai/testbase/coupling/__init__.py +569 -0
- ccai/testbase/coupling/basecoupling.py +69 -0
- ccai/testbase/coupling/configurationcoupling.py +138 -0
- ccai/testbase/coupling/integrationcoupling.py +842 -0
- ccai/testbase/coupling/validatorcoupling.py +127 -0
- ccai/testbase/debuggingext.py +281 -0
- ccai/testbase/debuglogging.py +407 -0
- ccai/testbase/debugports.py +469 -0
- ccai/testbase/declaration/__init__.py +13 -0
- ccai/testbase/declaration/attachments.py +222 -0
- ccai/testbase/declaration/originations.py +217 -0
- ccai/testbase/declaration/parameterization.py +160 -0
- ccai/testbase/declaration/registrations.py +476 -0
- ccai/testbase/diagnostic_level.py +197 -0
- ccai/testbase/diagnostic_streaming.py +1534 -0
- ccai/testbase/diagnostics.py +1685 -0
- ccai/testbase/entrypoints.py +485 -0
- ccai/testbase/environment.py +162 -0
- ccai/testbase/errors/testruntimeouterror.py +50 -0
- ccai/testbase/expressions.py +355 -0
- ccai/testbase/factories.py +277 -0
- ccai/testbase/factoryprotocols.py +35 -0
- ccai/testbase/features.py +913 -0
- ccai/testbase/initialize.py +210 -0
- ccai/testbase/injection/__init__.py +25 -0
- ccai/testbase/injection/injectiongroup.py +493 -0
- ccai/testbase/injection/injectionmoment.py +155 -0
- ccai/testbase/injection/injectionregistry.py +823 -0
- ccai/testbase/injection/injectionscope.py +2589 -0
- ccai/testbase/injection/introspection.py +514 -0
- ccai/testbase/markers.py +665 -0
- ccai/testbase/mocking.py +4856 -0
- ccai/testbase/origins/__init__.py +13 -0
- ccai/testbase/origins/resourceorigin.py +110 -0
- ccai/testbase/origins/validatororigin.py +111 -0
- ccai/testbase/output/__init__.py +17 -0
- ccai/testbase/output/outputcontext.py +201 -0
- ccai/testbase/output/runmetadata.py +184 -0
- ccai/testbase/properties/__init__.py +40 -0
- ccai/testbase/properties/assumptions.py +56 -0
- ccai/testbase/properties/decorators.py +173 -0
- ccai/testbase/properties/propertyrunner.py +449 -0
- ccai/testbase/properties/strategies.py +1592 -0
- ccai/testbase/properties/unittestsupport.py +87 -0
- ccai/testbase/py.typed +0 -0
- ccai/testbase/queries.py +95 -0
- ccai/testbase/resourcelifespan.py +24 -0
- ccai/testbase/results/__init__.py +35 -0
- ccai/testbase/results/exceptions.py +60 -0
- ccai/testbase/results/filtering/__init__.py +26 -0
- ccai/testbase/results/filtering/resultfilter.py +570 -0
- ccai/testbase/results/model/__init__.py +32 -0
- ccai/testbase/results/model/buildinfo.py +54 -0
- ccai/testbase/results/model/checkresult.py +183 -0
- ccai/testbase/results/model/forwardinginfo.py +30 -0
- ccai/testbase/results/model/jobcontainer.py +32 -0
- ccai/testbase/results/model/jobinfo.py +91 -0
- ccai/testbase/results/model/nestedprogressinfo.py +211 -0
- ccai/testbase/results/model/pipelineinfo.py +51 -0
- ccai/testbase/results/model/progressaggregator.py +551 -0
- ccai/testbase/results/model/progresscode.py +29 -0
- ccai/testbase/results/model/progressdelivery.py +51 -0
- ccai/testbase/results/model/progressinfo.py +84 -0
- ccai/testbase/results/model/progresstype.py +24 -0
- ccai/testbase/results/model/renderinfo.py +30 -0
- ccai/testbase/results/model/resultcode.py +28 -0
- ccai/testbase/results/model/resultcontainer.py +95 -0
- ccai/testbase/results/model/resultnode.py +258 -0
- ccai/testbase/results/model/resulttype.py +34 -0
- ccai/testbase/results/model/streaminginfo.py +111 -0
- ccai/testbase/results/model/taskinggroup.py +85 -0
- ccai/testbase/results/model/taskingresult.py +297 -0
- ccai/testbase/results/model/testcontainer.py +35 -0
- ccai/testbase/results/model/testresult.py +170 -0
- ccai/testbase/results/recorders/__init__.py +31 -0
- ccai/testbase/results/recorders/csvresultrecorder.py +414 -0
- ccai/testbase/results/recorders/jsonresultrecorder.py +467 -0
- ccai/testbase/results/recorders/resultrecorder.py +1472 -0
- ccai/testbase/results/recorders/stdoutresultrecorder.py +70 -0
- ccai/testbase/results/recorders/xmlresultrecorder.py +305 -0
- ccai/testbase/results/utilities.py +141 -0
- ccai/testbase/sequencing/__init__.py +13 -0
- ccai/testbase/sequencing/sequencermodulescope.py +96 -0
- ccai/testbase/sequencing/sequencerscopebase.py +91 -0
- ccai/testbase/sequencing/sequencersessionscope.py +84 -0
- ccai/testbase/sequencing/sequencertestscope.py +249 -0
- ccai/testbase/sequencing/sequencertestsetupscope.py +86 -0
- ccai/testbase/sequencing/testactivity.py +111 -0
- ccai/testbase/sequencing/testsequencer.py +3072 -0
- ccai/testbase/server/__init__.py +13 -0
- ccai/testbase/server/resultserver.py +599 -0
- ccai/testbase/sources/__init__.py +13 -0
- ccai/testbase/sources/configurationsource.py +32 -0
- ccai/testbase/sources/integrationsource.py +29 -0
- ccai/testbase/sources/resourcesource.py +27 -0
- ccai/testbase/sources/sourcebase.py +71 -0
- ccai/testbase/sources/unknownsource.py +30 -0
- ccai/testbase/sources/validatorsource.py +28 -0
- ccai/testbase/tandem/__init__.py +13 -0
- ccai/testbase/tandem/validators.py +286 -0
- ccai/testbase/testcollector.py +230 -0
- ccai/testbase/testgroup.py +54 -0
- ccai/testbase/testjob.py +600 -0
- ccai/testbase/testref.py +64 -0
- ccai/testbase/utilities.py +472 -0
- ccai/testbase/verification.py +768 -0
- codecraftai_testbase-1.3.0.dist-info/METADATA +99 -0
- codecraftai_testbase-1.3.0.dist-info/RECORD +142 -0
- codecraftai_testbase-1.3.0.dist-info/WHEEL +4 -0
- codecraftai_testbase-1.3.0.dist-info/entry_points.txt +3 -0
- codecraftai_testbase-1.3.0.dist-info/licenses/LICENSE.md +204 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.results.recorders.stdoutresultrecorder
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: The default ``testbase`` result recorder for standalone runs — records the
|
|
5
|
+
machine-readable JSOS/JSON artefacts and echoes the human-readable summary to
|
|
6
|
+
stdout, without the integration-only HTML rendering.
|
|
7
|
+
|
|
8
|
+
Plain ``testbase`` runs standalone (no ``codecraftai-runtime`` / ``codecraftai-this-app``) and has
|
|
9
|
+
no HTML summary template or static-resource directory. :class:`StdoutResultRecorder` is the
|
|
10
|
+
default recorder used by :class:`ccai.testbase.testjob.TestJob`: it reuses the JSOS stream
|
|
11
|
+
and JSON summary serialisation (so the ``testbase agents`` machine CLI can still consume the
|
|
12
|
+
artefacts), skips the HTML template / static-resource publication, and prints the run summary
|
|
13
|
+
to stdout so results are visible without any reporting infrastructure.
|
|
14
|
+
|
|
15
|
+
The integration runtime (``codecraftai-integration-runtime`` / ``IntegratedTestJob``) overrides
|
|
16
|
+
``TestJob._create_recorder`` to use the full HTML-rendering recorder instead.
|
|
17
|
+
|
|
18
|
+
.. note::
|
|
19
|
+
Phase-2 transitional design: this subclasses :class:`JsonResultRecorder` (which is
|
|
20
|
+
import-clean of runtime/this-app) to reuse its JSON/JSOS serialisation. When the HTML
|
|
21
|
+
rendering is split out of ``JsonResultRecorder`` into the integration runtime (Phase 3),
|
|
22
|
+
this recorder is re-based onto the JSON/JSOS serialisation core that remains in
|
|
23
|
+
``testbase``. See ``REFACTOR-TESTBASE-INTEGRATION-RUNTIME-ROADMAP.md`` (§3, §7.2).
|
|
24
|
+
|
|
25
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
__author__ = "Myron Walker"
|
|
29
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
30
|
+
__credits__ = []
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
from ccai.testbase.results.recorders.jsonresultrecorder import JsonResultRecorder
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class StdoutResultRecorder(JsonResultRecorder):
|
|
37
|
+
"""
|
|
38
|
+
Standalone result recorder that produces the JSOS/JSON artefacts and echoes the run
|
|
39
|
+
summary to stdout, without the integration-only HTML rendering.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def initialize_report(self):
|
|
43
|
+
"""
|
|
44
|
+
Standalone runs have no HTML summary template or static-resource directory to
|
|
45
|
+
publish, so report initialisation is a no-op. The JSOS result stream and the JSON
|
|
46
|
+
summary are still written by the inherited recorder behaviour.
|
|
47
|
+
|
|
48
|
+
:returns: None
|
|
49
|
+
"""
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
def finalize(self):
|
|
53
|
+
"""
|
|
54
|
+
Finalises the recording (reusing the inherited counters / result-determination and
|
|
55
|
+
artefact writing) and then echoes the human-readable run summary to stdout exactly
|
|
56
|
+
once, even though ``finalize`` may be invoked both explicitly and by the context
|
|
57
|
+
manager's ``__exit__``.
|
|
58
|
+
|
|
59
|
+
:returns: None
|
|
60
|
+
"""
|
|
61
|
+
was_finalized = self._finalized
|
|
62
|
+
|
|
63
|
+
super().finalize()
|
|
64
|
+
|
|
65
|
+
if not was_finalized:
|
|
66
|
+
summary_lines = self.format_lines()
|
|
67
|
+
for line in summary_lines:
|
|
68
|
+
print(line, flush=True)
|
|
69
|
+
|
|
70
|
+
return
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.results.recorders.xmlresultrecorder
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for XML result recording.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: CodeCraftX
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = "CodeCraftX"
|
|
10
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
11
|
+
__credits__ = []
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from typing import Any, Optional
|
|
15
|
+
|
|
16
|
+
import xml.etree.ElementTree as ET
|
|
17
|
+
from xml.dom import minidom
|
|
18
|
+
|
|
19
|
+
from datetime import datetime
|
|
20
|
+
|
|
21
|
+
from ccai.xmodules.jsos import CHAR_RECORD_SEPERATOR
|
|
22
|
+
|
|
23
|
+
from ccai.testbase.results.exceptions import ResultRecordingError
|
|
24
|
+
from ccai.testbase.results.model.buildinfo import BuildInfo
|
|
25
|
+
from ccai.testbase.results.model.jobinfo import JobInfo
|
|
26
|
+
from ccai.testbase.results.model.pipelineinfo import PipelineInfo
|
|
27
|
+
from ccai.testbase.results.model.renderinfo import RenderInfo
|
|
28
|
+
|
|
29
|
+
from ccai.testbase.results.model.resultcode import ResultCode
|
|
30
|
+
from ccai.testbase.results.model.resultnode import ResultNode
|
|
31
|
+
from ccai.testbase.results.model.resulttype import ResultType
|
|
32
|
+
|
|
33
|
+
from ccai.testbase.results.recorders.resultrecorder import ResultRecorder
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _datetime_to_str(dt: datetime) -> str:
|
|
37
|
+
"""
|
|
38
|
+
Converts a datetime object to an ISO format string.
|
|
39
|
+
|
|
40
|
+
:param dt: The datetime object to convert.
|
|
41
|
+
:returns: ISO format string representation.
|
|
42
|
+
"""
|
|
43
|
+
if dt is None:
|
|
44
|
+
return ""
|
|
45
|
+
return dt.isoformat()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _dict_to_xml_element(data: dict, tag_name: str) -> ET.Element:
|
|
49
|
+
"""
|
|
50
|
+
Converts a dictionary to an XML element recursively.
|
|
51
|
+
|
|
52
|
+
:param data: The dictionary to convert.
|
|
53
|
+
:param tag_name: The tag name for the root element.
|
|
54
|
+
:returns: An XML Element representing the dictionary.
|
|
55
|
+
"""
|
|
56
|
+
element = ET.Element(tag_name)
|
|
57
|
+
|
|
58
|
+
for key, value in data.items():
|
|
59
|
+
child = ET.SubElement(element, str(key))
|
|
60
|
+
if isinstance(value, dict):
|
|
61
|
+
# Recursively convert nested dictionaries
|
|
62
|
+
for sub_key, sub_value in value.items():
|
|
63
|
+
sub_child = ET.SubElement(child, str(sub_key))
|
|
64
|
+
sub_child.text = _value_to_str(sub_value)
|
|
65
|
+
elif isinstance(value, list):
|
|
66
|
+
# Convert lists to repeated elements
|
|
67
|
+
for item in value:
|
|
68
|
+
if isinstance(item, dict):
|
|
69
|
+
item_elem = _dict_to_xml_element(item, "item")
|
|
70
|
+
child.append(item_elem)
|
|
71
|
+
else:
|
|
72
|
+
item_elem = ET.SubElement(child, "item")
|
|
73
|
+
item_elem.text = _value_to_str(item)
|
|
74
|
+
else:
|
|
75
|
+
child.text = _value_to_str(value)
|
|
76
|
+
|
|
77
|
+
return element
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _value_to_str(value: Any) -> str:
|
|
81
|
+
"""
|
|
82
|
+
Converts a value to a string representation for XML.
|
|
83
|
+
|
|
84
|
+
:param value: The value to convert.
|
|
85
|
+
:returns: String representation of the value.
|
|
86
|
+
"""
|
|
87
|
+
if value is None:
|
|
88
|
+
return ""
|
|
89
|
+
elif isinstance(value, datetime):
|
|
90
|
+
return value.isoformat()
|
|
91
|
+
elif isinstance(value, bool):
|
|
92
|
+
return str(value).lower()
|
|
93
|
+
else:
|
|
94
|
+
return str(value)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _prettify_xml(element: ET.Element) -> str:
|
|
98
|
+
"""
|
|
99
|
+
Returns a pretty-printed XML string for the Element.
|
|
100
|
+
|
|
101
|
+
:param element: The XML element to prettify.
|
|
102
|
+
:returns: A formatted XML string with proper indentation.
|
|
103
|
+
"""
|
|
104
|
+
rough_string = ET.tostring(element, encoding='unicode')
|
|
105
|
+
reparsed = minidom.parseString(rough_string)
|
|
106
|
+
return reparsed.toprettyxml(indent=" ")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class XmlResultRecorder(ResultRecorder):
|
|
110
|
+
"""
|
|
111
|
+
Records test results in XML format.
|
|
112
|
+
|
|
113
|
+
The :class:`XmlResultRecorder` is a concrete implementation of
|
|
114
|
+
:class:`ResultRecorder` that writes test results to XML files. It produces
|
|
115
|
+
three main output files:
|
|
116
|
+
|
|
117
|
+
1. **Summary File** (testsummary.xml): Contains run metadata, timing, and
|
|
118
|
+
result counts in XML format.
|
|
119
|
+
|
|
120
|
+
2. **Stream Results File** (testresults_stream.xml): Contains individual
|
|
121
|
+
result records. Records are written as tests execute, enabling real-time
|
|
122
|
+
monitoring.
|
|
123
|
+
|
|
124
|
+
3. **Consolidated Results File** (testresults.xml): Contains the complete
|
|
125
|
+
result tree in a single XML document.
|
|
126
|
+
|
|
127
|
+
Context Manager Lifecycle
|
|
128
|
+
-------------------------
|
|
129
|
+
The XmlResultRecorder inherits the context manager pattern from ResultRecorder:
|
|
130
|
+
|
|
131
|
+
1. **Entry (__enter__)**: Initializes output environment, writes initial
|
|
132
|
+
summary, opens stream file
|
|
133
|
+
2. **Active Recording**: preview() and record() write to stream file
|
|
134
|
+
3. **Exit (__exit__)**: Finalizes counts, writes final summary, closes files
|
|
135
|
+
|
|
136
|
+
Thread Safety
|
|
137
|
+
-------------
|
|
138
|
+
The XmlResultRecorder is thread-safe for concurrent recording:
|
|
139
|
+
|
|
140
|
+
- The record() method uses locking when updating result counters
|
|
141
|
+
- Multiple threads can call record() concurrently without data corruption
|
|
142
|
+
- The stream file writes are serialized through the lock
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
def __init__(self, *, runid: str, start: datetime, render_info: RenderInfo,
|
|
146
|
+
apod: Optional[str] = None, build_info: Optional[BuildInfo] = None,
|
|
147
|
+
pipeline_info: Optional[PipelineInfo] = None, job_info: Optional[JobInfo] = None):
|
|
148
|
+
"""
|
|
149
|
+
Initializes the :class:`XmlResultRecorder` for recording test results.
|
|
150
|
+
|
|
151
|
+
:param runid: The uuid string that identifies a set of test results.
|
|
152
|
+
:param start: The date and time of the start of the test run.
|
|
153
|
+
:param render_info: A :class:`RenderInfo` instance containing output file paths.
|
|
154
|
+
:param apod: Optional name of an automation pod.
|
|
155
|
+
:param build_info: Optional :class:`BuildInfo` instance.
|
|
156
|
+
:param pipeline_info: Optional :class:`PipelineInfo` instance.
|
|
157
|
+
:param job_info: Optional :class:`JobInfo` instance.
|
|
158
|
+
|
|
159
|
+
:returns: None
|
|
160
|
+
"""
|
|
161
|
+
super(XmlResultRecorder, self).__init__(runid=runid, start=start, render_info=render_info, apod=apod,
|
|
162
|
+
build_info=build_info, pipeline_info=pipeline_info, job_info=job_info)
|
|
163
|
+
return
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def preview(self, result: ResultNode):
|
|
167
|
+
"""
|
|
168
|
+
Writes a preview of a result to the stream file in XML format.
|
|
169
|
+
|
|
170
|
+
This method serializes the result as an XML preview (without detail section)
|
|
171
|
+
and writes it to the stream results file. The preview is preceded by an
|
|
172
|
+
ASCII record separator character.
|
|
173
|
+
|
|
174
|
+
:param result: A :class:`ResultNode` object to preview.
|
|
175
|
+
|
|
176
|
+
:returns: None
|
|
177
|
+
"""
|
|
178
|
+
result_dict = result.as_dict(is_preview=True)
|
|
179
|
+
xml_element = _dict_to_xml_element(result_dict, "result")
|
|
180
|
+
xml_str = _prettify_xml(xml_element)
|
|
181
|
+
|
|
182
|
+
self._rout.write(CHAR_RECORD_SEPERATOR)
|
|
183
|
+
self._rout.write(xml_str)
|
|
184
|
+
self._rout.flush()
|
|
185
|
+
|
|
186
|
+
self.catalog_output_directory()
|
|
187
|
+
|
|
188
|
+
return
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def record(self, result: ResultNode):
|
|
192
|
+
"""
|
|
193
|
+
Records a final result entry to the stream file in XML format.
|
|
194
|
+
|
|
195
|
+
This method serializes the complete result (with detail section) and
|
|
196
|
+
writes it to the stream results file. Result counters are updated based
|
|
197
|
+
on the result type and code.
|
|
198
|
+
|
|
199
|
+
Thread Safety:
|
|
200
|
+
This method is thread-safe. Counter updates are performed within
|
|
201
|
+
a lock-protected section.
|
|
202
|
+
|
|
203
|
+
:param result: A :class:`ResultNode` object to record.
|
|
204
|
+
|
|
205
|
+
:returns: None
|
|
206
|
+
"""
|
|
207
|
+
result_dict = result.as_dict(is_preview=False)
|
|
208
|
+
xml_element = _dict_to_xml_element(result_dict, "result")
|
|
209
|
+
xml_str = _prettify_xml(xml_element)
|
|
210
|
+
|
|
211
|
+
self._rout.write(CHAR_RECORD_SEPERATOR)
|
|
212
|
+
self._rout.write(xml_str)
|
|
213
|
+
self._rout.flush()
|
|
214
|
+
|
|
215
|
+
self._lock.acquire()
|
|
216
|
+
try:
|
|
217
|
+
if result.result_type == ResultType.TEST:
|
|
218
|
+
self._total_count += 1
|
|
219
|
+
|
|
220
|
+
result_code = result.result_code
|
|
221
|
+
if result_code == ResultCode.PASSED:
|
|
222
|
+
self._pass_count += 1
|
|
223
|
+
elif result_code == ResultCode.ERRORED:
|
|
224
|
+
self._error_count += 1
|
|
225
|
+
elif result_code == ResultCode.FAILED:
|
|
226
|
+
self._failure_count += 1
|
|
227
|
+
elif result_code == ResultCode.SKIPPED:
|
|
228
|
+
self._skip_count += 1
|
|
229
|
+
else:
|
|
230
|
+
self._unknown_count += 1
|
|
231
|
+
finally:
|
|
232
|
+
self._lock.release()
|
|
233
|
+
|
|
234
|
+
self.catalog_output_directory()
|
|
235
|
+
|
|
236
|
+
return
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def update_summary(self):
|
|
240
|
+
"""
|
|
241
|
+
Writes the current summary state to the summary XML file.
|
|
242
|
+
|
|
243
|
+
This method serializes the internal summary dictionary to XML and
|
|
244
|
+
writes it to the configured summary_filename.
|
|
245
|
+
|
|
246
|
+
:returns: None
|
|
247
|
+
|
|
248
|
+
:raises: ResultRecordingError if the summary file cannot be written.
|
|
249
|
+
"""
|
|
250
|
+
summary_filename = self._render_info.summary_filename
|
|
251
|
+
|
|
252
|
+
try:
|
|
253
|
+
xml_element = _dict_to_xml_element(self._summary, "summary")
|
|
254
|
+
xml_str = _prettify_xml(xml_element)
|
|
255
|
+
|
|
256
|
+
with open(summary_filename, 'w') as sout:
|
|
257
|
+
sout.write(xml_str)
|
|
258
|
+
except OSError as err:
|
|
259
|
+
errmsg = f"Failed to write summary to '{summary_filename}'."
|
|
260
|
+
raise ResultRecordingError(
|
|
261
|
+
errmsg,
|
|
262
|
+
file_path=summary_filename,
|
|
263
|
+
operation="writing summary XML",
|
|
264
|
+
original_error=err
|
|
265
|
+
) from err
|
|
266
|
+
|
|
267
|
+
self.catalog_output_directory()
|
|
268
|
+
|
|
269
|
+
return
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def write_consolidated_results(self, root_node: dict):
|
|
273
|
+
"""
|
|
274
|
+
Writes the consolidated results tree to the consolidated results XML file.
|
|
275
|
+
|
|
276
|
+
This method serializes the complete result tree to XML and writes it
|
|
277
|
+
to the configured consolidated_results_filename.
|
|
278
|
+
|
|
279
|
+
:param root_node: A dictionary representing the root of the consolidated
|
|
280
|
+
result tree.
|
|
281
|
+
|
|
282
|
+
:returns: None
|
|
283
|
+
|
|
284
|
+
:raises: ResultRecordingError if the consolidated results file cannot be written.
|
|
285
|
+
"""
|
|
286
|
+
consolidated_filename = self._render_info.consolidated_results_filename
|
|
287
|
+
|
|
288
|
+
try:
|
|
289
|
+
xml_element = _dict_to_xml_element(root_node, "testresults")
|
|
290
|
+
xml_str = _prettify_xml(xml_element)
|
|
291
|
+
|
|
292
|
+
with open(consolidated_filename, 'w+') as rout:
|
|
293
|
+
rout.write(xml_str)
|
|
294
|
+
except OSError as err:
|
|
295
|
+
errmsg = f"Failed to write consolidated results to '{consolidated_filename}'."
|
|
296
|
+
raise ResultRecordingError(
|
|
297
|
+
errmsg,
|
|
298
|
+
file_path=consolidated_filename,
|
|
299
|
+
operation="writing consolidated results XML",
|
|
300
|
+
original_error=err
|
|
301
|
+
) from err
|
|
302
|
+
|
|
303
|
+
self.catalog_output_directory(force=True)
|
|
304
|
+
|
|
305
|
+
return
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.results.utilities
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for utilities.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
__author__ = "Myron Walker"
|
|
12
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
13
|
+
__credits__ = []
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from typing import List
|
|
17
|
+
|
|
18
|
+
import os
|
|
19
|
+
import json
|
|
20
|
+
|
|
21
|
+
DEFAULT_DO_NOT_CATALOG_DIRS = [
|
|
22
|
+
"__pycache__"
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
DEFAULT_DO_NOT_DESCEND_DIRS = [
|
|
26
|
+
"diagnostics"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
def catalog_tree(rootdir: str, dont_catalog_dirs: List[str] = DEFAULT_DO_NOT_CATALOG_DIRS,
|
|
30
|
+
dont_descend_dirs: List[str] = DEFAULT_DO_NOT_DESCEND_DIRS):
|
|
31
|
+
"""
|
|
32
|
+
Adds json catalog files to a file system tree to help provide directory
|
|
33
|
+
services to javascript in html files.
|
|
34
|
+
|
|
35
|
+
CATALOG TREE TRAVERSAL ALGORITHM:
|
|
36
|
+
=================================
|
|
37
|
+
This function implements a depth-first recursive traversal of a directory tree,
|
|
38
|
+
creating catalog.json files at each level to enable HTML report navigation.
|
|
39
|
+
|
|
40
|
+
Algorithm Overview:
|
|
41
|
+
1. List all entries in the current directory
|
|
42
|
+
2. Classify each entry as file or directory
|
|
43
|
+
3. For directories: optionally include in catalog and optionally recurse
|
|
44
|
+
4. Write catalog.json with files and folders arrays
|
|
45
|
+
5. Recurse into child directories (depth-first)
|
|
46
|
+
|
|
47
|
+
Filtering Rules:
|
|
48
|
+
- dont_catalog_dirs: Directories to exclude from the "folders" array
|
|
49
|
+
(e.g., __pycache__) but still descend into for recursive processing
|
|
50
|
+
- dont_descend_dirs: Directories to not recurse into (e.g., diagnostics)
|
|
51
|
+
These may still appear in the catalog if not in dont_catalog_dirs
|
|
52
|
+
|
|
53
|
+
Output Format:
|
|
54
|
+
Each catalog.json contains:
|
|
55
|
+
{
|
|
56
|
+
"files": ["file1.txt", "file2.json", ...],
|
|
57
|
+
"folders": ["subdir1", "subdir2", ...]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:param rootdir: The root directory to start cataloging from.
|
|
61
|
+
:param dont_catalog_dirs: List of directory names to exclude from folder listings.
|
|
62
|
+
:param dont_descend_dirs: List of directory names to not recurse into.
|
|
63
|
+
|
|
64
|
+
:returns: None
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
# STEP 1: LIST AND SORT DIRECTORY CONTENTS
|
|
68
|
+
# ----------------------------------------
|
|
69
|
+
# Get all entries in the current directory and sort them alphabetically.
|
|
70
|
+
# Sorting ensures consistent catalog output across runs, which is important
|
|
71
|
+
# for reproducibility and makes diffs easier to read.
|
|
72
|
+
directory_items = [item for item in os.listdir(rootdir)]
|
|
73
|
+
directory_items.sort()
|
|
74
|
+
|
|
75
|
+
# STEP 2: INITIALIZE CLASSIFICATION LISTS
|
|
76
|
+
# ---------------------------------------
|
|
77
|
+
# Separate lists for files and directories. These will be written to catalog.json.
|
|
78
|
+
dirnames = []
|
|
79
|
+
filenames = []
|
|
80
|
+
|
|
81
|
+
# STEP 3: CLASSIFY EACH DIRECTORY ENTRY
|
|
82
|
+
# -------------------------------------
|
|
83
|
+
# Iterate through all entries and classify them as files or directories.
|
|
84
|
+
# Apply filtering rules for directories.
|
|
85
|
+
for dentry in directory_items:
|
|
86
|
+
|
|
87
|
+
# Skip special directory entries (current and parent directory references)
|
|
88
|
+
if dentry == "." or dentry == "..":
|
|
89
|
+
continue
|
|
90
|
+
|
|
91
|
+
dentry_full = os.path.join(rootdir, dentry)
|
|
92
|
+
|
|
93
|
+
if os.path.isfile(dentry_full):
|
|
94
|
+
# CASE: Regular file - add to files list unconditionally
|
|
95
|
+
filenames.append(dentry)
|
|
96
|
+
elif os.path.isdir(dentry_full):
|
|
97
|
+
# CASE: Directory - apply filtering rules
|
|
98
|
+
|
|
99
|
+
# CATALOG INCLUSION CHECK:
|
|
100
|
+
# Only add to dirnames if not in the exclusion list.
|
|
101
|
+
# This controls what appears in the "folders" array of catalog.json.
|
|
102
|
+
# Example: __pycache__ is excluded from listings but may still be traversed.
|
|
103
|
+
if dentry not in dont_catalog_dirs:
|
|
104
|
+
dirnames.append(dentry)
|
|
105
|
+
|
|
106
|
+
# RECURSION CHECK:
|
|
107
|
+
# Only recurse into directories that are:
|
|
108
|
+
# 1. Not in the dont_descend_dirs list (e.g., diagnostics)
|
|
109
|
+
# 2. Not symbolic links (to prevent infinite loops and unexpected behavior)
|
|
110
|
+
# This is a depth-first traversal - we recurse before writing the catalog.
|
|
111
|
+
if dentry not in dont_descend_dirs:
|
|
112
|
+
if not os.path.islink(dentry_full):
|
|
113
|
+
catalog_tree(dentry_full, dont_catalog_dirs, dont_descend_dirs)
|
|
114
|
+
|
|
115
|
+
# STEP 4: WRITE CATALOG FILE
|
|
116
|
+
# --------------------------
|
|
117
|
+
# Write the catalog.json file AFTER recursing into subdirectories.
|
|
118
|
+
# This ensures child catalogs exist before the parent catalog is written,
|
|
119
|
+
# though the order doesn't affect functionality since each catalog is independent.
|
|
120
|
+
catalog = {
|
|
121
|
+
"files": filenames,
|
|
122
|
+
"folders": dirnames
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
catalogfile = os.path.join(rootdir, "catalog.json")
|
|
126
|
+
|
|
127
|
+
content = json.dumps(catalog, indent=4)
|
|
128
|
+
try:
|
|
129
|
+
with open(catalogfile, 'r') as cf:
|
|
130
|
+
if cf.read() == content:
|
|
131
|
+
return
|
|
132
|
+
except OSError:
|
|
133
|
+
# No readable existing catalog (usually it does not exist yet); the
|
|
134
|
+
# unchanged-content check is only an optimization, so write it below.
|
|
135
|
+
pass
|
|
136
|
+
|
|
137
|
+
with open(catalogfile, 'w') as cf:
|
|
138
|
+
cf.write(content)
|
|
139
|
+
|
|
140
|
+
return
|
|
141
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.sequencing
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for sequencing.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = "Myron Walker"
|
|
10
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
11
|
+
__credits__ = []
|
|
12
|
+
|
|
13
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.sequencing.sequencermodulescope
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for sequencermodulescope.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
__author__ = "Myron Walker"
|
|
12
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
13
|
+
__credits__ = []
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from typing import Type, TYPE_CHECKING
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
import os
|
|
20
|
+
|
|
21
|
+
from types import TracebackType
|
|
22
|
+
|
|
23
|
+
from ccai.errors.xtraceback import create_traceback_detail, format_traceback_detail
|
|
24
|
+
from ccai.errors.exceptions import SkipError
|
|
25
|
+
|
|
26
|
+
from ccai.xmodules.xlogging.enhancedloggers import getEnhancedLogger
|
|
27
|
+
|
|
28
|
+
from ccai.testbase.results.recorders.resultrecorder import ResultRecorder
|
|
29
|
+
from ccai.testbase.sequencing.sequencerscopebase import SequencerScopeBase
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
logger = getEnhancedLogger()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if TYPE_CHECKING:
|
|
36
|
+
from ccai.testbase.sequencing.testsequencer import TestSequencer
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class SequencerModuleScope(SequencerScopeBase):
|
|
40
|
+
"""
|
|
41
|
+
Context manager that manages the lifetime of a module level scope.
|
|
42
|
+
"""
|
|
43
|
+
def __init__(self, sequencer: "TestSequencer", recorder: ResultRecorder, scope_name: str, **kwargs):
|
|
44
|
+
super().__init__(sequencer, recorder)
|
|
45
|
+
|
|
46
|
+
self._scope_name = scope_name
|
|
47
|
+
self._scope_args = kwargs
|
|
48
|
+
self._scope_id = None
|
|
49
|
+
self._parent_scope_id = None
|
|
50
|
+
self._scope_node = self._sequencer.find_treenode_for_scope(scope_name)
|
|
51
|
+
return
|
|
52
|
+
|
|
53
|
+
def __enter__(self):
|
|
54
|
+
self._parent_scope_id, self._scope_id = self._sequencer.scope_id_create(self._scope_name)
|
|
55
|
+
try:
|
|
56
|
+
result = self._sequencer.create_test_result_container(self._scope_id, self._scope_name, parent_inst=self._parent_scope_id)
|
|
57
|
+
self._recorder.record(result)
|
|
58
|
+
except BaseException:
|
|
59
|
+
# If __enter__ raises, Python never calls __exit__, so the scope
|
|
60
|
+
# id pushed above would be left on the stack and every outer
|
|
61
|
+
# scope's pop would fail its name check, burying the real error.
|
|
62
|
+
# Pop what we pushed and let the true failure surface.
|
|
63
|
+
self._sequencer.scope_id_pop(self._scope_name)
|
|
64
|
+
raise
|
|
65
|
+
logger.info("MODULE ENTER: {}, {}".format(self._scope_name, self._scope_id))
|
|
66
|
+
return self
|
|
67
|
+
|
|
68
|
+
def __exit__(self, ex_type: Type, ex_inst: BaseException, ex_tb: TracebackType) -> bool:
|
|
69
|
+
handled = False
|
|
70
|
+
|
|
71
|
+
if ex_type is not None:
|
|
72
|
+
|
|
73
|
+
if issubclass(ex_type, SkipError):
|
|
74
|
+
self._mark_descendants_skipped(self._scope_node, self._scope_id, ex_inst.reason, ex_inst.bug)
|
|
75
|
+
else:
|
|
76
|
+
tb_detail = create_traceback_detail(ex_inst)
|
|
77
|
+
self._mark_descendants_as_error(self._scope_node, self._scope_id, tb_detail)
|
|
78
|
+
|
|
79
|
+
# If an exceptions was thrown in this context, it means
|
|
80
|
+
# that the exception occured during the setup for this
|
|
81
|
+
# module, this means we need to mark all descendant tests
|
|
82
|
+
# as error'd due to a setup failure.
|
|
83
|
+
errmsg_lines = [
|
|
84
|
+
"Exception raises setting up scope='{}'".format(self._scope_name)
|
|
85
|
+
]
|
|
86
|
+
errmsg_lines.extend(format_traceback_detail(tb_detail))
|
|
87
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
88
|
+
logger.error(errmsg)
|
|
89
|
+
|
|
90
|
+
handled = True
|
|
91
|
+
|
|
92
|
+
self._scope_node.finalize()
|
|
93
|
+
self._sequencer.scope_id_pop(self._scope_name)
|
|
94
|
+
logger.info("MODULE EXIT: {}, {}".format(self._scope_name, self._scope_id))
|
|
95
|
+
|
|
96
|
+
return handled
|