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.
Files changed (142) hide show
  1. ccai/factories/py.typed +0 -0
  2. ccai/factories/testbasedefaulttypefactory.py +25 -0
  3. ccai/testbase/__init__.py +63 -0
  4. ccai/testbase/breakpoints.py +110 -0
  5. ccai/testbase/cli/__init__.py +13 -0
  6. ccai/testbase/cli/cmdtree/agents/__init__.py +28 -0
  7. ccai/testbase/cli/cmdtree/agents/config/__init__.py +24 -0
  8. ccai/testbase/cli/cmdtree/agents/config/extract.py +94 -0
  9. ccai/testbase/cli/cmdtree/agents/formatting.py +71 -0
  10. ccai/testbase/cli/cmdtree/agents/jsosparser.py +119 -0
  11. ccai/testbase/cli/cmdtree/agents/pathresolver.py +34 -0
  12. ccai/testbase/cli/cmdtree/agents/summary/__init__.py +26 -0
  13. ccai/testbase/cli/cmdtree/agents/summary/compare.py +128 -0
  14. ccai/testbase/cli/cmdtree/agents/summary/extract.py +91 -0
  15. ccai/testbase/cli/cmdtree/agents/testresult/__init__.py +28 -0
  16. ccai/testbase/cli/cmdtree/agents/testresult/extract.py +77 -0
  17. ccai/testbase/cli/cmdtree/agents/testresult/failures.py +73 -0
  18. ccai/testbase/cli/cmdtree/agents/testresult/list.py +63 -0
  19. ccai/testbase/cli/cmdtree/services/__init__.py +27 -0
  20. ccai/testbase/cli/cmdtree/services/results.py +66 -0
  21. ccai/testbase/cli/cmdtree/testing/__init__.py +30 -0
  22. ccai/testbase/cli/cmdtree/testing/jobs.py +175 -0
  23. ccai/testbase/cli/cmdtree/testing/query.py +131 -0
  24. ccai/testbase/cli/cmdtree/testing/run.py +263 -0
  25. ccai/testbase/cli/cmdtree/utilities/__init__.py +28 -0
  26. ccai/testbase/cli/cmdtree/utilities/timestamp.py +33 -0
  27. ccai/testbase/cli/options.py +370 -0
  28. ccai/testbase/cli/testbase_command.py +64 -0
  29. ccai/testbase/cli/utilities.py +31 -0
  30. ccai/testbase/configuration.py +324 -0
  31. ccai/testbase/constraints.py +998 -0
  32. ccai/testbase/coupling/__init__.py +569 -0
  33. ccai/testbase/coupling/basecoupling.py +69 -0
  34. ccai/testbase/coupling/configurationcoupling.py +138 -0
  35. ccai/testbase/coupling/integrationcoupling.py +842 -0
  36. ccai/testbase/coupling/validatorcoupling.py +127 -0
  37. ccai/testbase/debuggingext.py +281 -0
  38. ccai/testbase/debuglogging.py +407 -0
  39. ccai/testbase/debugports.py +469 -0
  40. ccai/testbase/declaration/__init__.py +13 -0
  41. ccai/testbase/declaration/attachments.py +222 -0
  42. ccai/testbase/declaration/originations.py +217 -0
  43. ccai/testbase/declaration/parameterization.py +160 -0
  44. ccai/testbase/declaration/registrations.py +476 -0
  45. ccai/testbase/diagnostic_level.py +197 -0
  46. ccai/testbase/diagnostic_streaming.py +1534 -0
  47. ccai/testbase/diagnostics.py +1685 -0
  48. ccai/testbase/entrypoints.py +485 -0
  49. ccai/testbase/environment.py +162 -0
  50. ccai/testbase/errors/testruntimeouterror.py +50 -0
  51. ccai/testbase/expressions.py +355 -0
  52. ccai/testbase/factories.py +277 -0
  53. ccai/testbase/factoryprotocols.py +35 -0
  54. ccai/testbase/features.py +913 -0
  55. ccai/testbase/initialize.py +210 -0
  56. ccai/testbase/injection/__init__.py +25 -0
  57. ccai/testbase/injection/injectiongroup.py +493 -0
  58. ccai/testbase/injection/injectionmoment.py +155 -0
  59. ccai/testbase/injection/injectionregistry.py +823 -0
  60. ccai/testbase/injection/injectionscope.py +2589 -0
  61. ccai/testbase/injection/introspection.py +514 -0
  62. ccai/testbase/markers.py +665 -0
  63. ccai/testbase/mocking.py +4856 -0
  64. ccai/testbase/origins/__init__.py +13 -0
  65. ccai/testbase/origins/resourceorigin.py +110 -0
  66. ccai/testbase/origins/validatororigin.py +111 -0
  67. ccai/testbase/output/__init__.py +17 -0
  68. ccai/testbase/output/outputcontext.py +201 -0
  69. ccai/testbase/output/runmetadata.py +184 -0
  70. ccai/testbase/properties/__init__.py +40 -0
  71. ccai/testbase/properties/assumptions.py +56 -0
  72. ccai/testbase/properties/decorators.py +173 -0
  73. ccai/testbase/properties/propertyrunner.py +449 -0
  74. ccai/testbase/properties/strategies.py +1592 -0
  75. ccai/testbase/properties/unittestsupport.py +87 -0
  76. ccai/testbase/py.typed +0 -0
  77. ccai/testbase/queries.py +95 -0
  78. ccai/testbase/resourcelifespan.py +24 -0
  79. ccai/testbase/results/__init__.py +35 -0
  80. ccai/testbase/results/exceptions.py +60 -0
  81. ccai/testbase/results/filtering/__init__.py +26 -0
  82. ccai/testbase/results/filtering/resultfilter.py +570 -0
  83. ccai/testbase/results/model/__init__.py +32 -0
  84. ccai/testbase/results/model/buildinfo.py +54 -0
  85. ccai/testbase/results/model/checkresult.py +183 -0
  86. ccai/testbase/results/model/forwardinginfo.py +30 -0
  87. ccai/testbase/results/model/jobcontainer.py +32 -0
  88. ccai/testbase/results/model/jobinfo.py +91 -0
  89. ccai/testbase/results/model/nestedprogressinfo.py +211 -0
  90. ccai/testbase/results/model/pipelineinfo.py +51 -0
  91. ccai/testbase/results/model/progressaggregator.py +551 -0
  92. ccai/testbase/results/model/progresscode.py +29 -0
  93. ccai/testbase/results/model/progressdelivery.py +51 -0
  94. ccai/testbase/results/model/progressinfo.py +84 -0
  95. ccai/testbase/results/model/progresstype.py +24 -0
  96. ccai/testbase/results/model/renderinfo.py +30 -0
  97. ccai/testbase/results/model/resultcode.py +28 -0
  98. ccai/testbase/results/model/resultcontainer.py +95 -0
  99. ccai/testbase/results/model/resultnode.py +258 -0
  100. ccai/testbase/results/model/resulttype.py +34 -0
  101. ccai/testbase/results/model/streaminginfo.py +111 -0
  102. ccai/testbase/results/model/taskinggroup.py +85 -0
  103. ccai/testbase/results/model/taskingresult.py +297 -0
  104. ccai/testbase/results/model/testcontainer.py +35 -0
  105. ccai/testbase/results/model/testresult.py +170 -0
  106. ccai/testbase/results/recorders/__init__.py +31 -0
  107. ccai/testbase/results/recorders/csvresultrecorder.py +414 -0
  108. ccai/testbase/results/recorders/jsonresultrecorder.py +467 -0
  109. ccai/testbase/results/recorders/resultrecorder.py +1472 -0
  110. ccai/testbase/results/recorders/stdoutresultrecorder.py +70 -0
  111. ccai/testbase/results/recorders/xmlresultrecorder.py +305 -0
  112. ccai/testbase/results/utilities.py +141 -0
  113. ccai/testbase/sequencing/__init__.py +13 -0
  114. ccai/testbase/sequencing/sequencermodulescope.py +96 -0
  115. ccai/testbase/sequencing/sequencerscopebase.py +91 -0
  116. ccai/testbase/sequencing/sequencersessionscope.py +84 -0
  117. ccai/testbase/sequencing/sequencertestscope.py +249 -0
  118. ccai/testbase/sequencing/sequencertestsetupscope.py +86 -0
  119. ccai/testbase/sequencing/testactivity.py +111 -0
  120. ccai/testbase/sequencing/testsequencer.py +3072 -0
  121. ccai/testbase/server/__init__.py +13 -0
  122. ccai/testbase/server/resultserver.py +599 -0
  123. ccai/testbase/sources/__init__.py +13 -0
  124. ccai/testbase/sources/configurationsource.py +32 -0
  125. ccai/testbase/sources/integrationsource.py +29 -0
  126. ccai/testbase/sources/resourcesource.py +27 -0
  127. ccai/testbase/sources/sourcebase.py +71 -0
  128. ccai/testbase/sources/unknownsource.py +30 -0
  129. ccai/testbase/sources/validatorsource.py +28 -0
  130. ccai/testbase/tandem/__init__.py +13 -0
  131. ccai/testbase/tandem/validators.py +286 -0
  132. ccai/testbase/testcollector.py +230 -0
  133. ccai/testbase/testgroup.py +54 -0
  134. ccai/testbase/testjob.py +600 -0
  135. ccai/testbase/testref.py +64 -0
  136. ccai/testbase/utilities.py +472 -0
  137. ccai/testbase/verification.py +768 -0
  138. codecraftai_testbase-1.3.0.dist-info/METADATA +99 -0
  139. codecraftai_testbase-1.3.0.dist-info/RECORD +142 -0
  140. codecraftai_testbase-1.3.0.dist-info/WHEEL +4 -0
  141. codecraftai_testbase-1.3.0.dist-info/entry_points.txt +3 -0
  142. codecraftai_testbase-1.3.0.dist-info/licenses/LICENSE.md +204 -0
