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,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.sources.resourcesource
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for resourcesource.
|
|
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 Callable, Union, Type
|
|
17
|
+
|
|
18
|
+
from ccai.testbase.sources.sourcebase import SourceBase
|
|
19
|
+
|
|
20
|
+
class ResourceSource(SourceBase):
|
|
21
|
+
"""
|
|
22
|
+
Source wrapper for general resource providers.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, source_func: Callable, query_func: Union[Callable, None], resource_type: Type, constraints: dict):
|
|
26
|
+
SourceBase.__init__(self, source_func, query_func, resource_type, constraints)
|
|
27
|
+
return
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.sources.sourcebase
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for sourcebase.
|
|
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 Callable, Type
|
|
18
|
+
|
|
19
|
+
import inspect
|
|
20
|
+
|
|
21
|
+
class SourceBase:
|
|
22
|
+
"""
|
|
23
|
+
Base class representing a provider of injectable objects.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, source_func: Callable, query_func: Callable, resource_type: Type, constaints: dict):
|
|
27
|
+
self._source_func = source_func
|
|
28
|
+
self._query_func = query_func
|
|
29
|
+
self._resource_type = resource_type
|
|
30
|
+
self._constraints = constaints
|
|
31
|
+
self._subscriptions = None
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def constraints(self):
|
|
36
|
+
return self._constraints
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def module_name(self) -> str:
|
|
40
|
+
return self._source_func.__module__
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def query_function(self) -> Callable:
|
|
44
|
+
return self._query_func
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def resource_type(self) -> Type:
|
|
48
|
+
return self._resource_type
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def source_function(self) -> Callable:
|
|
52
|
+
return self._source_func
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def source_signature(self) -> inspect.Signature:
|
|
56
|
+
return inspect.signature(self._source_func)
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def source_id(self) -> str:
|
|
60
|
+
source = self._source_func
|
|
61
|
+
idstr = "{}#{}".format(source.__module__, source.__name__)
|
|
62
|
+
return idstr
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def subscriptions(self):
|
|
66
|
+
return self._subscriptions
|
|
67
|
+
|
|
68
|
+
@subscriptions.setter
|
|
69
|
+
def subscriptions(self, val):
|
|
70
|
+
self._subscriptions = val
|
|
71
|
+
return
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.sources.unknownsource
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for unknownsource.
|
|
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
|
+
__version__ = "1.0.0"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
from typing import Callable, Type
|
|
18
|
+
|
|
19
|
+
from ccai.testbase.sources.sourcebase import SourceBase
|
|
20
|
+
|
|
21
|
+
class UnknownSource(SourceBase):
|
|
22
|
+
"""
|
|
23
|
+
The :class:`UnknownSource` object is used when a parameter is declared for a
|
|
24
|
+
injectable method of other resource function that cannot be resolved to a source
|
|
25
|
+
function. The :class:`UnknownSource` enables the injectable parameters to be queried
|
|
26
|
+
by acting as a placeholder.
|
|
27
|
+
"""
|
|
28
|
+
def __init__(self, source_func: Callable, resource_type: Type, constraints: dict):
|
|
29
|
+
SourceBase.__init__(self, source_func, resource_type, constraints)
|
|
30
|
+
return
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.sources.validatorsource
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for validatorsource.
|
|
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
|
+
__version__ = "1.0.0"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
from typing import Callable, Type
|
|
18
|
+
|
|
19
|
+
from ccai.testbase.sources.sourcebase import SourceBase
|
|
20
|
+
|
|
21
|
+
class ValidatorSource(SourceBase):
|
|
22
|
+
"""
|
|
23
|
+
Source wrapper for validator implementations.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, source_func: Callable, resource_type: Type, constraints: dict):
|
|
27
|
+
SourceBase.__init__(self, source_func, None, resource_type, constraints)
|
|
28
|
+
return
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.tandem
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for tandem.
|
|
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,286 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.tandem.validators
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for validators.
|
|
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
|
+
import os
|
|
17
|
+
import threading
|
|
18
|
+
import time
|
|
19
|
+
import uuid
|
|
20
|
+
|
|
21
|
+
from ccai.errors.exceptions import AbstractMethodError, SemanticError
|
|
22
|
+
from ccai.errors.xtraceback import create_traceback_detail, format_traceback_detail
|
|
23
|
+
|
|
24
|
+
from ccai.waiting import wait_for_it, TimeoutContext
|
|
25
|
+
|
|
26
|
+
from ccai.xmodules.xlogging.enhancedloggers import getEnhancedLogger
|
|
27
|
+
|
|
28
|
+
from ccai.testbase.results.model.testresult import TestResult
|
|
29
|
+
from ccai.testbase.coupling.validatorcoupling import ValidatorCoupling
|
|
30
|
+
from ccai.testbase.sequencing.sequencertestscope import SequencerTestScope
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Validator(ValidatorCoupling):
|
|
34
|
+
"""
|
|
35
|
+
Base class for validator implementations used with tandem tests.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
def __init__(self):
|
|
39
|
+
super().__init__()
|
|
40
|
+
|
|
41
|
+
self._inst_id = str(uuid.uuid4())
|
|
42
|
+
|
|
43
|
+
self._suffix = None
|
|
44
|
+
self._testscope = None
|
|
45
|
+
self._parent_scope_id = None
|
|
46
|
+
self._validator_name = None
|
|
47
|
+
self._recorder = None
|
|
48
|
+
|
|
49
|
+
self._logger = getEnhancedLogger()
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def inst_id(self):
|
|
54
|
+
return self._inst_id
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def suffix(self):
|
|
58
|
+
return self._suffix
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def validator_name(self):
|
|
62
|
+
return self._validator_name
|
|
63
|
+
|
|
64
|
+
def attach_to_test(self, testscope: SequencerTestScope, suffix: str):
|
|
65
|
+
"""
|
|
66
|
+
The 'attach_to_test' method is called by the sequencer in order to attach the validator to its partner
|
|
67
|
+
test scope.
|
|
68
|
+
"""
|
|
69
|
+
self._testscope = testscope
|
|
70
|
+
self._suffix = suffix
|
|
71
|
+
self._parent_scope_id = self._testscope._parent_scope_id
|
|
72
|
+
self._validator_name = testscope.test_name + "_" + self._suffix
|
|
73
|
+
self._recorder = testscope.recorder
|
|
74
|
+
self._result = TestResult(self._inst_id, self._validator_name, self._parent_scope_id, self._testscope._monikers, self._testscope._pivots)
|
|
75
|
+
self._recorder.preview(self._result)
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
def initialize(self, *args, **kwargs):
|
|
79
|
+
"""
|
|
80
|
+
The 'initialize' method should attempt to initialize the validator but it should not allow an exception
|
|
81
|
+
to be raised. It should handle and store any exceptions raised during initialization for later evaluation
|
|
82
|
+
during the 'validate' method.
|
|
83
|
+
"""
|
|
84
|
+
self._logger.warn("Validator.initialize called on the base validator object which is a no-op.")
|
|
85
|
+
return
|
|
86
|
+
|
|
87
|
+
def validate(self):
|
|
88
|
+
"""
|
|
89
|
+
The 'validate' method is a self contained testcase. It checks the state of the validator object and then
|
|
90
|
+
raises the appropriate exception for an 'Error' or 'Failure' condition based on the results found.
|
|
91
|
+
"""
|
|
92
|
+
raise AbstractMethodError("Validator derived types must implement the 'validate' method.")
|
|
93
|
+
|
|
94
|
+
def finalize(self):
|
|
95
|
+
"""
|
|
96
|
+
The 'finalize' method should attempt to finalize the validator but it should not allow an exception
|
|
97
|
+
to be raised. It should handle and store any exceptions raised during finalization and store any
|
|
98
|
+
exceptions it has encountered into its associated test result.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
try:
|
|
102
|
+
self.validate()
|
|
103
|
+
|
|
104
|
+
self._result.mark_passed()
|
|
105
|
+
except AssertionError as aerr:
|
|
106
|
+
# If an exceptions was thrown in this context, it means
|
|
107
|
+
# that a test threw an exception.
|
|
108
|
+
tb_detail = create_traceback_detail(aerr)
|
|
109
|
+
|
|
110
|
+
self._result.add_failure(tb_detail)
|
|
111
|
+
|
|
112
|
+
traceback_lines = format_traceback_detail(tb_detail)
|
|
113
|
+
errmsg = os.linesep.join(traceback_lines)
|
|
114
|
+
self._logger.error(errmsg)
|
|
115
|
+
except Exception as gerr:
|
|
116
|
+
# If an exceptions was thrown in this context, it means
|
|
117
|
+
# that a test threw an exception.
|
|
118
|
+
tb_detail = create_traceback_detail(gerr)
|
|
119
|
+
|
|
120
|
+
self._result.add_error(tb_detail)
|
|
121
|
+
|
|
122
|
+
traceback_lines = format_traceback_detail(tb_detail)
|
|
123
|
+
errmsg = os.linesep.join(traceback_lines)
|
|
124
|
+
self._logger.error(errmsg)
|
|
125
|
+
|
|
126
|
+
finally:
|
|
127
|
+
self._result.finalize()
|
|
128
|
+
|
|
129
|
+
self._recorder.record(self._result)
|
|
130
|
+
|
|
131
|
+
return
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
DEFAULT_LOOP_DELAY = 0
|
|
135
|
+
|
|
136
|
+
DEFAULT_SHUTDOWN_TIMEOUT = 60
|
|
137
|
+
DEFAULT_SHUTDOWN_INTERVAL = 1
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class LoopingValidatorState:
|
|
141
|
+
"""
|
|
142
|
+
Enumerates the operational states of a :class:`LoopingValidator`.
|
|
143
|
+
"""
|
|
144
|
+
Initial = "Initial"
|
|
145
|
+
Running = "Running"
|
|
146
|
+
Shutdown = "Shutdown"
|
|
147
|
+
Finished = "Finished"
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class LoopingValidator(Validator):
|
|
151
|
+
"""
|
|
152
|
+
The :class:`LoopingValidator` object provides a mechanism for performing a series
|
|
153
|
+
of validation work tasks in parallel to a test.
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
def __init__(self, loop_delay: int=DEFAULT_LOOP_DELAY, shutdown_timeout: float=DEFAULT_SHUTDOWN_TIMEOUT, shutdown_interval: int=DEFAULT_SHUTDOWN_INTERVAL):
|
|
157
|
+
|
|
158
|
+
super().__init__()
|
|
159
|
+
|
|
160
|
+
self._loop_delay = loop_delay
|
|
161
|
+
self._shutdown_timeout = shutdown_timeout
|
|
162
|
+
self._shutdown_interval = shutdown_interval
|
|
163
|
+
|
|
164
|
+
self._state = LoopingValidatorState.Initial
|
|
165
|
+
|
|
166
|
+
self._thread = None
|
|
167
|
+
self._lock = threading.RLock()
|
|
168
|
+
|
|
169
|
+
return
|
|
170
|
+
|
|
171
|
+
def attach_to_test(self, testscope: SequencerTestScope, suffix: str):
|
|
172
|
+
"""
|
|
173
|
+
The 'attach_to_test' method is called by the sequencer in order to attach the validator to its partner
|
|
174
|
+
test scope.
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
self._testscope = testscope
|
|
178
|
+
self._suffix = suffix
|
|
179
|
+
self._parent_scope_id = self._testscope._parent_scope_id
|
|
180
|
+
self._validator_name = testscope.test_name + "_" + self._suffix
|
|
181
|
+
self._recorder = testscope.recorder
|
|
182
|
+
self._result = TestResult(self._inst_id, self._validator_name, self._parent_scope_id, self._testscope._monikers, self._testscope._pivots)
|
|
183
|
+
self._recorder.preview(self._result)
|
|
184
|
+
|
|
185
|
+
return
|
|
186
|
+
|
|
187
|
+
def do_work(self) -> bool:
|
|
188
|
+
|
|
189
|
+
return False
|
|
190
|
+
|
|
191
|
+
def initialize(self, *args, **kwargs):
|
|
192
|
+
"""
|
|
193
|
+
The 'initialize' method should attempt to initialize the validator but it should not allow an exception
|
|
194
|
+
to be raised. It should handle and store any exceptions raised during initialization for later evaluation
|
|
195
|
+
during the 'validate' method.
|
|
196
|
+
"""
|
|
197
|
+
if self._state != LoopingValidatorState.Initial:
|
|
198
|
+
errmsg = "LoopingValidator.initialize called while the looper was already running."
|
|
199
|
+
raise SemanticError(errmsg)
|
|
200
|
+
|
|
201
|
+
sgate = threading.Event()
|
|
202
|
+
sgate.clear()
|
|
203
|
+
|
|
204
|
+
self._thread = threading.Thread(target=self._thread_entry, args=(sgate,) ,daemon=True)
|
|
205
|
+
self._thread.start()
|
|
206
|
+
|
|
207
|
+
sgate.wait()
|
|
208
|
+
|
|
209
|
+
return
|
|
210
|
+
|
|
211
|
+
def finalize(self):
|
|
212
|
+
"""
|
|
213
|
+
The 'finalize' method should attempt to finalize the validator but it should not allow an exception
|
|
214
|
+
to be raised. It should handle and store any exceptions raised during finalization and store any
|
|
215
|
+
exceptions it has encountered into its associated test result.
|
|
216
|
+
"""
|
|
217
|
+
|
|
218
|
+
# Mark the state as 'Shutdown' to tell the thread to stop
|
|
219
|
+
# looping
|
|
220
|
+
self._state = LoopingValidatorState.Shutdown
|
|
221
|
+
|
|
222
|
+
# We have to wait for the thread that is shutting down to exit
|
|
223
|
+
# and mark the state as 'Finised' before we can call finalize
|
|
224
|
+
self.wait()
|
|
225
|
+
|
|
226
|
+
super().finalize()
|
|
227
|
+
|
|
228
|
+
return
|
|
229
|
+
|
|
230
|
+
def wait(self):
|
|
231
|
+
|
|
232
|
+
wait_for_it(self._wait_for_shutdown, what_for="LoopingValidator Shutdown", timeout=self._shutdown_timeout, interval=self._shutdown_interval)
|
|
233
|
+
|
|
234
|
+
return
|
|
235
|
+
|
|
236
|
+
def _thread_entry(self, sgate: threading.Event):
|
|
237
|
+
|
|
238
|
+
sgate.set()
|
|
239
|
+
|
|
240
|
+
self._state = LoopingValidatorState.Running
|
|
241
|
+
|
|
242
|
+
while self._state == LoopingValidatorState.Running:
|
|
243
|
+
more_work = self.do_work()
|
|
244
|
+
if not more_work:
|
|
245
|
+
break
|
|
246
|
+
|
|
247
|
+
if self._loop_delay > 0:
|
|
248
|
+
time.sleep(self._loop_delay)
|
|
249
|
+
|
|
250
|
+
self._state = LoopingValidatorState.Finished
|
|
251
|
+
|
|
252
|
+
return
|
|
253
|
+
|
|
254
|
+
def _wait_for_shutdown(self, wctx: TimeoutContext) -> bool:
|
|
255
|
+
|
|
256
|
+
shutdown = False
|
|
257
|
+
if self._state != LoopingValidatorState.Finished:
|
|
258
|
+
shutdown = True
|
|
259
|
+
|
|
260
|
+
if not shutdown and wctx.final_attempt:
|
|
261
|
+
to = wctx.create_timeout(what_for="LoopingValidator Shutdown")
|
|
262
|
+
raise to
|
|
263
|
+
|
|
264
|
+
return shutdown
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class TimeIntervalValidator(LoopingValidator):
|
|
268
|
+
"""
|
|
269
|
+
The :class:`TimeIntervalValidator` object provides a mechanism for performing a series
|
|
270
|
+
of validation work tasks in parallel to a test.
|
|
271
|
+
"""
|
|
272
|
+
|
|
273
|
+
def __init__(self, interval: int, shutdown_timeout: float=DEFAULT_SHUTDOWN_TIMEOUT, shutdown_interval: int=DEFAULT_SHUTDOWN_INTERVAL):
|
|
274
|
+
super().__init__(loop_delay=interval, shutdown_timeout=shutdown_timeout, shutdown_interval=shutdown_interval)
|
|
275
|
+
return
|
|
276
|
+
|
|
277
|
+
def do_work(self) -> bool:
|
|
278
|
+
self.tick()
|
|
279
|
+
return True
|
|
280
|
+
|
|
281
|
+
def tick(self):
|
|
282
|
+
"""
|
|
283
|
+
The 'tick' method is implemented by derived classes in order to perform work at
|
|
284
|
+
a specified interval.
|
|
285
|
+
"""
|
|
286
|
+
return
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.testbase.testcollector
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module for testcollector.
|
|
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
|
+
from typing import Dict, List, Sequence, Tuple
|
|
16
|
+
from types import ModuleType
|
|
17
|
+
|
|
18
|
+
import os
|
|
19
|
+
|
|
20
|
+
from ccai.errors.exceptions import SemanticError, UnknownParameterError
|
|
21
|
+
|
|
22
|
+
from ccai.xmodules.xlogging.enhancedloggers import getEnhancedLogger
|
|
23
|
+
|
|
24
|
+
from ccai.testbase.markers import MetaFilter
|
|
25
|
+
from ccai.testbase.injection.injectionregistry import injection_registry
|
|
26
|
+
from ccai.testbase.coupling.integrationcoupling import IntegrationCoupling
|
|
27
|
+
|
|
28
|
+
from ccai.testbase.expressions import parse_test_include_expression
|
|
29
|
+
from ccai.testbase.utilities import find_included_modules_under_root
|
|
30
|
+
from ccai.testbase.queries import collect_test_references
|
|
31
|
+
|
|
32
|
+
from ccai.testbase.testgroup import TestGroup
|
|
33
|
+
from ccai.testbase.testref import TestRef
|
|
34
|
+
|
|
35
|
+
logger = getEnhancedLogger()
|
|
36
|
+
|
|
37
|
+
def catagorize_exclusions(excluded: str) -> Tuple[List[str], List[str]]:
|
|
38
|
+
"""
|
|
39
|
+
Go through a list of exclusion expressions and divide them up by whether they are
|
|
40
|
+
file based exclusions or an exclusion that targets python types or methods within
|
|
41
|
+
a specific module.
|
|
42
|
+
|
|
43
|
+
:param excluded: A list of exclusion expressions.
|
|
44
|
+
|
|
45
|
+
:returns: A list of file exclusion expressions and a list of specific exclusions.
|
|
46
|
+
"""
|
|
47
|
+
file_exclusions = []
|
|
48
|
+
specific_exclusions = []
|
|
49
|
+
|
|
50
|
+
if excluded is not None:
|
|
51
|
+
for ex in excluded:
|
|
52
|
+
if ex.find("@") == -1:
|
|
53
|
+
path_prefix = ex.replace(".", os.sep)
|
|
54
|
+
file_exclusions.append(path_prefix)
|
|
55
|
+
else:
|
|
56
|
+
specific_exclusions.append(ex)
|
|
57
|
+
|
|
58
|
+
return file_exclusions, specific_exclusions
|
|
59
|
+
|
|
60
|
+
class TestCollector:
|
|
61
|
+
"""
|
|
62
|
+
The :class:`TestCollector` object utilizes the include and exclude expressions along with any test_module
|
|
63
|
+
provided to collect the information about the test references and the associated test packages that will
|
|
64
|
+
be involved in test run.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(self, root: str, excludes: Sequence[str], metafilters: Sequence[MetaFilter],
|
|
68
|
+
method_prefix: str = "test", test_module: ModuleType = None):
|
|
69
|
+
"""
|
|
70
|
+
Initializes a :class:`TestCollector` instance in order to process the test tree and
|
|
71
|
+
collect references and test packages to be run.
|
|
72
|
+
|
|
73
|
+
:param root: The root directory to scan for included tests
|
|
74
|
+
:param excludes: A list or sequence of exclude expressions to apply during test collection operations.
|
|
75
|
+
:param metafilters: A list of metadata filters to apply during test collection operations.
|
|
76
|
+
:param method_prefix: The prefix or word that test methods will start with. The default is 'test'.
|
|
77
|
+
:param test_module: A test module which is passed for the debug workflow where a test module is run directly
|
|
78
|
+
as a script using the generic_test_entrypoint or in the debugger by Right-Click
|
|
79
|
+
|
|
80
|
+
"""
|
|
81
|
+
self._root = root
|
|
82
|
+
self._root_directory_listing = None
|
|
83
|
+
self._excludes = excludes
|
|
84
|
+
self._metafilters = metafilters
|
|
85
|
+
self._method_prefix = method_prefix
|
|
86
|
+
self._test_module = test_module
|
|
87
|
+
self._test_references: Dict[str, TestRef] = {}
|
|
88
|
+
self._import_errors = {}
|
|
89
|
+
self._excluded_tests = []
|
|
90
|
+
self._excluded_files = []
|
|
91
|
+
self._excluded_path_prefixes, self._excluded_specifically = catagorize_exclusions(self._excludes)
|
|
92
|
+
self._test_tree = None
|
|
93
|
+
return
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def import_errors(self):
|
|
97
|
+
"""
|
|
98
|
+
A list of import errors that were encountered while collecting test references.
|
|
99
|
+
"""
|
|
100
|
+
return self._import_errors
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def references(self) -> Dict[str, TestRef]:
|
|
104
|
+
"""
|
|
105
|
+
A list of :class:`TestReferences` that were collected.
|
|
106
|
+
"""
|
|
107
|
+
return self._test_references
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def test_tree(self) -> TestGroup:
|
|
111
|
+
"""
|
|
112
|
+
Returns the :class:`TestGroup` created from the collected references.
|
|
113
|
+
|
|
114
|
+
:returns: The root of the test reference tree.
|
|
115
|
+
"""
|
|
116
|
+
return self._test_tree
|
|
117
|
+
|
|
118
|
+
def collect_integrations_and_configurations(self) -> List[IntegrationCoupling]:
|
|
119
|
+
"""
|
|
120
|
+
Iterates through all of the test references and collects the IntegrationCoupling(s) and
|
|
121
|
+
ScopeCouplings that are found. The collected IntegrationCoupling(s) and ScopeCoupling(s) can
|
|
122
|
+
be used by integrations and scopes to participate in test framework startup.
|
|
123
|
+
|
|
124
|
+
:returns: A tuple containing lists of referenced integrations and configurations.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
referenced_integrations = {}
|
|
128
|
+
|
|
129
|
+
# Add implied injected resources
|
|
130
|
+
injection_registry.add_implied_session_resource("sequencer")
|
|
131
|
+
|
|
132
|
+
# All the implicit registration of all the integration, scope and resource parameters sources
|
|
133
|
+
# should have happend by now. The ResourceRegistry should have a partially populated scope
|
|
134
|
+
# tree.
|
|
135
|
+
injection_registry.finalize_startup(self._test_references)
|
|
136
|
+
|
|
137
|
+
unknown_parameter = injection_registry.unknown_parameters
|
|
138
|
+
|
|
139
|
+
if len(unknown_parameter) > 0:
|
|
140
|
+
err_msg_lines = [
|
|
141
|
+
"TestCollector: Unable to resolve the following parameters.",
|
|
142
|
+
"Missing Parameters:"
|
|
143
|
+
]
|
|
144
|
+
subscriber_key_list = [upn for upn in unknown_parameter.keys()]
|
|
145
|
+
subscriber_key_list.sort()
|
|
146
|
+
for subscriber in subscriber_key_list:
|
|
147
|
+
missing_params = unknown_parameter[subscriber]
|
|
148
|
+
err_msg_lines.append(" {}".format(subscriber))
|
|
149
|
+
for mparam in missing_params:
|
|
150
|
+
err_msg_lines.append(" {}".format(mparam))
|
|
151
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
152
|
+
raise UnknownParameterError(err_msg) from None
|
|
153
|
+
|
|
154
|
+
referenced_integrations = injection_registry.referenced_integrations
|
|
155
|
+
referenced_configurations = injection_registry.referenced_configurations
|
|
156
|
+
|
|
157
|
+
return referenced_integrations, referenced_configurations
|
|
158
|
+
|
|
159
|
+
def collect_references(self, expression: str):
|
|
160
|
+
"""
|
|
161
|
+
Collects and appends the test references based on the expression provided and the excludes
|
|
162
|
+
for this class. The `collect_references` method is intended to be called multiple times,
|
|
163
|
+
once with each include expression provided by the users. The :class:`TestCollector` will
|
|
164
|
+
extend its collection of reference with each successive call.
|
|
165
|
+
|
|
166
|
+
:param expression: An include expression to process and collect references for.
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
expr_package, expr_module, expr_testclass, expr_testname = parse_test_include_expression(expression, self._test_module, self._method_prefix)
|
|
170
|
+
|
|
171
|
+
if expr_testclass != None:
|
|
172
|
+
raise SemanticError("TestBase style tests do not support tests inside of classes.") from None
|
|
173
|
+
|
|
174
|
+
# Find all the files that are included based on the expr_package, expr_module expressions
|
|
175
|
+
included_files = []
|
|
176
|
+
excluded_files = []
|
|
177
|
+
|
|
178
|
+
if expr_package is not None or expr_module is not None:
|
|
179
|
+
included_files, excluded_files = find_included_modules_under_root(self._root,
|
|
180
|
+
expr_package, expr_module, excluded_path_prefixes=self._excluded_path_prefixes)
|
|
181
|
+
|
|
182
|
+
self._excluded_files.extend(excluded_files)
|
|
183
|
+
|
|
184
|
+
test_references, import_errors = collect_test_references(
|
|
185
|
+
self._root, included_files, expr_package, expr_module, expr_testname, self._method_prefix)
|
|
186
|
+
|
|
187
|
+
self._test_references.update(test_references)
|
|
188
|
+
|
|
189
|
+
self._import_errors.update(import_errors)
|
|
190
|
+
|
|
191
|
+
for modname, ifile, errmsg in import_errors.values():
|
|
192
|
+
logger.error("TestCase: Import error filename=%r" % ifile)
|
|
193
|
+
|
|
194
|
+
return
|
|
195
|
+
|
|
196
|
+
def finalize_collection(self):
|
|
197
|
+
"""
|
|
198
|
+
Applies the metadata filters and then creates the test tree.
|
|
199
|
+
|
|
200
|
+
:returns: ``None``
|
|
201
|
+
"""
|
|
202
|
+
|
|
203
|
+
testref_key_list = [k for k in self._test_references.keys()]
|
|
204
|
+
|
|
205
|
+
temp_tree = TestGroup("<session>")
|
|
206
|
+
for _, trval in self._test_references.items():
|
|
207
|
+
temp_tree.add_descendent(trval)
|
|
208
|
+
|
|
209
|
+
# Go through all of the test references and have all of the them
|
|
210
|
+
# resolve their metadata reference chains
|
|
211
|
+
temp_tree.resolve_metadata()
|
|
212
|
+
|
|
213
|
+
# Apply metafilters to remove any tests that don't meet any specified
|
|
214
|
+
# meta criteria
|
|
215
|
+
if self._metafilters is not None and len(self._metafilters) > 0:
|
|
216
|
+
filtered_references = {}
|
|
217
|
+
|
|
218
|
+
for tref_key in testref_key_list:
|
|
219
|
+
tref_obj = self._test_references[tref_key]
|
|
220
|
+
if tref_obj.is_member_of_metaset(self._metafilters):
|
|
221
|
+
filtered_references[tref_key] = tref_obj
|
|
222
|
+
|
|
223
|
+
del self._test_references
|
|
224
|
+
self._test_references = filtered_references
|
|
225
|
+
|
|
226
|
+
self._test_tree = TestGroup("<session>")
|
|
227
|
+
for _, trval in self._test_references.items():
|
|
228
|
+
self._test_tree.add_descendent(trval)
|
|
229
|
+
|
|
230
|
+
return
|