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,569 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.coupling
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Package containing coupling classes for integrating external resources,
|
|
5
|
+
configurations, and validators into the TestBase test execution framework.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
|
|
9
|
+
The coupling package provides a mechanism for integrating external resources, configurations,
|
|
10
|
+
and validators into the TestBase test execution framework. It enables:
|
|
11
|
+
|
|
12
|
+
* Defining integration points with external systems (devices, services, databases)
|
|
13
|
+
* Managing configuration resources that provide test environment setup
|
|
14
|
+
* Creating validators that verify test outcomes
|
|
15
|
+
* Establishing lifecycle hooks for resource management
|
|
16
|
+
* Supporting hierarchical resource organization with precedence ordering
|
|
17
|
+
|
|
18
|
+
The package includes the following modules:
|
|
19
|
+
|
|
20
|
+
* :mod:`basecoupling` - Contains :class:`BaseCoupling`, the foundational base class
|
|
21
|
+
* :mod:`integrationcoupling` - Contains :class:`IntegrationCoupling` for external resources
|
|
22
|
+
* :mod:`configurationcoupling` - Contains :class:`ConfigurationCoupling` for configurations
|
|
23
|
+
* :mod:`validatorcoupling` - Contains :class:`ValidatorCoupling` for test validators
|
|
24
|
+
|
|
25
|
+
Coupling Hierarchy::
|
|
26
|
+
|
|
27
|
+
BaseCoupling
|
|
28
|
+
├── IntegrationCoupling (external resource integration)
|
|
29
|
+
└── ConfigurationCoupling (environment configuration)
|
|
30
|
+
|
|
31
|
+
ValidatorCoupling (test validation, separate hierarchy)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Coupling Lifecycle Patterns
|
|
35
|
+
===========================
|
|
36
|
+
|
|
37
|
+
The coupling system follows a well-defined lifecycle pattern that ensures resources are
|
|
38
|
+
properly initialized, connected, and cleaned up during test execution. Understanding
|
|
39
|
+
these patterns is essential for implementing robust coupling classes.
|
|
40
|
+
|
|
41
|
+
IntegrationCoupling Lifecycle
|
|
42
|
+
-----------------------------
|
|
43
|
+
|
|
44
|
+
Integration couplings follow a five-phase lifecycle executed in strict order:
|
|
45
|
+
|
|
46
|
+
1. **Registration Phase** (``attach_to_framework``)
|
|
47
|
+
|
|
48
|
+
The first phase registers the coupling with the test framework. This allows the
|
|
49
|
+
framework to track which couplings are required by the tests being executed and
|
|
50
|
+
ignore couplings that are not needed.
|
|
51
|
+
|
|
52
|
+
::
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def attach_to_framework(cls, **kwargs):
|
|
56
|
+
# Register with framework for participation
|
|
57
|
+
framework = kwargs.get('framework')
|
|
58
|
+
framework.register_integration(cls)
|
|
59
|
+
return
|
|
60
|
+
|
|
61
|
+
2. **Configuration Phase** (``attach_to_environment``)
|
|
62
|
+
|
|
63
|
+
The second phase processes configuration information and validates that the
|
|
64
|
+
coupling has a valid environment to operate in. This is where configuration
|
|
65
|
+
files are loaded and validated.
|
|
66
|
+
|
|
67
|
+
::
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
def attach_to_environment(cls, **kwargs):
|
|
71
|
+
config = kwargs.get('config')
|
|
72
|
+
if config is None:
|
|
73
|
+
raise AKitMissingConfigError("Configuration required")
|
|
74
|
+
cls._config = config
|
|
75
|
+
return
|
|
76
|
+
|
|
77
|
+
3. **Resource Acquisition Phase** (``collect_resources``)
|
|
78
|
+
|
|
79
|
+
The third phase connects with resource management systems to acquire the
|
|
80
|
+
resources needed for the automation run. This may involve reserving devices,
|
|
81
|
+
allocating connections, or acquiring other shared resources.
|
|
82
|
+
|
|
83
|
+
::
|
|
84
|
+
|
|
85
|
+
@classmethod
|
|
86
|
+
def collect_resources(cls):
|
|
87
|
+
resource_manager = get_resource_manager()
|
|
88
|
+
cls._resources = resource_manager.acquire('my_resources')
|
|
89
|
+
return
|
|
90
|
+
|
|
91
|
+
4. **Connectivity Phase** (``establish_connectivity``)
|
|
92
|
+
|
|
93
|
+
The fourth phase establishes actual connections to compute or storage resources.
|
|
94
|
+
This phase returns error information and connectivity reports.
|
|
95
|
+
|
|
96
|
+
::
|
|
97
|
+
|
|
98
|
+
@classmethod
|
|
99
|
+
def establish_connectivity(cls, allow_missing_devices=False):
|
|
100
|
+
errors = []
|
|
101
|
+
reports = {}
|
|
102
|
+
for device in cls._devices:
|
|
103
|
+
try:
|
|
104
|
+
connection = device.connect()
|
|
105
|
+
reports[device.id] = {'status': 'connected'}
|
|
106
|
+
except ConnectionError as err:
|
|
107
|
+
if not allow_missing_devices:
|
|
108
|
+
errors.append(f"Failed to connect: {err}")
|
|
109
|
+
reports[device.id] = {'status': 'failed'}
|
|
110
|
+
return (errors, reports)
|
|
111
|
+
|
|
112
|
+
5. **Presence Phase** (``establish_presence``)
|
|
113
|
+
|
|
114
|
+
The fifth phase verifies that resources are not only connected but also
|
|
115
|
+
available and ready for use. This may involve health checks or capability
|
|
116
|
+
verification.
|
|
117
|
+
|
|
118
|
+
::
|
|
119
|
+
|
|
120
|
+
@classmethod
|
|
121
|
+
def establish_presence(cls):
|
|
122
|
+
errors = []
|
|
123
|
+
reports = {}
|
|
124
|
+
for device in cls._devices:
|
|
125
|
+
health = device.health_check()
|
|
126
|
+
reports[device.id] = {'status': 'ready', 'health': health}
|
|
127
|
+
return (errors, reports)
|
|
128
|
+
|
|
129
|
+
Diagnostic Collection
|
|
130
|
+
---------------------
|
|
131
|
+
|
|
132
|
+
Throughout test execution, the ``diagnostic`` method is called at checkpoints
|
|
133
|
+
(pre-run, post-run) to collect diagnostic information:
|
|
134
|
+
|
|
135
|
+
::
|
|
136
|
+
|
|
137
|
+
@classmethod
|
|
138
|
+
def diagnostic(cls, label, level, diag_folder):
|
|
139
|
+
import json
|
|
140
|
+
diag_data = {'label': label, 'status': cls.get_status()}
|
|
141
|
+
diag_file = os.path.join(diag_folder, 'my_diag.json')
|
|
142
|
+
with open(diag_file, 'w') as f:
|
|
143
|
+
json.dump(diag_data, f)
|
|
144
|
+
return
|
|
145
|
+
|
|
146
|
+
ConfigurationCoupling Lifecycle
|
|
147
|
+
-------------------------------
|
|
148
|
+
|
|
149
|
+
Configuration couplings have a simpler lifecycle with only the ``attach_to_environment``
|
|
150
|
+
method for customization. The base class provides a default implementation that does
|
|
151
|
+
nothing, allowing derived classes to override only when needed:
|
|
152
|
+
|
|
153
|
+
::
|
|
154
|
+
|
|
155
|
+
class DatabaseConfig(ConfigurationCoupling):
|
|
156
|
+
@classmethod
|
|
157
|
+
def attach_to_environment(cls, constraints=None):
|
|
158
|
+
# Load configuration
|
|
159
|
+
config = load_database_config()
|
|
160
|
+
# Apply constraints if provided
|
|
161
|
+
if constraints is not None:
|
|
162
|
+
config.update(constraints)
|
|
163
|
+
# Validate and store
|
|
164
|
+
cls._config = config
|
|
165
|
+
return
|
|
166
|
+
|
|
167
|
+
ValidatorCoupling Lifecycle
|
|
168
|
+
---------------------------
|
|
169
|
+
|
|
170
|
+
Validator couplings have the simplest lifecycle, focused on test-level attachment
|
|
171
|
+
rather than framework-level resource management:
|
|
172
|
+
|
|
173
|
+
::
|
|
174
|
+
|
|
175
|
+
class ResponseValidator(ValidatorCoupling):
|
|
176
|
+
def attach_to_test(self, testscope, suffix):
|
|
177
|
+
self._testscope = testscope
|
|
178
|
+
self._suffix = suffix
|
|
179
|
+
return
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
Integration with Dependency Injection
|
|
183
|
+
=====================================
|
|
184
|
+
|
|
185
|
+
The coupling system integrates tightly with the TestBase dependency injection system
|
|
186
|
+
to provide injectable resources to tests and other components.
|
|
187
|
+
|
|
188
|
+
Factory Registration
|
|
189
|
+
--------------------
|
|
190
|
+
|
|
191
|
+
Couplings are registered with the injection system using factory decorators from
|
|
192
|
+
the ``ccai.testbase.declaration.registrations`` module:
|
|
193
|
+
|
|
194
|
+
* ``@integration_factory()`` - Registers integration coupling factories
|
|
195
|
+
* ``@configuration_factory()`` - Registers configuration coupling factories
|
|
196
|
+
* ``@validator_factory()`` - Registers validator coupling factories
|
|
197
|
+
|
|
198
|
+
Integration Factory Example
|
|
199
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
200
|
+
|
|
201
|
+
Integration factories must yield (not return) their coupling instances to support
|
|
202
|
+
cleanup operations:
|
|
203
|
+
|
|
204
|
+
::
|
|
205
|
+
|
|
206
|
+
from typing import Generator
|
|
207
|
+
import testbase
|
|
208
|
+
|
|
209
|
+
@testbase.register.integration_factory()
|
|
210
|
+
def create_device_integration() -> Generator[DeviceIntegration, None, None]:
|
|
211
|
+
integration = DeviceIntegration()
|
|
212
|
+
yield integration
|
|
213
|
+
# Cleanup code runs when generator is closed
|
|
214
|
+
integration.cleanup()
|
|
215
|
+
|
|
216
|
+
Configuration Factory Example
|
|
217
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
218
|
+
|
|
219
|
+
Configuration factories also use generators for lifecycle management:
|
|
220
|
+
|
|
221
|
+
::
|
|
222
|
+
|
|
223
|
+
@testbase.register.configuration_factory()
|
|
224
|
+
def create_database_config() -> Generator[DatabaseConfig, None, None]:
|
|
225
|
+
config = DatabaseConfig()
|
|
226
|
+
yield config
|
|
227
|
+
# Cleanup on generator close
|
|
228
|
+
|
|
229
|
+
Validator Factory Example
|
|
230
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
231
|
+
|
|
232
|
+
Validator factories return instances directly (no generator required):
|
|
233
|
+
|
|
234
|
+
::
|
|
235
|
+
|
|
236
|
+
@testbase.register.validator_factory()
|
|
237
|
+
def create_response_validator() -> ResponseValidator:
|
|
238
|
+
return ResponseValidator()
|
|
239
|
+
|
|
240
|
+
Source Objects
|
|
241
|
+
--------------
|
|
242
|
+
|
|
243
|
+
When a factory is registered, the injection system creates source objects that
|
|
244
|
+
wrap the factory function:
|
|
245
|
+
|
|
246
|
+
* ``IntegrationSource`` - Wraps integration factory functions
|
|
247
|
+
* ``ConfigurationSource`` - Wraps configuration factory functions
|
|
248
|
+
* ``ValidatorSource`` - Wraps validator factory functions
|
|
249
|
+
|
|
250
|
+
These source objects are stored in the ``InjectionRegistry`` and used to track
|
|
251
|
+
which couplings are referenced by tests.
|
|
252
|
+
|
|
253
|
+
Coupling Collection
|
|
254
|
+
-------------------
|
|
255
|
+
|
|
256
|
+
During test framework startup, the injection system walks the scope tree to
|
|
257
|
+
identify all couplings referenced by tests. This is done by the
|
|
258
|
+
``collect_integrations_and_configurations_for_injection_moment`` method:
|
|
259
|
+
|
|
260
|
+
::
|
|
261
|
+
|
|
262
|
+
# The injection system identifies:
|
|
263
|
+
# - Parameters whose resource types are IntegrationCoupling subclasses
|
|
264
|
+
# - Parameters whose resource types are ConfigurationCoupling subclasses
|
|
265
|
+
# These are added to referenced_integrations and referenced_configurations
|
|
266
|
+
|
|
267
|
+
This collection process ensures that only necessary couplings are initialized
|
|
268
|
+
during test execution, improving startup time and resource efficiency.
|
|
269
|
+
|
|
270
|
+
Injection into Tests
|
|
271
|
+
--------------------
|
|
272
|
+
|
|
273
|
+
Once registered, couplings can be injected into test functions by declaring
|
|
274
|
+
parameters with the coupling type:
|
|
275
|
+
|
|
276
|
+
::
|
|
277
|
+
|
|
278
|
+
def test_device_operation(device: DeviceIntegration):
|
|
279
|
+
# The DeviceIntegration instance is automatically injected
|
|
280
|
+
device.perform_operation()
|
|
281
|
+
return
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
Best Practices for Coupling Organization
|
|
285
|
+
========================================
|
|
286
|
+
|
|
287
|
+
Following these best practices ensures maintainable, scalable, and debuggable
|
|
288
|
+
coupling implementations.
|
|
289
|
+
|
|
290
|
+
Hierarchical Organization
|
|
291
|
+
-------------------------
|
|
292
|
+
|
|
293
|
+
Use the integration key hierarchy to organize couplings logically:
|
|
294
|
+
|
|
295
|
+
::
|
|
296
|
+
|
|
297
|
+
# Good: Clear hierarchical organization
|
|
298
|
+
class CiscoRouter(IntegrationCoupling):
|
|
299
|
+
integration_root = "devices" # Top-level category
|
|
300
|
+
integration_section = "network" # Subcategory
|
|
301
|
+
integration_leaf = "router" # Specific type
|
|
302
|
+
integration_class = "CiscoRouter" # Implementation
|
|
303
|
+
|
|
304
|
+
class JuniperSwitch(IntegrationCoupling):
|
|
305
|
+
integration_root = "devices"
|
|
306
|
+
integration_section = "network"
|
|
307
|
+
integration_leaf = "switch"
|
|
308
|
+
integration_class = "JuniperSwitch"
|
|
309
|
+
|
|
310
|
+
Precedence Management
|
|
311
|
+
---------------------
|
|
312
|
+
|
|
313
|
+
Use precedence values to control initialization order. Lower values initialize
|
|
314
|
+
first, so couplings that others depend on should have lower precedence:
|
|
315
|
+
|
|
316
|
+
::
|
|
317
|
+
|
|
318
|
+
class DatabaseIntegration(IntegrationCoupling):
|
|
319
|
+
@classmethod
|
|
320
|
+
def declare_precedence(cls) -> int:
|
|
321
|
+
return 10 # Initialize early (low value)
|
|
322
|
+
|
|
323
|
+
class ServiceIntegration(IntegrationCoupling):
|
|
324
|
+
@classmethod
|
|
325
|
+
def declare_precedence(cls) -> int:
|
|
326
|
+
return 50 # Initialize after database
|
|
327
|
+
|
|
328
|
+
class UIIntegration(IntegrationCoupling):
|
|
329
|
+
@classmethod
|
|
330
|
+
def declare_precedence(cls) -> int:
|
|
331
|
+
return 100 # Initialize last
|
|
332
|
+
|
|
333
|
+
Recommended precedence ranges:
|
|
334
|
+
|
|
335
|
+
* 1-25: Core infrastructure (databases, message queues)
|
|
336
|
+
* 26-50: Services and APIs
|
|
337
|
+
* 51-75: Devices and hardware
|
|
338
|
+
* 76-100: UI and presentation layer
|
|
339
|
+
|
|
340
|
+
Error Handling
|
|
341
|
+
--------------
|
|
342
|
+
|
|
343
|
+
Return detailed error information from lifecycle methods rather than raising
|
|
344
|
+
exceptions immediately. This allows the framework to collect all errors and
|
|
345
|
+
present them together:
|
|
346
|
+
|
|
347
|
+
::
|
|
348
|
+
|
|
349
|
+
@classmethod
|
|
350
|
+
def establish_connectivity(cls, allow_missing_devices=False):
|
|
351
|
+
errors = []
|
|
352
|
+
reports = {}
|
|
353
|
+
|
|
354
|
+
for device in cls._devices:
|
|
355
|
+
try:
|
|
356
|
+
connection = device.connect()
|
|
357
|
+
reports[device.id] = {'status': 'connected'}
|
|
358
|
+
except ConnectionError as err:
|
|
359
|
+
# Collect error instead of raising
|
|
360
|
+
if not allow_missing_devices:
|
|
361
|
+
errors.append(f"Device {device.id}: {err}")
|
|
362
|
+
reports[device.id] = {'status': 'failed', 'error': str(err)}
|
|
363
|
+
|
|
364
|
+
return (errors, reports)
|
|
365
|
+
|
|
366
|
+
Configuration Validation
|
|
367
|
+
------------------------
|
|
368
|
+
|
|
369
|
+
Use ``validate_item_configuration`` to detect configuration problems early:
|
|
370
|
+
|
|
371
|
+
::
|
|
372
|
+
|
|
373
|
+
@classmethod
|
|
374
|
+
def validate_item_configuration(cls, item_info):
|
|
375
|
+
errors = []
|
|
376
|
+
warnings = []
|
|
377
|
+
|
|
378
|
+
# Check required fields
|
|
379
|
+
if 'host' not in item_info:
|
|
380
|
+
errors.append("Missing required 'host' configuration")
|
|
381
|
+
|
|
382
|
+
# Check optional fields with warnings
|
|
383
|
+
if 'timeout' not in item_info:
|
|
384
|
+
warnings.append("No 'timeout' specified, using default of 30s")
|
|
385
|
+
|
|
386
|
+
# Validate field values
|
|
387
|
+
if 'port' in item_info:
|
|
388
|
+
port = item_info['port']
|
|
389
|
+
if not isinstance(port, int) or port < 1 or port > 65535:
|
|
390
|
+
errors.append(f"Invalid port value: {port}")
|
|
391
|
+
|
|
392
|
+
return (errors, warnings)
|
|
393
|
+
|
|
394
|
+
Diagnostic Collection
|
|
395
|
+
---------------------
|
|
396
|
+
|
|
397
|
+
Implement comprehensive diagnostics to aid troubleshooting:
|
|
398
|
+
|
|
399
|
+
::
|
|
400
|
+
|
|
401
|
+
@classmethod
|
|
402
|
+
def diagnostic(cls, label, level, diag_folder):
|
|
403
|
+
import json
|
|
404
|
+
import os
|
|
405
|
+
|
|
406
|
+
# Collect diagnostic data based on level
|
|
407
|
+
diag_data = {
|
|
408
|
+
'label': label,
|
|
409
|
+
'level': level,
|
|
410
|
+
'integration_key': cls.get_integration_key(),
|
|
411
|
+
'activated': cls.integration_activated
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
# Add more detail at higher levels
|
|
415
|
+
if level >= 2:
|
|
416
|
+
diag_data['config'] = cls._config
|
|
417
|
+
if level >= 3:
|
|
418
|
+
diag_data['connection_details'] = cls._get_connection_details()
|
|
419
|
+
|
|
420
|
+
# Write to diagnostic folder
|
|
421
|
+
filename = f"{cls.integration_class}_diag.json"
|
|
422
|
+
diag_file = os.path.join(diag_folder, filename)
|
|
423
|
+
with open(diag_file, 'w') as f:
|
|
424
|
+
json.dump(diag_data, f, indent=2)
|
|
425
|
+
return
|
|
426
|
+
|
|
427
|
+
State Tracking
|
|
428
|
+
--------------
|
|
429
|
+
|
|
430
|
+
Use the built-in state tracking properties to manage coupling state:
|
|
431
|
+
|
|
432
|
+
::
|
|
433
|
+
|
|
434
|
+
class MyIntegration(IntegrationCoupling):
|
|
435
|
+
|
|
436
|
+
@classmethod
|
|
437
|
+
def establish_connectivity(cls, allow_missing_devices=False):
|
|
438
|
+
errors, reports = super().establish_connectivity(allow_missing_devices)
|
|
439
|
+
|
|
440
|
+
# Check state before proceeding
|
|
441
|
+
instance = cls()
|
|
442
|
+
if not instance.connectivity_establish:
|
|
443
|
+
# Handle connectivity not established
|
|
444
|
+
pass
|
|
445
|
+
|
|
446
|
+
return (errors, reports)
|
|
447
|
+
|
|
448
|
+
Logging
|
|
449
|
+
-------
|
|
450
|
+
|
|
451
|
+
Use the inherited logger for consistent logging across all couplings:
|
|
452
|
+
|
|
453
|
+
::
|
|
454
|
+
|
|
455
|
+
class MyIntegration(IntegrationCoupling):
|
|
456
|
+
|
|
457
|
+
@classmethod
|
|
458
|
+
def attach_to_framework(cls, **kwargs):
|
|
459
|
+
cls.logger.info(f"Registering {cls.integration_class} with framework")
|
|
460
|
+
# Registration logic
|
|
461
|
+
return
|
|
462
|
+
|
|
463
|
+
@classmethod
|
|
464
|
+
def establish_connectivity(cls, allow_missing_devices=False):
|
|
465
|
+
cls.logger.debug(f"Establishing connectivity for {cls.integration_class}")
|
|
466
|
+
errors = []
|
|
467
|
+
reports = {}
|
|
468
|
+
# Connection logic
|
|
469
|
+
if errors:
|
|
470
|
+
cls.logger.warning(f"Connectivity errors: {errors}")
|
|
471
|
+
return (errors, reports)
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
Example Usage
|
|
475
|
+
=============
|
|
476
|
+
|
|
477
|
+
Complete Integration Coupling Example
|
|
478
|
+
-------------------------------------
|
|
479
|
+
|
|
480
|
+
::
|
|
481
|
+
|
|
482
|
+
from ccai.testbase.coupling.integrationcoupling import IntegrationCoupling
|
|
483
|
+
|
|
484
|
+
class DeviceIntegration(IntegrationCoupling):
|
|
485
|
+
integration_root = "devices"
|
|
486
|
+
integration_section = "network"
|
|
487
|
+
integration_leaf = "router"
|
|
488
|
+
integration_class = "DeviceIntegration"
|
|
489
|
+
|
|
490
|
+
@classmethod
|
|
491
|
+
def declare_precedence(cls) -> int:
|
|
492
|
+
return 100
|
|
493
|
+
|
|
494
|
+
@classmethod
|
|
495
|
+
def attach_to_framework(cls, **kwargs):
|
|
496
|
+
cls.logger.info("Attaching DeviceIntegration to framework")
|
|
497
|
+
return
|
|
498
|
+
|
|
499
|
+
@classmethod
|
|
500
|
+
def attach_to_environment(cls, **kwargs):
|
|
501
|
+
cls._config = kwargs.get('config', {})
|
|
502
|
+
return
|
|
503
|
+
|
|
504
|
+
@classmethod
|
|
505
|
+
def collect_resources(cls):
|
|
506
|
+
cls._devices = [] # Acquire from resource manager
|
|
507
|
+
return
|
|
508
|
+
|
|
509
|
+
@classmethod
|
|
510
|
+
def establish_connectivity(cls, allow_missing_devices=False):
|
|
511
|
+
return ([], {})
|
|
512
|
+
|
|
513
|
+
@classmethod
|
|
514
|
+
def establish_presence(cls):
|
|
515
|
+
return ([], {})
|
|
516
|
+
|
|
517
|
+
@classmethod
|
|
518
|
+
def diagnostic(cls, label, level, diag_folder):
|
|
519
|
+
return
|
|
520
|
+
|
|
521
|
+
@classmethod
|
|
522
|
+
def validate_item_configuration(cls, item_info):
|
|
523
|
+
return ([], [])
|
|
524
|
+
|
|
525
|
+
Complete Configuration Coupling Example
|
|
526
|
+
---------------------------------------
|
|
527
|
+
|
|
528
|
+
::
|
|
529
|
+
|
|
530
|
+
from ccai.testbase.coupling.configurationcoupling import ConfigurationCoupling
|
|
531
|
+
|
|
532
|
+
class TestConfig(ConfigurationCoupling):
|
|
533
|
+
@classmethod
|
|
534
|
+
def attach_to_environment(cls, constraints=None):
|
|
535
|
+
# Load and validate configuration
|
|
536
|
+
cls._config = {}
|
|
537
|
+
if constraints is not None:
|
|
538
|
+
cls._config.update(constraints)
|
|
539
|
+
return
|
|
540
|
+
|
|
541
|
+
Complete Validator Coupling Example
|
|
542
|
+
-----------------------------------
|
|
543
|
+
|
|
544
|
+
::
|
|
545
|
+
|
|
546
|
+
from ccai.testbase.coupling.validatorcoupling import ValidatorCoupling
|
|
547
|
+
|
|
548
|
+
class ResponseValidator(ValidatorCoupling):
|
|
549
|
+
def __init__(self):
|
|
550
|
+
self._testscope = None
|
|
551
|
+
self._suffix = None
|
|
552
|
+
return
|
|
553
|
+
|
|
554
|
+
def attach_to_test(self, testscope, suffix):
|
|
555
|
+
self._testscope = testscope
|
|
556
|
+
self._suffix = suffix
|
|
557
|
+
return
|
|
558
|
+
|
|
559
|
+
def validate_status(self, expected_status):
|
|
560
|
+
# Validation logic
|
|
561
|
+
return
|
|
562
|
+
|
|
563
|
+
"""
|
|
564
|
+
|
|
565
|
+
__author__ = "Myron Walker"
|
|
566
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
567
|
+
__credits__ = []
|
|
568
|
+
|
|
569
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.coupling.basecoupling
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module containing the :class:`BaseCoupling` class which serves as the foundational
|
|
5
|
+
abstract base class for all coupling-based resources in the TestBase framework.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
|
|
9
|
+
The BaseCoupling module provides the foundational type for all coupling-based resources in the
|
|
10
|
+
TestBase test execution framework. It establishes common infrastructure including logging
|
|
11
|
+
capabilities that are shared across all derived coupling types.
|
|
12
|
+
|
|
13
|
+
Example usage::
|
|
14
|
+
|
|
15
|
+
from ccai.testbase.coupling.basecoupling import BaseCoupling
|
|
16
|
+
|
|
17
|
+
class MyCustomCoupling(BaseCoupling):
|
|
18
|
+
'''
|
|
19
|
+
Custom coupling implementation.
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
def do_something(self):
|
|
23
|
+
self.logger.info("Performing custom coupling operation")
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
__author__ = "Myron Walker"
|
|
29
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
30
|
+
__credits__ = []
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
from ccai.xmodules.xlogging.enhancedloggers import getEnhancedLogger
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class BaseCoupling:
|
|
37
|
+
"""
|
|
38
|
+
The :class:`BaseCoupling` class serves as the foundational abstract base class for all
|
|
39
|
+
coupling-based resources in the TestBase framework. It provides common infrastructure
|
|
40
|
+
including logging capabilities that are shared across all derived coupling types.
|
|
41
|
+
|
|
42
|
+
This class is the base type used for detecting coupling-based resources during dependency
|
|
43
|
+
injection and test execution. All coupling types (IntegrationCoupling, ConfigurationCoupling)
|
|
44
|
+
inherit from this class to gain access to the shared logger instance.
|
|
45
|
+
|
|
46
|
+
:cvar logger: A shared :class:`EnhancedLogger` instance accessible to all derived classes
|
|
47
|
+
for logging coupling operations and diagnostic information.
|
|
48
|
+
|
|
49
|
+
Example usage::
|
|
50
|
+
|
|
51
|
+
from ccai.testbase.coupling.basecoupling import BaseCoupling
|
|
52
|
+
|
|
53
|
+
class DeviceCoupling(BaseCoupling):
|
|
54
|
+
'''
|
|
55
|
+
Coupling for device automation resources.
|
|
56
|
+
'''
|
|
57
|
+
|
|
58
|
+
def connect(self):
|
|
59
|
+
self.logger.info("Connecting to device...")
|
|
60
|
+
# Connection logic here
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
.. note::
|
|
64
|
+
This class should not be instantiated directly. Instead, use one of the derived
|
|
65
|
+
coupling types: :class:`IntegrationCoupling`, :class:`ConfigurationCoupling`, or
|
|
66
|
+
:class:`ValidatorCoupling`.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
logger = getEnhancedLogger()
|