@@ -0,0 +1,91 @@
1
+ """
2
+ .. module:: ccai.testbase.sequencing.sequencerscopebase
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module for sequencerscopebase.
5
+
6
+ .. moduleauthor:: Myron Walker <myron.walker@gmail.com>
7
+ """
8
+
9
+
10
+
11
+ __author__ = "Myron Walker"
12
+ __copyright__ = "Copyright 2025, Code Craft AI LLC"
13
+ __credits__ = []
14
+
15
+
16
+ from typing import TYPE_CHECKING
17
+
18
+ import uuid
19
+
20
+ from ccai.errors.xtraceback import TracebackDetail
21
+
22
+ from ccai.xmodules.xlogging.enhancedloggers import getEnhancedLogger
23
+
24
+ from ccai.testbase.results.recorders.resultrecorder import ResultRecorder
25
+ from ccai.testbase.testgroup import TestGroup
26
+ from ccai.testbase.testref import TestRef
27
+
28
+ if TYPE_CHECKING:
29
+ from ccai.testbase.sequencing.testsequencer import TestSequencer
30
+
31
+ logger = getEnhancedLogger()
32
+
33
+ class SequencerScopeBase:
34
+ """
35
+ Base context manager for all sequencer scope implementations.
36
+ """
37
+
38
+ def __init__(self, sequencer: "TestSequencer", recorder: ResultRecorder):
39
+ super().__init__()
40
+
41
+ self._sequencer = sequencer
42
+ self._recorder = recorder
43
+ return
44
+
45
+ def _mark_descendants_as_error(self, cursor, cursor_id, tbdetail):
46
+
47
+ for chkey in cursor.children:
48
+ child = cursor.children[chkey]
49
+ if not child.finalized:
50
+ if isinstance(child, TestRef):
51
+ self._mark_test_as_error(child, cursor_id, tbdetail)
52
+ elif isinstance(child, TestGroup):
53
+ scope_id = str(uuid.uuid4())
54
+ scope_name = child.scope_name
55
+ result = self._sequencer.create_test_result_container(scope_id, scope_name, parent_inst=cursor_id)
56
+ self._recorder.record(result)
57
+ self._mark_descendants_as_error(child, scope_id, tbdetail)
58
+
59
+ return
60
+
61
+ def _mark_descendants_skipped(self, cursor, cursor_id, reason, bug):
62
+
63
+ for chkey in cursor.children:
64
+ child = cursor.children[chkey]
65
+ if not child.finalized:
66
+ if isinstance(child, TestRef):
67
+ self._mark_test_as_skip(child, cursor_id, reason, bug)
68
+ elif isinstance(child, TestGroup):
69
+ scope_id = str(uuid.uuid4())
70
+ scope_name = child.scope_name
71
+ result = self._sequencer.create_test_result_container(scope_id, scope_name, parent_inst=cursor_id)
72
+ self._recorder.record(result)
73
+ self._mark_descendants_skipped(child, scope_id, reason, bug)
74
+
75
+ return
76
+
77
+ def _mark_test_as_error(self, testref: TestRef, parent_id: str, tbdetail: TracebackDetail):
78
+ test_id = str(uuid.uuid4())
79
+ result = self._sequencer.create_test_result_node(test_id, testref.name, testref.monikers, testref.pivots, parent_inst=parent_id)
80
+ result.add_error(tbdetail)
81
+ result.finalize()
82
+ self._recorder.record(result)
83
+ return
84
+
85
+ def _mark_test_as_skip(self, testref: TestRef, parent_id: str, reason: str, bug: str):
86
+ test_id = str(uuid.uuid4())
87
+ result = self._sequencer.create_test_result_node(test_id, testref.name, testref.monikers, testref.pivots, parent_inst=parent_id)
88
+ result.mark_skip(reason, bug)
89
+ result.finalize()
90
+ self._recorder.record(result)
91
+ return
@@ -0,0 +1,84 @@
1
+ """
2
+ .. module:: ccai.testbase.sequencing.sequencersessionscope
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module for sequencersessionscope.
5
+
6
+ .. moduleauthor:: Myron Walker <myron.walker@gmail.com>
7
+ """
8
+
9
+
10
+
11
+ __author__ = "Myron Walker"
12
+ __copyright__ = "Copyright 2025, Code Craft AI LLC"
13
+ __credits__ = []
14
+
15
+
16
+ from typing import Type, TYPE_CHECKING
17
+
18
+ import os
19
+
20
+ from types import TracebackType
21
+
22
+ from ccai.errors.exceptions import SkipError
23
+ from ccai.errors.xtraceback import create_traceback_detail, format_traceback_detail
24
+
25
+ from ccai.xmodules.xlogging.enhancedloggers import getEnhancedLogger
26
+
27
+ from ccai.testbase.results.recorders.resultrecorder import ResultRecorder
28
+ from ccai.testbase.results.model.jobcontainer import JobContainer
29
+ from ccai.testbase.sequencing.sequencerscopebase import SequencerScopeBase
30
+
31
+
32
+ logger = getEnhancedLogger()
33
+
34
+
35
+ if TYPE_CHECKING:
36
+ from ccai.testbase.sequencing.testsequencer import TestSequencer
37
+
38
+
39
+ class SequencerSessionScope(SequencerScopeBase):
40
+ """
41
+ Context manager for the root session scope of a test run.
42
+ """
43
+ def __init__(self, sequencer: "TestSequencer", recorder: ResultRecorder, root_result: JobContainer):
44
+ super().__init__(sequencer, recorder)
45
+
46
+ self._scope_name = root_result.name
47
+ self._scope_id = root_result.inst_id
48
+ self._root_result = root_result
49
+ self._scope_node = self._sequencer.testtree
50
+ return
51
+
52
+ def __enter__(self):
53
+ self._sequencer.scope_id_push(self._scope_name, self._scope_id)
54
+ logger.info("SESSION ENTER: {}".format(self._scope_id))
55
+ return self
56
+
57
+ def __exit__(self, ex_type: Type, ex_inst: BaseException, ex_tb: TracebackType) -> bool:
58
+ handled = False
59
+
60
+ if ex_type is not None:
61
+
62
+ if issubclass(ex_type, SkipError):
63
+ self._mark_descendants_skipped(self._scope_node, self._scope_id, ex_inst.reason, ex_inst.bug)
64
+ else:
65
+ tb_detail = create_traceback_detail(ex_inst)
66
+ self._mark_descendants_as_error(self._scope_node, self._scope_id, tb_detail)
67
+
68
+ # If an exceptions was thrown in this context, it means
69
+ # that the exception occured during the setup for this
70
+ # module, this means we need to mark all descendant tests
71
+ # as error'd due to a setup failure.
72
+ errmsg_lines = [
73
+ "Exception raises setting up scope='{}'".format(self._scope_name)
74
+ ]
75
+ errmsg_lines.extend(format_traceback_detail(tb_detail))
76
+ errmsg = os.linesep.join(errmsg_lines)
77
+ logger.error(errmsg)
78
+
79
+ handled = True
80
+
81
+ self._scope_node.finalize()
82
+ self._sequencer.scope_id_pop(self._scope_name)
83
+ logger.info("SESSION EXIT: {}".format(self._scope_id))
84
+ return handled
@@ -0,0 +1,249 @@
1
+ """
2
+ .. module:: ccai.testbase.sequencing.sequencertestscope
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module for sequencertestscope.
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 Any, List, Optional, Tuple, Type, TYPE_CHECKING
17
+
18
+ import os
19
+
20
+ from types import TracebackType
21
+
22
+ from collections import OrderedDict
23
+
24
+ from ccai.errors.exceptions import SkipError
25
+ from ccai.errors.xtraceback import create_traceback_detail, format_traceback_detail
26
+
27
+ from ccai.xmodules.xlogging.enhancedloggers import getEnhancedLogger
28
+
29
+ # Test-case by-products dir is resolved via the sequencer's injected IOutputContext.
30
+
31
+ from ccai.testbase.results.model.testresult import TestResult
32
+ from ccai.testbase.results.recorders.resultrecorder import ResultRecorder
33
+ from ccai.testbase.sequencing.testactivity import TestActivity
34
+
35
+ logger = getEnhancedLogger()
36
+
37
+
38
+ if TYPE_CHECKING:
39
+ from ccai.testbase.sequencing.testsequencer import TestSequencer
40
+
41
+
42
+ class SequencerTestScope:
43
+ """
44
+ Context manager for executing a single test function.
45
+ """
46
+
47
+ def __init__(self, sequencer: "TestSequencer", recorder: ResultRecorder, test_name: str,
48
+ notables: OrderedDict[str, Any]={}, expected_failure: dict = None):
49
+ super().__init__()
50
+
51
+ self._sequencer = sequencer
52
+ self._recorder = recorder
53
+ self._test_name = test_name
54
+ self._scope_id = None
55
+ self._parent_scope_id = None
56
+ self._result = None
57
+ self._scope_node = self._sequencer.find_treenode_for_scope(test_name)
58
+ self._notables = notables
59
+ self._expected_failure = expected_failure
60
+ self._monikers, self._pivots = self._get_monikers_and_pivots()
61
+ self._context_identifier = "{}:{}".format(self._test_name, ",".join(self._monikers))
62
+
63
+ self._tc_byproducts_folder = None
64
+ self._activity_stream_filename = None
65
+ return
66
+
67
+ @property
68
+ def recorder(self):
69
+ return self._recorder
70
+
71
+ @property
72
+ def result(self) -> Optional[TestResult]:
73
+ """
74
+ The :class:`TestResult` of this test scope. It is created when the scope is
75
+ entered and is ``None`` before that. The generated sequence document passes it
76
+ to :meth:`TestSequencer.run_property_test` so property metadata can be attached.
77
+ """
78
+ return self._result
79
+
80
+ @property
81
+ def scope_id(self):
82
+ return self._scope_id
83
+
84
+ @property
85
+ def test_name(self):
86
+ return self._test_name
87
+
88
+ def begin_activity(self, activity_name: str, target: str="NA", detail: Optional[dict] = None) -> TestActivity:
89
+ """
90
+ Mark the beginning of a test activity.
91
+ """
92
+ if not os.path.exists(self._tc_byproducts_folder):
93
+ os.makedirs(self._tc_byproducts_folder)
94
+
95
+ activity = TestActivity(self._activity_stream_filename, activity_name, target, detail=detail)
96
+
97
+ return activity
98
+
99
+ def mark_activity(self, activity_name: str, target: str="NA", detail: Optional[dict] = None):
100
+ """
101
+ Mark the beginning of a test activity.
102
+ """
103
+ if not os.path.exists(self._tc_byproducts_folder):
104
+ os.makedirs(self._tc_byproducts_folder)
105
+
106
+ activity = TestActivity(self._activity_stream_filename, activity_name, target, detail=detail)
107
+ activity.finalize()
108
+
109
+ return
110
+
111
+ def _get_monikers_and_pivots(self) -> Tuple[List[str], OrderedDict[str, Any]]:
112
+ """
113
+ Creates a full context identifier based on the full testname and the identifiers of any
114
+ parameterized parameters that are being passed to the test.
115
+ """
116
+
117
+ monikers = []
118
+ pivots = OrderedDict()
119
+
120
+ if len(self._notables) > 0:
121
+
122
+ for pname, pobj in self._notables.items():
123
+
124
+ # The attribute is used only when it is of the type this
125
+ # expects. A `hasattr` check alone is not enough: a mock that
126
+ # proxies every attribute answers it, and the proxy then fails
127
+ # the join below with 'sequence item 0: expected str instance'
128
+ # from inside the sequencer, naming nothing the test author
129
+ # would recognise. Test doubles that proxy attribute access are
130
+ # a common idiom, and attaching one is legitimate.
131
+ moniker = getattr(pobj, "moniker", None)
132
+ if isinstance(moniker, str):
133
+ monikers.append(moniker)
134
+ else:
135
+ monikers.append(str(pobj))
136
+
137
+ resource_pivots = getattr(pobj, "pivots", None)
138
+ if isinstance(resource_pivots, (dict, OrderedDict)):
139
+ pivots[pname] = resource_pivots
140
+ else:
141
+ pivots[pname] = str(pobj)
142
+
143
+ return monikers, pivots
144
+
145
+ def __enter__(self):
146
+ self._parent_scope_id, self._scope_id = self._sequencer.scope_id_create(self._context_identifier)
147
+ logger.info("TEST SCOPE ENTER: {}, {}".format(self._context_identifier, self._scope_id))
148
+
149
+ try:
150
+ self._tc_byproducts_folder = self._sequencer.output_context.get_testcase_byproducts_dir(self._scope_id)
151
+ self._activity_stream_filename = os.path.join(self._tc_byproducts_folder, "activity.jsos")
152
+
153
+ self._result = self._sequencer.create_test_result_node(self._scope_id, self._test_name, self._monikers, self._pivots, parent_inst=self._parent_scope_id)
154
+ self._recorder.preview(self._result)
155
+ self._test_scope_enter()
156
+ except BaseException:
157
+ # If __enter__ raises, Python never calls __exit__, so the scope
158
+ # id pushed above would be left on the stack. Every OUTER scope's
159
+ # pop would then fail its name check, burying the real error under
160
+ # a cascade of scope-stack RuntimeErrors. Pop what we pushed and
161
+ # let the true failure surface.
162
+ self._sequencer.scope_id_pop(self._context_identifier)
163
+ raise
164
+ return self
165
+
166
+ def __exit__(self, ex_type: Type, ex_inst: BaseException, ex_tb: TracebackType) -> bool:
167
+ handled = True
168
+
169
+ if self._expected_failure is not None:
170
+ # Expected failure handling: the @expect_exception decorator set
171
+ # metadata indicating this test should raise a specific exception.
172
+ expected_type = self._expected_failure.get("exception_type", AssertionError)
173
+ reason = self._expected_failure.get("reason", "")
174
+
175
+ if ex_type is not None and issubclass(ex_type, expected_type):
176
+ # The expected exception was raised — test passes.
177
+ # Individual check results (e.g., from PropertyRunner) are
178
+ # already recorded and may show as FAILED at the check level.
179
+ self._result.mark_passed()
180
+ if reason:
181
+ logger.info("EXPECTED EXCEPTION ({}): {}".format(expected_type.__name__, reason))
182
+ elif ex_type is None:
183
+ # No exception raised but one was expected — test fails.
184
+ msg = "Expected {} to be raised".format(expected_type.__name__)
185
+ if reason:
186
+ msg += " ({})".format(reason)
187
+ try:
188
+ raise AssertionError(msg)
189
+ except AssertionError as synth_err:
190
+ fail_detail = create_traceback_detail(synth_err)
191
+ self._result.add_failure(fail_detail)
192
+ logger.error(msg)
193
+ else:
194
+ # A different exception type was raised — test fails.
195
+ msg = "Expected {} but got {}: {}".format(
196
+ expected_type.__name__, ex_type.__name__, str(ex_inst))
197
+ try:
198
+ raise AssertionError(msg) from ex_inst
199
+ except AssertionError as synth_err:
200
+ fail_detail = create_traceback_detail(synth_err)
201
+ self._result.add_failure(fail_detail)
202
+ logger.error(msg)
203
+
204
+ handled = True
205
+ elif ex_type is not None:
206
+
207
+ if issubclass(ex_type, SkipError):
208
+ self._result.mark_skip(ex_inst.reason, ex_inst.bug)
209
+ else:
210
+ # If an exceptions was thrown in this context, it means
211
+ # that a test threw an exception.
212
+ tb_detail = create_traceback_detail(ex_inst)
213
+
214
+ if issubclass(ex_type, AssertionError):
215
+ # The convention for test failures that all tests should throw
216
+ # an AssertionError derived exception for failure conditions.
217
+ # This is important because a failure condition implies an expectation
218
+ # was checked and not met which implies a product code related failure
219
+
220
+ self._result.add_failure(tb_detail)
221
+ else:
222
+ self._result.add_error(tb_detail)
223
+
224
+ traceback_lines = format_traceback_detail(tb_detail)
225
+ errmsg = os.linesep.join(traceback_lines)
226
+ logger.error(errmsg)
227
+
228
+ handled = True
229
+ else:
230
+ self._result.mark_passed()
231
+
232
+ # Call test scope exit before we finalize our results
233
+ self._test_scope_exit()
234
+
235
+ self._result.finalize()
236
+ self._recorder.record(self._result)
237
+
238
+ self._scope_node.finalize()
239
+ self._sequencer.scope_id_pop(self._context_identifier)
240
+
241
+ logger.info("TEST SCOPE EXIT: {}, {}".format(self._context_identifier, self._scope_id))
242
+
243
+ return handled
244
+
245
+ def _test_scope_enter(self):
246
+ return
247
+
248
+ def _test_scope_exit(self):
249
+ return
@@ -0,0 +1,86 @@
1
+ """
2
+ .. module:: ccai.testbase.sequencing.sequencertestsetupscope
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module for sequencertestsetupscope.
5
+
6
+ .. moduleauthor:: Myron Walker <myron.walker@gmail.com>
7
+ """
8
+
9
+
10
+
11
+ __author__ = "Myron Walker"
12
+ __copyright__ = "Copyright 2025, Code Craft AI LLC"
13
+ __credits__ = []
14
+
15
+
16
+ from typing import TYPE_CHECKING
17
+
18
+ import os
19
+
20
+ from ccai.errors.xtraceback import create_traceback_detail, format_traceback_detail
21
+ from ccai.errors.exceptions import SkipError
22
+
23
+ from ccai.xmodules.xlogging.enhancedloggers import getEnhancedLogger
24
+
25
+ from ccai.testbase.results.recorders.resultrecorder import ResultRecorder
26
+ from ccai.testbase.sequencing.sequencerscopebase import SequencerScopeBase
27
+
28
+ logger = getEnhancedLogger()
29
+
30
+
31
+ if TYPE_CHECKING:
32
+ from ccai.testbase.sequencing.testsequencer import TestSequencer
33
+
34
+
35
+ class SequencerTestSetupScope(SequencerScopeBase):
36
+ """
37
+ Context manager that manages setup operations for a test scope.
38
+ """
39
+
40
+ def __init__(self, sequencer: "TestSequencer", recorder: ResultRecorder, test_name: str, **kwargs):
41
+ super().__init__(sequencer, recorder)
42
+
43
+ self._sequencer = sequencer
44
+ self._recorder = recorder
45
+ self._test_name = test_name
46
+ self._scope_name = "setup:{}".format(test_name)
47
+ self._scope_args = kwargs
48
+ self._scope_id = None
49
+ self._parent_scope_id = None
50
+ self._test_scope_node = self._sequencer.find_treenode_for_scope(test_name)
51
+ return
52
+
53
+ def __enter__(self):
54
+ self._parent_scope_id, self._scope_id = self._sequencer.scope_id_create(self._scope_name)
55
+ logger.info("TEST SETUP ENTER: {}, {}".format(self._scope_name, self._scope_id))
56
+ return self
57
+
58
+ def __exit__(self, ex_type, ex_inst, ex_tb):
59
+ handled = False
60
+
61
+ if ex_type is not None:
62
+
63
+ if issubclass(ex_type, SkipError):
64
+ self._mark_test_as_skip(self._test_scope_node, self._scope_id, ex_inst.reason, ex_inst.bug)
65
+ else:
66
+ tb_detail = create_traceback_detail(ex_inst)
67
+ self._mark_test_as_error(self._test_scope_node, self._scope_id, tb_detail)
68
+
69
+ # If an exceptions was thrown in this context, it means
70
+ # that the exception occured during the setup for this
71
+ # module, this means we need to mark all descendant tests
72
+ # as error'd due to a setup failure.
73
+ errmsg_lines = [
74
+ "Exception raises setting up scope='{}'".format(self._scope_name)
75
+ ]
76
+ errmsg_lines.extend(format_traceback_detail(tb_detail))
77
+ errmsg = os.linesep.join(errmsg_lines)
78
+ logger.error(errmsg)
79
+
80
+ handled = True
81
+
82
+
83
+ self._test_scope_node.finalize()
84
+ self._sequencer.scope_id_pop(self._scope_name)
85
+ logger.info("TEST SETUP EXIT: {}, {}".format(self._scope_name, self._scope_id))
86
+ return handled
@@ -0,0 +1,111 @@
1
+ """
2
+ .. module:: ccai.testbase.sequencing.testactivity
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module for testactivity.
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 Optional, Type
17
+
18
+ import json
19
+
20
+ from datetime import datetime
21
+
22
+ from ccai.xmodules.xdatetime import format_datetime_with_fractional
23
+ from ccai.xmodules.jsos import CHAR_RECORD_SEPERATOR
24
+
25
+ from types import TracebackType
26
+
27
+ class TestActivity:
28
+ """
29
+ Records the timing information for a test activity.
30
+ """
31
+
32
+ def __init__(self, activity_filename: str, activity_name: str, target: str, detail: Optional[dict]):
33
+ self._activity_filename = activity_filename
34
+ self._activity_name = activity_name
35
+ self._target = target
36
+ self._detail = detail
37
+
38
+ self._begin = datetime.now()
39
+ self._end = None
40
+ return
41
+
42
+ def __enter__(self):
43
+ return self
44
+
45
+ def __exit__(self, ex_type: Type, ex_inst: BaseException, ex_tb: TracebackType) -> bool:
46
+ self.finalize()
47
+ return False
48
+
49
+ @property
50
+ def activity_name(self) -> str:
51
+ return self._activity_name
52
+
53
+ @property
54
+ def begin(self) -> str:
55
+ return self._begin
56
+
57
+ @property
58
+ def detail(self) -> str:
59
+ return self._detail
60
+
61
+ @property
62
+ def end(self) -> str:
63
+ return self._end
64
+
65
+ @property
66
+ def target(self) -> str:
67
+ return self._target
68
+
69
+ def as_dict(self):
70
+ """
71
+ Convert the TestActivity object to a dictionary.
72
+ """
73
+
74
+ dobj = {
75
+ "activity-name": self._activity_name,
76
+ "detail": self._detail,
77
+ "target": self._target,
78
+ "begin": self._begin,
79
+ "end": self._end
80
+ }
81
+
82
+ return dobj
83
+
84
+ def as_json(self, indent=4):
85
+ """
86
+ Convert the TestActivity object to json.
87
+ """
88
+
89
+ dobj = self.as_dict()
90
+
91
+ dobj["begin"] = format_datetime_with_fractional(dobj["begin"])
92
+ if dobj["end"] is not None:
93
+ dobj["end"] = format_datetime_with_fractional(dobj["end"])
94
+
95
+ content = json.dumps(dobj, indent=indent)
96
+
97
+ return content
98
+
99
+ def finalize(self):
100
+ """
101
+ Finalize the activity.
102
+ """
103
+
104
+ self._end = datetime.now()
105
+
106
+ content = self.as_json()
107
+ with open(self._activity_filename, 'a+') as af:
108
+ af.write(CHAR_RECORD_SEPERATOR)
109
+ af.write(content)
110
+
111
+ return