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,54 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.testgroup
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for testgroup.
|
|
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
|
+
|
|
17
|
+
from ccai.xmodules.xlogging.enhancedloggers import getEnhancedLogger
|
|
18
|
+
|
|
19
|
+
from ccai.testbase.testref import TestRef
|
|
20
|
+
from ccai.testbase.injection.injectiongroup import InjectionGroup
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
logger = getEnhancedLogger()
|
|
24
|
+
|
|
25
|
+
class TestGroup(InjectionGroup):
|
|
26
|
+
"""
|
|
27
|
+
-------------
|
|
28
|
+
| Group A |
|
|
29
|
+
---------------------------
|
|
30
|
+
| Group AA | Scope AB |
|
|
31
|
+
-------------------------------
|
|
32
|
+
| Scope AAA/ABA |
|
|
33
|
+
-------------------------------
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(self, name, package=None):
|
|
37
|
+
"""
|
|
38
|
+
Initializes the :class:`TestGroup` with the specified name and
|
|
39
|
+
optional package.
|
|
40
|
+
|
|
41
|
+
:param name: The name of the group being created.
|
|
42
|
+
:param package: Optional package name associated with the group.
|
|
43
|
+
"""
|
|
44
|
+
super().__init__(name, package=package)
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
def add_descendent(self, test_ref: TestRef):
|
|
48
|
+
"""
|
|
49
|
+
Adds a :class:`TestRef` instance as a descendent of this group.
|
|
50
|
+
|
|
51
|
+
:param test_ref: The :class:`TestRef` to add.
|
|
52
|
+
"""
|
|
53
|
+
super().add_descendent(test_ref)
|
|
54
|
+
return
|
ccai/testbase/testjob.py
ADDED
|
@@ -0,0 +1,600 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.testjob
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for testjob.
|
|
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
|
+
|
|
17
|
+
from typing import List, Optional
|
|
18
|
+
from datetime import datetime
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
import threading
|
|
22
|
+
import traceback
|
|
23
|
+
|
|
24
|
+
from ccai.xmodules.xformatting import CommandOutputFormat
|
|
25
|
+
from ccai.xmodules.debugging import debugger_wellknown_breakpoint_entry
|
|
26
|
+
from ccai.xmodules.xlogging.enhancedloggers import EnhancedLogger
|
|
27
|
+
|
|
28
|
+
from ccai.testbase import environment
|
|
29
|
+
from ccai.testbase.output.outputcontext import IOutputContext, SimpleOutputContext
|
|
30
|
+
from ccai.testbase.output.runmetadata import IRunMetadata, StandaloneRunMetadata
|
|
31
|
+
|
|
32
|
+
from ccai.testbase.breakpoints import WELLKNOWN_BREAKPOINTS
|
|
33
|
+
from ccai.testbase.results.model.buildinfo import BuildInfo
|
|
34
|
+
from ccai.testbase.results.model.jobinfo import JobInfo
|
|
35
|
+
from ccai.testbase.results.model.pipelineinfo import PipelineInfo
|
|
36
|
+
from ccai.testbase.results.model.renderinfo import RenderInfo
|
|
37
|
+
|
|
38
|
+
from ccai.testbase.results.recorders.resultrecorder import ResultRecorder
|
|
39
|
+
from ccai.testbase.results.recorders.stdoutresultrecorder import StdoutResultRecorder
|
|
40
|
+
|
|
41
|
+
from ccai.testbase.sequencing.testsequencer import TestSequencer
|
|
42
|
+
from ccai.testbase.errors.testruntimeouterror import TestRunTimeoutError
|
|
43
|
+
from ccai.interfaces.itestjob import ITestJob
|
|
44
|
+
|
|
45
|
+
class TestJob(ITestJob):
|
|
46
|
+
"""
|
|
47
|
+
The :class:`TestJob` spans the execution of all :class:`TestPack` and organizes the
|
|
48
|
+
flow of execution of test packs. It allows for the sequencing of the execution of test
|
|
49
|
+
packs so as to optimize the time test runs spend performing setup and tearnown tasks. This
|
|
50
|
+
allows for the optimization of infrastructure resources.
|
|
51
|
+
|
|
52
|
+
* Single Instance
|
|
53
|
+
* Setup Test Landscape
|
|
54
|
+
* Jobs have an expected number of tests based
|
|
55
|
+
* Collects and organizes results from all the :class:`TestPack` runs
|
|
56
|
+
|
|
57
|
+
* Can be used to customize the sequencing of :class:`TestPack` runs.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
name = "" # Friendly name for the test job
|
|
61
|
+
description = "" # Description of the job
|
|
62
|
+
owner = "" # The owning individual or team
|
|
63
|
+
|
|
64
|
+
includes = None # The test packs or tests that are included in this TestJob
|
|
65
|
+
excludes = None # The tests that are to be excluded from this TestJob
|
|
66
|
+
metafilters = None
|
|
67
|
+
|
|
68
|
+
def __init__(self, logger: EnhancedLogger, testroot: str, includes: Optional[List[str]]=None, excludes: Optional[List[str]]=None,
|
|
69
|
+
metafilters: Optional[List[str]]=None, test_module: Optional[str]=None, parser=None):
|
|
70
|
+
"""
|
|
71
|
+
Constructor for a :class:`TestJob`. It initializes the member variables based on the parameters passed
|
|
72
|
+
from the entry point function and the class member data declared on :class:`TestJob` derived classes.
|
|
73
|
+
"""
|
|
74
|
+
self._logger = logger
|
|
75
|
+
self._testroot = testroot
|
|
76
|
+
|
|
77
|
+
if self.includes is None:
|
|
78
|
+
self.includes = includes
|
|
79
|
+
self.excludes = excludes
|
|
80
|
+
|
|
81
|
+
self.metafilters = metafilters
|
|
82
|
+
|
|
83
|
+
self._test_module = test_module
|
|
84
|
+
self._parser = parser
|
|
85
|
+
self._starttime = None
|
|
86
|
+
|
|
87
|
+
self._test_results_dir = None
|
|
88
|
+
self._stream_result_filename = None
|
|
89
|
+
self._summary_filename = None
|
|
90
|
+
self._summary_template = None
|
|
91
|
+
self._import_errors_filename = None
|
|
92
|
+
|
|
93
|
+
self._testpacks = None
|
|
94
|
+
|
|
95
|
+
self._run_metadata = self._create_run_metadata()
|
|
96
|
+
self._output_context = self._create_output_context()
|
|
97
|
+
|
|
98
|
+
self._apod = self._run_metadata.apod
|
|
99
|
+
self._run_id = self._run_metadata.run_id
|
|
100
|
+
|
|
101
|
+
self._import_errors = []
|
|
102
|
+
|
|
103
|
+
self._testrun_timeout = self._run_metadata.testrun_timeout
|
|
104
|
+
|
|
105
|
+
self._title = self._run_metadata.title
|
|
106
|
+
|
|
107
|
+
return
|
|
108
|
+
|
|
109
|
+
def __enter__(self):
|
|
110
|
+
self.begin()
|
|
111
|
+
return self
|
|
112
|
+
|
|
113
|
+
def __exit__(self, ex_type, ex_inst, ex_tb):
|
|
114
|
+
self.finalize()
|
|
115
|
+
return False
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def import_errors(self):
|
|
119
|
+
return self._import_errors
|
|
120
|
+
|
|
121
|
+
@property
|
|
122
|
+
def job_seed(self) -> str:
|
|
123
|
+
"""
|
|
124
|
+
Returns the job-level seed for reproducible property testing.
|
|
125
|
+
|
|
126
|
+
The seed is a string (typically a UUID) read from ``AM_JOB_SEED``.
|
|
127
|
+
If no seed was set, a random UUID is generated on first access
|
|
128
|
+
and cached for the duration of the job.
|
|
129
|
+
|
|
130
|
+
:returns: A string seed value (UUID).
|
|
131
|
+
"""
|
|
132
|
+
seed = self._run_metadata.job_seed
|
|
133
|
+
return seed
|
|
134
|
+
|
|
135
|
+
def begin(self):
|
|
136
|
+
"""
|
|
137
|
+
Called at the beginning of a test job in order to setup the recording of test results.
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
self._starttime = self._run_metadata.starttime
|
|
141
|
+
|
|
142
|
+
self._test_results_dir = self._output_context.get_test_results_dir()
|
|
143
|
+
|
|
144
|
+
# Dump out a flattened copy of the runtime file to the test output folder so we have a copy
|
|
145
|
+
# of the inputs to the automation run.
|
|
146
|
+
self._runtime_archive = os.path.join(self._test_results_dir, "runtime-declared.yaml")
|
|
147
|
+
|
|
148
|
+
self._stream_result_filename = os.path.join(self._test_results_dir, "testrun_results_stream.jsos")
|
|
149
|
+
self._consolidated_result_filename = os.path.join(self._test_results_dir, "testrun_results.json")
|
|
150
|
+
self._summary_filename = os.path.join(self._test_results_dir, "testrun_summary.json")
|
|
151
|
+
self._summary_template = self._output_context.get_summary_template_source()
|
|
152
|
+
self._import_errors_filename = os.path.join(self._test_results_dir, "import_errors.jsos")
|
|
153
|
+
self._testrun_sequence_filename = os.path.join(self._test_results_dir, "testrun_sequence.py")
|
|
154
|
+
|
|
155
|
+
return
|
|
156
|
+
|
|
157
|
+
def execute(self) -> int:
|
|
158
|
+
"""
|
|
159
|
+
Runs the tests that are included in the given :class:'TestPack'.
|
|
160
|
+
"""
|
|
161
|
+
result_code = 0
|
|
162
|
+
|
|
163
|
+
with self._create_sequencer() as tseq:
|
|
164
|
+
# IMPORTANT: The ordering of the automation sequence is extremely important. Proper
|
|
165
|
+
# ordering of these steps ensures that the correct things are happening in the correct
|
|
166
|
+
# order in the automation code and that we provide the ability for configuration
|
|
167
|
+
# issues to be discovered as early as possible.
|
|
168
|
+
|
|
169
|
+
debugger_name = environment.get_debugger_name()
|
|
170
|
+
configured_breakpoints = environment.get_debug_breakpoints()
|
|
171
|
+
if debugger_name is not None and configured_breakpoints is not None:
|
|
172
|
+
debugger_wellknown_breakpoint_entry(debugger_name, WELLKNOWN_BREAKPOINTS.TEST_DISCOVERY, configured_breakpoints)
|
|
173
|
+
|
|
174
|
+
# STEP 1: We discover the tests first so we can build a listing of the
|
|
175
|
+
# Integration and Scope couplings. We don't want to execute any test code, setup,
|
|
176
|
+
# or teardown code at this point. We want to seperate out the integration
|
|
177
|
+
# code from the test code and run the integration code first so we can discover
|
|
178
|
+
# integration issues independant of the test code itself.
|
|
179
|
+
self._logger.section("Discovery")
|
|
180
|
+
count = tseq.discover(test_module=self._test_module)
|
|
181
|
+
|
|
182
|
+
# STEP 2: Tell the sequencer to record any import errors that happened during discovery
|
|
183
|
+
# of tests. If a test file or dependent file failed to import then the test
|
|
184
|
+
# will just not be included in a run and this is a type of invisible error
|
|
185
|
+
# that we must plan for and highlight.
|
|
186
|
+
self._import_errors.extend(tseq.import_errors)
|
|
187
|
+
tseq.record_import_errors(self._import_errors_filename)
|
|
188
|
+
|
|
189
|
+
if count > 0:
|
|
190
|
+
|
|
191
|
+
self._logger.section("Integration Publishing")
|
|
192
|
+
|
|
193
|
+
# STEP 1: Call attach_to_framework on the sequencer to give all the couplings a chance
|
|
194
|
+
# to plug themselves into the automation framework. This allows us to only integrate
|
|
195
|
+
# couplings that are being consumed by the tests AND also to only include couplings that
|
|
196
|
+
# are included in the test framework. This give the opportunity for the couplings to trigger
|
|
197
|
+
# the startup of the coordinators that inter-operate with the test landscape and the
|
|
198
|
+
# associated devices.
|
|
199
|
+
self.fire_attach_to_framework(tseq)
|
|
200
|
+
|
|
201
|
+
# STEP 2: Now that we have collected all the couplings and have a preview of
|
|
202
|
+
# the complexity of the automation run encoded into the coupling types collected.
|
|
203
|
+
# Allow the couplings to attach to the automation environment so they can get
|
|
204
|
+
# a preview of the parameters and configuration and provide us with an early
|
|
205
|
+
# indicator of any parameter or configuration issues.
|
|
206
|
+
#
|
|
207
|
+
# This is the final step of validating all the input information to the run and
|
|
208
|
+
# we are able to perform this step in the context of the integration code and
|
|
209
|
+
# outside of the execution of any test code
|
|
210
|
+
self.fire_attach_to_environment(tseq)
|
|
211
|
+
|
|
212
|
+
# STEP 8: Capture pre-run diagnostics
|
|
213
|
+
# This captures the initial state of the test environment before test execution
|
|
214
|
+
# begins, useful for understanding the starting conditions.
|
|
215
|
+
try:
|
|
216
|
+
from ccai.testbase.diagnostic_level import get_diagnostic_level
|
|
217
|
+
self.fire_diagnostic_capture_pre_testrun(tseq, level=get_diagnostic_level())
|
|
218
|
+
except Exception:
|
|
219
|
+
# Log the error with full traceback but do not re-raise
|
|
220
|
+
# This ensures the test run continues even if diagnostic capture fails
|
|
221
|
+
err_msg = traceback.format_exc()
|
|
222
|
+
self._logger.error(err_msg)
|
|
223
|
+
|
|
224
|
+
self._logger.section("Expanding Test Tree Based on Query")
|
|
225
|
+
tseq.expand_test_tree_based_on_query()
|
|
226
|
+
|
|
227
|
+
self._logger.section("Generating Test Run Sequence")
|
|
228
|
+
# STEP 10: Generate the test run sequence document that will be used or the run.
|
|
229
|
+
tseq.generate_testrun_sequence_document(self._testrun_sequence_filename)
|
|
230
|
+
|
|
231
|
+
title = self.name
|
|
232
|
+
runid = self._run_id
|
|
233
|
+
start = self._starttime
|
|
234
|
+
|
|
235
|
+
static_resource_source = self._output_context.get_static_resource_source()
|
|
236
|
+
static_resource_destination = self._output_context.get_static_resource_destination()
|
|
237
|
+
|
|
238
|
+
render_info = RenderInfo(title=title, summary_filename=self._summary_filename, summary_template=self._summary_template,
|
|
239
|
+
stream_results_filename=self._stream_result_filename, consolidated_results_filename=self._consolidated_result_filename, static_resource_source=static_resource_source,
|
|
240
|
+
static_resource_destination=static_resource_destination)
|
|
241
|
+
|
|
242
|
+
build_info = self._run_metadata.build_info()
|
|
243
|
+
|
|
244
|
+
pipeline_info = self._run_metadata.pipeline_info()
|
|
245
|
+
|
|
246
|
+
job_info = self._run_metadata.job_info()
|
|
247
|
+
|
|
248
|
+
self._logger.section("Running Tests")
|
|
249
|
+
|
|
250
|
+
# STEP 11: The startup phase is over, up to this point we have mostly been executing
|
|
251
|
+
# integration code and configuration analysis code that is embedded into mostly class
|
|
252
|
+
# level methods.
|
|
253
|
+
#
|
|
254
|
+
# Now we start going through all the test testpacks and tests and start instantiating
|
|
255
|
+
# test scopes and instances and start executing setup, teardown and test level code
|
|
256
|
+
with self._create_recorder(runid=runid, start=start, render_info=render_info,
|
|
257
|
+
build_info=build_info, pipeline_info=pipeline_info, job_info=job_info) as recorder:
|
|
258
|
+
|
|
259
|
+
timeout_timer = None
|
|
260
|
+
|
|
261
|
+
try:
|
|
262
|
+
# Start timeout guard if configured
|
|
263
|
+
if self._testrun_timeout is not None:
|
|
264
|
+
main_thread_id = threading.current_thread().ident
|
|
265
|
+
|
|
266
|
+
def _timeout_handler():
|
|
267
|
+
import ctypes
|
|
268
|
+
ctypes.pythonapi.PyThreadState_SetAsyncExc(
|
|
269
|
+
ctypes.c_ulong(main_thread_id),
|
|
270
|
+
ctypes.py_object(TestRunTimeoutError)
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
timeout_timer = threading.Timer(self._testrun_timeout, _timeout_handler)
|
|
274
|
+
timeout_timer.daemon = True
|
|
275
|
+
timeout_timer.start()
|
|
276
|
+
self._logger.section("Timeout configured: %d seconds" % self._testrun_timeout)
|
|
277
|
+
|
|
278
|
+
# Traverse the execution graph
|
|
279
|
+
tseq.execute_tests(runid, recorder)
|
|
280
|
+
|
|
281
|
+
# ============================================================================
|
|
282
|
+
# ERROR HANDLING STRATEGY - DIAGNOSTIC CAPTURE
|
|
283
|
+
# ============================================================================
|
|
284
|
+
# Diagnostic capture is wrapped in its own try/except block to ensure that
|
|
285
|
+
# diagnostic failures do NOT cause the test run to fail. This is a critical
|
|
286
|
+
# design decision based on the following principles:
|
|
287
|
+
#
|
|
288
|
+
# 1. ISOLATION: Diagnostic capture is a secondary concern - the primary goal
|
|
289
|
+
# is test execution. Diagnostic failures should not impact test results.
|
|
290
|
+
#
|
|
291
|
+
# 2. GRACEFUL DEGRADATION: If diagnostic capture fails, we log the error
|
|
292
|
+
# with full traceback for debugging but continue with finalization.
|
|
293
|
+
#
|
|
294
|
+
# 3. NON-BLOCKING: The test run should complete and report results even if
|
|
295
|
+
# diagnostic capture encounters issues (e.g., disk full, permission errors,
|
|
296
|
+
# integration coupling errors).
|
|
297
|
+
#
|
|
298
|
+
# 4. FULL TRACEBACK: We capture the complete traceback using traceback.format_exc()
|
|
299
|
+
# to provide maximum debugging information for diagnosing capture failures.
|
|
300
|
+
#
|
|
301
|
+
# This pattern ensures that test results are always available, even when
|
|
302
|
+
# diagnostic capture encounters unexpected errors.
|
|
303
|
+
# ============================================================================
|
|
304
|
+
try:
|
|
305
|
+
# STEP 12: Capture a post-testrun diagnostic capture
|
|
306
|
+
# This captures the final state of the test environment after all tests
|
|
307
|
+
# have completed, useful for post-mortem analysis and debugging.
|
|
308
|
+
from ccai.testbase.diagnostic_level import get_diagnostic_level
|
|
309
|
+
self.fire_diagnostic_capture_post_testrun(tseq, level=get_diagnostic_level())
|
|
310
|
+
except Exception:
|
|
311
|
+
# Log the error with full traceback but do not re-raise
|
|
312
|
+
# This ensures the test run continues to finalization
|
|
313
|
+
err_msg = traceback.format_exc()
|
|
314
|
+
self._logger.error(err_msg)
|
|
315
|
+
|
|
316
|
+
except TestRunTimeoutError:
|
|
317
|
+
err_msg = "Test run exceeded the configured timeout of %d seconds. Remaining tests have been marked as errored." % self._testrun_timeout
|
|
318
|
+
self._logger.error(err_msg)
|
|
319
|
+
result_code = -1
|
|
320
|
+
|
|
321
|
+
finally:
|
|
322
|
+
# Cancel timeout timer if it is still active
|
|
323
|
+
if timeout_timer is not None:
|
|
324
|
+
timeout_timer.cancel()
|
|
325
|
+
|
|
326
|
+
recorder.finalize()
|
|
327
|
+
|
|
328
|
+
recorded_sumary = recorder.summary
|
|
329
|
+
if "result" in recorded_sumary:
|
|
330
|
+
if recorded_sumary["result"] != "PASSED":
|
|
331
|
+
result_code = -1
|
|
332
|
+
else:
|
|
333
|
+
self._logger.error("The 'result' field was not found in the recorded summary report.")
|
|
334
|
+
result_code = -1
|
|
335
|
+
|
|
336
|
+
# STEP 13: This is where we do any final processing and or publishing of results.
|
|
337
|
+
# We might also want to add automated bug filing here later.
|
|
338
|
+
self._logger.section("Completed Tests")
|
|
339
|
+
|
|
340
|
+
# Write out the test results
|
|
341
|
+
results_msg_lines = [""]
|
|
342
|
+
results_msg_lines.extend(recorder.format_lines())
|
|
343
|
+
results_msg_lines.append("")
|
|
344
|
+
|
|
345
|
+
results_msg = os.linesep.join(results_msg_lines)
|
|
346
|
+
|
|
347
|
+
self._logger.render(results_msg)
|
|
348
|
+
|
|
349
|
+
else:
|
|
350
|
+
# We didn't find any tests so display a message, and set the return code to
|
|
351
|
+
# indicate an error condition
|
|
352
|
+
err_msg_lines = [
|
|
353
|
+
"The include and exclude parameters specified resulted in an empty test set."
|
|
354
|
+
]
|
|
355
|
+
|
|
356
|
+
if self.includes is not None:
|
|
357
|
+
err_msg_lines.append("INCLUDES:")
|
|
358
|
+
for nxtitem in self.includes:
|
|
359
|
+
err_msg_lines.append(" %s" % nxtitem)
|
|
360
|
+
err_msg_lines.append("")
|
|
361
|
+
else:
|
|
362
|
+
err_msg_lines.append("INCLUDES: None")
|
|
363
|
+
|
|
364
|
+
if self.excludes is not None:
|
|
365
|
+
err_msg_lines.append("EXCLUDES:")
|
|
366
|
+
for nxtitem in self.excludes:
|
|
367
|
+
err_msg_lines.append(" %s" % nxtitem)
|
|
368
|
+
err_msg_lines.append("")
|
|
369
|
+
else:
|
|
370
|
+
err_msg_lines.append("EXCLUDES: None")
|
|
371
|
+
|
|
372
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
373
|
+
self._logger.error(err_msg)
|
|
374
|
+
|
|
375
|
+
result_code = -1
|
|
376
|
+
|
|
377
|
+
return result_code
|
|
378
|
+
|
|
379
|
+
def fire_attach_to_environment(self, tseq: TestSequencer):
|
|
380
|
+
"""
|
|
381
|
+
Goes through all the integrations and provides them with an opportunity to
|
|
382
|
+
attach to the test environment.
|
|
383
|
+
"""
|
|
384
|
+
|
|
385
|
+
tseq.attach_to_environment()
|
|
386
|
+
|
|
387
|
+
return
|
|
388
|
+
|
|
389
|
+
def fire_attach_to_framework(self, tseq: TestSequencer):
|
|
390
|
+
"""
|
|
391
|
+
Goes through all the integrations and provides them with an opportunity to
|
|
392
|
+
attach to the test environment.
|
|
393
|
+
"""
|
|
394
|
+
|
|
395
|
+
tseq.attach_to_framework()
|
|
396
|
+
|
|
397
|
+
return
|
|
398
|
+
|
|
399
|
+
def fire_diagnostic_capture_post_testrun(self, tseq: TestSequencer, level: int=9):
|
|
400
|
+
"""
|
|
401
|
+
Fires the post-run diagnostic capture event, delegating to the TestSequencer.
|
|
402
|
+
|
|
403
|
+
This method is called after test execution completes but before finalization to
|
|
404
|
+
capture diagnostic information about the final state of the test environment.
|
|
405
|
+
It delegates the actual diagnostic capture to the TestSequencer's
|
|
406
|
+
:meth:`diagnostic_capture_post_testrun` method.
|
|
407
|
+
|
|
408
|
+
The diagnostic capture is wrapped in error handling at the call site to ensure
|
|
409
|
+
that diagnostic failures do not cause the test run to fail.
|
|
410
|
+
|
|
411
|
+
:param tseq: The :class:`TestSequencer` instance managing the test execution.
|
|
412
|
+
The sequencer contains the registered integration couplings that will
|
|
413
|
+
perform the actual diagnostic capture.
|
|
414
|
+
:param level: The maximum diagnostic level to capture (1-9). Higher levels
|
|
415
|
+
indicate more detailed diagnostic information. Defaults to 9 (maximum detail).
|
|
416
|
+
|
|
417
|
+
* Levels 1-3: Basic diagnostic information
|
|
418
|
+
* Levels 4-6: Standard diagnostic information
|
|
419
|
+
* Levels 7-9: Detailed diagnostic information
|
|
420
|
+
|
|
421
|
+
:returns: None. Diagnostic files are written by integration couplings.
|
|
422
|
+
|
|
423
|
+
Lifecycle Position:
|
|
424
|
+
This method is called at STEP 12 in the test execution lifecycle::
|
|
425
|
+
|
|
426
|
+
STEP 11: Test execution completes
|
|
427
|
+
STEP 12: fire_diagnostic_capture_post_testrun (this method)
|
|
428
|
+
STEP 13: Finalization begins
|
|
429
|
+
|
|
430
|
+
Example Usage::
|
|
431
|
+
|
|
432
|
+
# Called internally during test execution
|
|
433
|
+
try:
|
|
434
|
+
self.fire_diagnostic_capture_post_testrun(tseq)
|
|
435
|
+
except Exception:
|
|
436
|
+
err_msg = traceback.format_exc()
|
|
437
|
+
self._logger.error(err_msg)
|
|
438
|
+
|
|
439
|
+
Note:
|
|
440
|
+
Errors during diagnostic capture are caught and logged but do not fail
|
|
441
|
+
the test run. This ensures that diagnostic issues do not impact test
|
|
442
|
+
results.
|
|
443
|
+
|
|
444
|
+
See Also:
|
|
445
|
+
- :meth:`fire_diagnostic_capture_pre_testrun`: Fires pre-run diagnostics
|
|
446
|
+
- :meth:`TestSequencer.diagnostic_capture_post_testrun`: Performs the capture
|
|
447
|
+
"""
|
|
448
|
+
tseq.diagnostic_capture_post_testrun(level)
|
|
449
|
+
return
|
|
450
|
+
|
|
451
|
+
def fire_diagnostic_capture_pre_testrun(self, tseq: TestSequencer, level: int=9):
|
|
452
|
+
"""
|
|
453
|
+
Fires the pre-run diagnostic capture event, delegating to the TestSequencer.
|
|
454
|
+
|
|
455
|
+
This method is called after integration setup completes but before test execution
|
|
456
|
+
begins to capture diagnostic information about the initial state of the test
|
|
457
|
+
environment. It delegates the actual diagnostic capture to the TestSequencer's
|
|
458
|
+
:meth:`diagnostic_capture_pre_testrun` method.
|
|
459
|
+
|
|
460
|
+
The diagnostic capture is wrapped in error handling at the call site to ensure
|
|
461
|
+
that diagnostic failures do not cause the test run to fail.
|
|
462
|
+
|
|
463
|
+
:param tseq: The :class:`TestSequencer` instance managing the test execution.
|
|
464
|
+
The sequencer contains the registered integration couplings that will
|
|
465
|
+
perform the actual diagnostic capture.
|
|
466
|
+
:param level: The maximum diagnostic level to capture (1-9). Higher levels
|
|
467
|
+
indicate more detailed diagnostic information. Defaults to 9 (maximum detail).
|
|
468
|
+
|
|
469
|
+
* Levels 1-3: Basic diagnostic information
|
|
470
|
+
* Levels 4-6: Standard diagnostic information
|
|
471
|
+
* Levels 7-9: Detailed diagnostic information
|
|
472
|
+
|
|
473
|
+
:returns: None. Diagnostic files are written by integration couplings.
|
|
474
|
+
|
|
475
|
+
Lifecycle Position:
|
|
476
|
+
This method is called at STEP 8 in the test execution lifecycle::
|
|
477
|
+
|
|
478
|
+
STEP 7: Integration setup completes
|
|
479
|
+
STEP 8: fire_diagnostic_capture_pre_testrun (this method)
|
|
480
|
+
STEP 9: Test execution begins
|
|
481
|
+
|
|
482
|
+
Example Usage::
|
|
483
|
+
|
|
484
|
+
# Called internally during test execution
|
|
485
|
+
try:
|
|
486
|
+
self.fire_diagnostic_capture_pre_testrun(tseq)
|
|
487
|
+
except Exception:
|
|
488
|
+
err_msg = traceback.format_exc()
|
|
489
|
+
self._logger.error(err_msg)
|
|
490
|
+
|
|
491
|
+
Note:
|
|
492
|
+
Errors during diagnostic capture are caught and logged but do not fail
|
|
493
|
+
the test run. This ensures that diagnostic issues do not impact test
|
|
494
|
+
results.
|
|
495
|
+
|
|
496
|
+
See Also:
|
|
497
|
+
- :meth:`fire_diagnostic_capture_post_testrun`: Fires post-run diagnostics
|
|
498
|
+
- :meth:`TestSequencer.diagnostic_capture_pre_testrun`: Performs the capture
|
|
499
|
+
"""
|
|
500
|
+
tseq.diagnostic_capture_pre_testrun(level)
|
|
501
|
+
return
|
|
502
|
+
|
|
503
|
+
def finalize(self): # pylint: disable=no-self-use
|
|
504
|
+
"""
|
|
505
|
+
Called at the end of a test job in order to flush the results of the test run, copy
|
|
506
|
+
the report template to the output directory.
|
|
507
|
+
"""
|
|
508
|
+
return
|
|
509
|
+
|
|
510
|
+
def query(self, format: CommandOutputFormat=CommandOutputFormat.DISPLAY):
|
|
511
|
+
|
|
512
|
+
query_results = []
|
|
513
|
+
|
|
514
|
+
with self._create_sequencer() as tseq:
|
|
515
|
+
|
|
516
|
+
tseq.discover(test_module=self._test_module)
|
|
517
|
+
|
|
518
|
+
query_results = tseq.references
|
|
519
|
+
|
|
520
|
+
self._import_errors.extend(tseq.import_errors)
|
|
521
|
+
|
|
522
|
+
return query_results
|
|
523
|
+
|
|
524
|
+
@classmethod
|
|
525
|
+
def user_interface_display_options(cls):
|
|
526
|
+
"""
|
|
527
|
+
Overridden by derived TestJob classes in order to return a configuration user interface
|
|
528
|
+
description that provides information about a vue javascript component that meets the
|
|
529
|
+
interface requirements and will allow a user to display job configuration information that
|
|
530
|
+
can be packaged stored in a data store as a json object and later passed to a job in order
|
|
531
|
+
to configure the job.
|
|
532
|
+
"""
|
|
533
|
+
return
|
|
534
|
+
|
|
535
|
+
@classmethod
|
|
536
|
+
def user_interface_edit_options(cls):
|
|
537
|
+
"""
|
|
538
|
+
Overridden by derived TestJob classes in order to return a configuration user interface
|
|
539
|
+
description that provides information about a vue javascript component that meets the
|
|
540
|
+
interface requirements and will allow a user to input job configuration information that
|
|
541
|
+
can be packaged stored in a data store as a json object and later passed to a job in order
|
|
542
|
+
to configure the job.
|
|
543
|
+
"""
|
|
544
|
+
return
|
|
545
|
+
|
|
546
|
+
def _create_recorder(self, runid: str, start: datetime, render_info: RenderInfo, build_info: BuildInfo,
|
|
547
|
+
pipeline_info: PipelineInfo, job_info: JobInfo) -> ResultRecorder:
|
|
548
|
+
"""
|
|
549
|
+
Simple hook function to make it possible to overload the type of ResultRecorder that is created for
|
|
550
|
+
any given job.
|
|
551
|
+
"""
|
|
552
|
+
|
|
553
|
+
inst = StdoutResultRecorder(runid=runid, start=start, render_info=render_info, apod=self._apod,
|
|
554
|
+
build_info=build_info, pipeline_info=pipeline_info, job_info=job_info)
|
|
555
|
+
return inst
|
|
556
|
+
|
|
557
|
+
def _create_sequencer(self):
|
|
558
|
+
"""
|
|
559
|
+
Simple hook function to make it possible to overload the type of the TestSequencer that is created
|
|
560
|
+
for jobs.
|
|
561
|
+
"""
|
|
562
|
+
inst = TestSequencer(self._title, self._testroot, includes=self.includes, excludes=self.excludes, metafilters=self.metafilters, job_seed=self.job_seed, output_context=self._output_context)
|
|
563
|
+
return inst
|
|
564
|
+
|
|
565
|
+
def _create_output_context(self) -> IOutputContext:
|
|
566
|
+
"""
|
|
567
|
+
Hook function to make it possible to overload the :class:`IOutputContext` used to resolve
|
|
568
|
+
where run artefacts are written. The standalone default roots everything under the
|
|
569
|
+
``AM_OUTPUT_DIRECTORY`` environment variable or ``<cwd>/.output``. The integration
|
|
570
|
+
runtime overrides this hook to use the well-known result paths.
|
|
571
|
+
|
|
572
|
+
:returns: An :class:`IOutputContext` instance.
|
|
573
|
+
"""
|
|
574
|
+
inst = SimpleOutputContext()
|
|
575
|
+
return inst
|
|
576
|
+
|
|
577
|
+
def _create_run_metadata(self) -> IRunMetadata:
|
|
578
|
+
"""
|
|
579
|
+
Hook function to make it possible to overload the :class:`IRunMetadata` that describes
|
|
580
|
+
this run. The standalone default auto-generates a run id and fills the CI / build /
|
|
581
|
+
pipeline / job descriptors with ``(unknown)`` placeholders. The integration runtime
|
|
582
|
+
overrides this hook to source the values from ``RuntimeVariables``.
|
|
583
|
+
|
|
584
|
+
:returns: An :class:`IRunMetadata` instance.
|
|
585
|
+
"""
|
|
586
|
+
run_title = "Test Run"
|
|
587
|
+
if self.name is not None and len(self.name) > 0:
|
|
588
|
+
run_title = self.name
|
|
589
|
+
|
|
590
|
+
inst = StandaloneRunMetadata(title=run_title)
|
|
591
|
+
return inst
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
class DefaultTestJob(TestJob):
|
|
596
|
+
"""
|
|
597
|
+
The :class:`DefautTestJob` is utilized as a job container when a job was not specified.
|
|
598
|
+
"""
|
|
599
|
+
name = "Test Job"
|
|
600
|
+
description = "Unspecified test job."
|