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,570 @@
1
+ """
2
+ .. module:: ccai.testbase.results.filtering.resultfilter
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module for result filtering and search functionality.
5
+
6
+ This module provides functionality to filter and search test results based on
7
+ various criteria including status, time range, metadata, and full-text search
8
+ in result details.
9
+
10
+ .. moduleauthor:: Myron Walker <myron.walker@gmail.com>
11
+ """
12
+
13
+ __author__ = "Myron Walker"
14
+ __copyright__ = "Copyright 2025, Code Craft AI LLC"
15
+ __credits__ = []
16
+
17
+
18
+ from typing import Any, Dict, List, Optional
19
+ from dataclasses import dataclass
20
+ from datetime import datetime
21
+ import re
22
+
23
+
24
+ @dataclass
25
+ class ResultFilterCriteria:
26
+ """
27
+ Dataclass representing filter criteria for result filtering.
28
+
29
+ This class encapsulates all possible filter criteria that can be applied
30
+ to test results. Multiple criteria can be combined for complex filtering.
31
+
32
+ Attributes:
33
+ status_codes: List of result status codes to include (e.g., ["PASSED", "FAILED"])
34
+ start_time_min: Minimum start time for results (inclusive)
35
+ start_time_max: Maximum start time for results (inclusive)
36
+ stop_time_min: Minimum stop time for results (inclusive)
37
+ stop_time_max: Maximum stop time for results (inclusive)
38
+ name_pattern: Regex pattern to match against result names
39
+ metadata_filters: Dictionary of metadata key-value pairs to match
40
+ result_types: List of result types to include (e.g., ["TEST", "TASKING"])
41
+
42
+ Example::
43
+
44
+ # Filter for failed tests in a specific time range
45
+ criteria = ResultFilterCriteria(
46
+ status_codes=["FAILED", "ERRORED"],
47
+ start_time_min=datetime(2025, 1, 1),
48
+ start_time_max=datetime(2025, 1, 31)
49
+ )
50
+ """
51
+ status_codes: Optional[List[str]] = None
52
+ start_time_min: Optional[datetime] = None
53
+ start_time_max: Optional[datetime] = None
54
+ stop_time_min: Optional[datetime] = None
55
+ stop_time_max: Optional[datetime] = None
56
+ name_pattern: Optional[str] = None
57
+ metadata_filters: Optional[Dict[str, Any]] = None
58
+ result_types: Optional[List[str]] = None
59
+
60
+
61
+ class ResultFilter:
62
+ """
63
+ Class for filtering test results based on various criteria.
64
+
65
+ The ResultFilter provides methods to filter a list of result dictionaries
66
+ based on status codes, time ranges, name patterns, metadata, and result types.
67
+ It also supports full-text search within result details.
68
+
69
+ FILTERING ALGORITHM:
70
+ ====================
71
+ The filter applies criteria in the following order:
72
+ 1. Result type filter (if specified)
73
+ 2. Status code filter (if specified)
74
+ 3. Time range filters (start_time_min/max, stop_time_min/max)
75
+ 4. Name pattern filter (regex matching)
76
+ 5. Metadata filters (key-value matching)
77
+
78
+ All criteria are combined with AND logic - a result must match ALL
79
+ specified criteria to be included in the output.
80
+
81
+ Thread Safety:
82
+ The ResultFilter is stateless and thread-safe. Multiple threads can
83
+ use the same filter instance concurrently without synchronization.
84
+
85
+ Usage Example::
86
+
87
+ from ccai.testbase.results.filtering import ResultFilter, ResultFilterCriteria
88
+
89
+ # Create filter with criteria
90
+ criteria = ResultFilterCriteria(
91
+ status_codes=["FAILED"],
92
+ name_pattern="test_.*integration.*"
93
+ )
94
+ result_filter = ResultFilter(criteria)
95
+
96
+ # Apply filter to results
97
+ filtered = result_filter.filter(results)
98
+
99
+ # Or use full-text search
100
+ search_results = result_filter.search(results, "connection timeout")
101
+ """
102
+
103
+ def __init__(self, criteria: Optional[ResultFilterCriteria] = None):
104
+ """
105
+ Initializes a ResultFilter with optional filter criteria.
106
+
107
+ :param criteria: Optional ResultFilterCriteria instance containing
108
+ filter parameters. If None, no filtering is applied.
109
+ """
110
+ self._criteria = criteria if criteria is not None else ResultFilterCriteria()
111
+ return
112
+
113
+ @property
114
+ def criteria(self) -> ResultFilterCriteria:
115
+ """
116
+ Returns the current filter criteria.
117
+
118
+ :returns: The ResultFilterCriteria instance used by this filter.
119
+ """
120
+ return self._criteria
121
+
122
+ def filter(self, results: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
123
+ """
124
+ Filters a list of result dictionaries based on the configured criteria.
125
+
126
+ This method applies all configured filter criteria to the input results
127
+ and returns only those results that match ALL criteria (AND logic).
128
+
129
+ :param results: List of result dictionaries to filter. Each dictionary
130
+ should contain keys like 'name', 'result', 'rtype',
131
+ 'start', 'stop', and optionally 'detail'.
132
+
133
+ :returns: List of result dictionaries that match all filter criteria.
134
+ """
135
+ filtered_results = []
136
+
137
+ for result in results:
138
+ if self._matches_criteria(result):
139
+ filtered_results.append(result)
140
+
141
+ return filtered_results
142
+
143
+ def search(self, results: List[Dict[str, Any]], search_text: str,
144
+ case_sensitive: bool = False) -> List[Dict[str, Any]]:
145
+ """
146
+ Performs full-text search within result details.
147
+
148
+ This method searches for the specified text within result names,
149
+ error messages, failure messages, and warning messages. Results
150
+ that contain the search text in any of these fields are returned.
151
+
152
+ :param results: List of result dictionaries to search.
153
+ :param search_text: Text to search for within result details.
154
+ :param case_sensitive: If True, search is case-sensitive. Default is False.
155
+
156
+ :returns: List of result dictionaries containing the search text.
157
+ """
158
+ matching_results = []
159
+
160
+ for result in results:
161
+ if self._contains_search_text(result, search_text, case_sensitive):
162
+ matching_results.append(result)
163
+
164
+ return matching_results
165
+
166
+ def filter_and_search(self, results: List[Dict[str, Any]], search_text: Optional[str] = None,
167
+ case_sensitive: bool = False) -> List[Dict[str, Any]]:
168
+ """
169
+ Combines filtering and searching in a single operation.
170
+
171
+ This method first applies filter criteria, then performs full-text
172
+ search on the filtered results (if search_text is provided).
173
+
174
+ :param results: List of result dictionaries to process.
175
+ :param search_text: Optional text to search for after filtering.
176
+ :param case_sensitive: If True, search is case-sensitive. Default is False.
177
+
178
+ :returns: List of result dictionaries matching both filter and search criteria.
179
+ """
180
+ filtered = self.filter(results)
181
+
182
+ if search_text:
183
+ filtered = self.search(filtered, search_text, case_sensitive)
184
+
185
+ return filtered
186
+
187
+ def _matches_criteria(self, result: Dict[str, Any]) -> bool:
188
+ """
189
+ Checks if a single result matches all configured filter criteria.
190
+
191
+ :param result: Result dictionary to check.
192
+
193
+ :returns: True if the result matches all criteria, False otherwise.
194
+ """
195
+ # Check result type filter
196
+ if self._criteria.result_types is not None:
197
+ result_type = result.get("rtype", "")
198
+ if result_type not in self._criteria.result_types:
199
+ return False
200
+
201
+ # Check status code filter
202
+ if self._criteria.status_codes is not None:
203
+ result_code = result.get("result", "")
204
+ if result_code not in self._criteria.status_codes:
205
+ return False
206
+
207
+ # Check start time range
208
+ if not self._matches_time_range(result, "start",
209
+ self._criteria.start_time_min,
210
+ self._criteria.start_time_max):
211
+ return False
212
+
213
+ # Check stop time range
214
+ if not self._matches_time_range(result, "stop",
215
+ self._criteria.stop_time_min,
216
+ self._criteria.stop_time_max):
217
+ return False
218
+
219
+ # Check name pattern
220
+ if self._criteria.name_pattern is not None:
221
+ name = result.get("name", "")
222
+ if not re.search(self._criteria.name_pattern, name):
223
+ return False
224
+
225
+ # Check metadata filters
226
+ if self._criteria.metadata_filters is not None:
227
+ if not self._matches_metadata(result):
228
+ return False
229
+
230
+ return True
231
+
232
+ def _matches_time_range(self, result: Dict[str, Any], time_field: str,
233
+ min_time: Optional[datetime],
234
+ max_time: Optional[datetime]) -> bool:
235
+ """
236
+ Checks if a result's timestamp falls within the specified range.
237
+
238
+ :param result: Result dictionary containing the timestamp.
239
+ :param time_field: Name of the timestamp field ('start' or 'stop').
240
+ :param min_time: Minimum time (inclusive), or None for no minimum.
241
+ :param max_time: Maximum time (inclusive), or None for no maximum.
242
+
243
+ :returns: True if the timestamp is within range, False otherwise.
244
+ """
245
+ if min_time is None and max_time is None:
246
+ return True
247
+
248
+ time_value = result.get(time_field, "")
249
+ if not time_value:
250
+ # If no time value and we have a filter, exclude the result
251
+ return min_time is None and max_time is None
252
+
253
+ # Parse the timestamp if it's a string
254
+ if isinstance(time_value, str):
255
+ try:
256
+ time_value = datetime.fromisoformat(time_value)
257
+ except ValueError:
258
+ return False
259
+ elif not isinstance(time_value, datetime):
260
+ return False
261
+
262
+ # Check minimum time
263
+ if min_time is not None and time_value < min_time:
264
+ return False
265
+
266
+ # Check maximum time
267
+ if max_time is not None and time_value > max_time:
268
+ return False
269
+
270
+ return True
271
+
272
+ def _matches_metadata(self, result: Dict[str, Any]) -> bool:
273
+ """
274
+ Checks if a result matches all metadata filter criteria.
275
+
276
+ Metadata filters can match against top-level result fields,
277
+ nested detail fields, monikers, and pivots.
278
+
279
+ :param result: Result dictionary to check.
280
+
281
+ :returns: True if all metadata filters match, False otherwise.
282
+ """
283
+ if self._criteria.metadata_filters is None:
284
+ return True
285
+
286
+ for key, expected_value in self._criteria.metadata_filters.items():
287
+ # Check top-level fields
288
+ if key in result:
289
+ if not self._value_matches(result[key], expected_value):
290
+ return False
291
+ continue
292
+
293
+ # Check in detail section
294
+ detail = result.get("detail", {})
295
+ if key in detail:
296
+ if not self._value_matches(detail[key], expected_value):
297
+ return False
298
+ continue
299
+
300
+ # Check in monikers (list membership)
301
+ if key == "moniker":
302
+ monikers = result.get("monikers", [])
303
+ if expected_value not in monikers:
304
+ return False
305
+ continue
306
+
307
+ # Check in pivots
308
+ pivots = result.get("pivots", {})
309
+ if key in pivots:
310
+ if not self._value_matches(pivots[key], expected_value):
311
+ return False
312
+ continue
313
+
314
+ # Key not found in any location - filter fails
315
+ return False
316
+
317
+ return True
318
+
319
+ def _value_matches(self, actual: Any, expected: Any) -> bool:
320
+ """
321
+ Checks if an actual value matches an expected value.
322
+
323
+ Supports exact matching, regex matching for strings, and
324
+ list membership checking.
325
+
326
+ :param actual: The actual value from the result.
327
+ :param expected: The expected value from the filter.
328
+
329
+ :returns: True if values match, False otherwise.
330
+ """
331
+ # Handle regex patterns for string values
332
+ if isinstance(expected, str) and isinstance(actual, str):
333
+ # Try regex match first
334
+ try:
335
+ if re.search(expected, actual):
336
+ return True
337
+ except re.error:
338
+ # The expected value is not a valid regex; treat it as a literal and
339
+ # fall through to the exact-match comparison below.
340
+ pass
341
+ # Fall back to exact match
342
+ return actual == expected
343
+
344
+ # Handle list membership
345
+ if isinstance(actual, list):
346
+ return expected in actual
347
+
348
+ # Exact match for other types
349
+ return actual == expected
350
+
351
+ def _contains_search_text(self, result: Dict[str, Any], search_text: str,
352
+ case_sensitive: bool) -> bool:
353
+ """
354
+ Checks if a result contains the search text in any searchable field.
355
+
356
+ Searchable fields include:
357
+ - name: Result name
358
+ - detail.errors: Error messages and tracebacks
359
+ - detail.failures: Failure messages and tracebacks
360
+ - detail.warnings: Warning messages
361
+ - detail.documentation: Documentation string
362
+
363
+ :param result: Result dictionary to search.
364
+ :param search_text: Text to search for.
365
+ :param case_sensitive: If True, search is case-sensitive.
366
+
367
+ :returns: True if search text is found, False otherwise.
368
+ """
369
+ if not case_sensitive:
370
+ search_text = search_text.lower()
371
+
372
+ # Search in name
373
+ name = result.get("name", "")
374
+ if self._text_in_string(name, search_text, case_sensitive):
375
+ return True
376
+
377
+ # Search in detail section
378
+ detail = result.get("detail", {})
379
+
380
+ # Search in errors
381
+ errors = detail.get("errors", [])
382
+ if self._search_in_traceback_list(errors, search_text, case_sensitive):
383
+ return True
384
+
385
+ # Search in failures
386
+ failures = detail.get("failures", [])
387
+ if self._search_in_traceback_list(failures, search_text, case_sensitive):
388
+ return True
389
+
390
+ # Search in warnings
391
+ warnings = detail.get("warnings", [])
392
+ if self._search_in_nested_list(warnings, search_text, case_sensitive):
393
+ return True
394
+
395
+ # Search in documentation
396
+ documentation = detail.get("documentation", "")
397
+ if documentation and self._text_in_string(documentation, search_text, case_sensitive):
398
+ return True
399
+
400
+ return False
401
+
402
+ def _text_in_string(self, text: str, search_text: str, case_sensitive: bool) -> bool:
403
+ """
404
+ Checks if search text is contained in a string.
405
+
406
+ :param text: String to search in.
407
+ :param search_text: Text to search for.
408
+ :param case_sensitive: If True, search is case-sensitive.
409
+
410
+ :returns: True if search text is found, False otherwise.
411
+ """
412
+ if not case_sensitive:
413
+ text = text.lower()
414
+ return search_text in text
415
+
416
+ def _search_in_traceback_list(self, traceback_list: List[Any], search_text: str,
417
+ case_sensitive: bool) -> bool:
418
+ """
419
+ Searches for text within a list of traceback details.
420
+
421
+ Traceback details can be dictionaries with 'extype', 'exargs', and 'traces'
422
+ fields, or simple strings.
423
+
424
+ :param traceback_list: List of traceback details to search.
425
+ :param search_text: Text to search for.
426
+ :param case_sensitive: If True, search is case-sensitive.
427
+
428
+ :returns: True if search text is found, False otherwise.
429
+ """
430
+ for tb in traceback_list:
431
+ if isinstance(tb, dict):
432
+ # Search in exception type
433
+ extype = tb.get("extype", "")
434
+ if self._text_in_string(str(extype), search_text, case_sensitive):
435
+ return True
436
+
437
+ # Search in exception arguments
438
+ exargs = tb.get("exargs", [])
439
+ for arg in exargs:
440
+ if self._text_in_string(str(arg), search_text, case_sensitive):
441
+ return True
442
+
443
+ # Search in traces
444
+ traces = tb.get("traces", [])
445
+ for trace in traces:
446
+ if isinstance(trace, dict):
447
+ # Search in call
448
+ call = trace.get("call", "")
449
+ if self._text_in_string(str(call), search_text, case_sensitive):
450
+ return True
451
+
452
+ # Search in code lines
453
+ code = trace.get("code", [])
454
+ for line in code:
455
+ if self._text_in_string(str(line), search_text, case_sensitive):
456
+ return True
457
+
458
+ # Search in origin
459
+ origin = trace.get("origin", {})
460
+ if isinstance(origin, dict):
461
+ for value in origin.values():
462
+ if self._text_in_string(str(value), search_text, case_sensitive):
463
+ return True
464
+ elif isinstance(tb, str):
465
+ if self._text_in_string(tb, search_text, case_sensitive):
466
+ return True
467
+
468
+ return False
469
+
470
+ def _search_in_nested_list(self, nested_list: List[Any], search_text: str,
471
+ case_sensitive: bool) -> bool:
472
+ """
473
+ Searches for text within a nested list structure.
474
+
475
+ :param nested_list: Nested list to search.
476
+ :param search_text: Text to search for.
477
+ :param case_sensitive: If True, search is case-sensitive.
478
+
479
+ :returns: True if search text is found, False otherwise.
480
+ """
481
+ for item in nested_list:
482
+ if isinstance(item, list):
483
+ if self._search_in_nested_list(item, search_text, case_sensitive):
484
+ return True
485
+ elif isinstance(item, str):
486
+ if self._text_in_string(item, search_text, case_sensitive):
487
+ return True
488
+
489
+ return False
490
+
491
+
492
+ def filter_results(results: List[Dict[str, Any]],
493
+ status_codes: Optional[List[str]] = None,
494
+ start_time_min: Optional[datetime] = None,
495
+ start_time_max: Optional[datetime] = None,
496
+ stop_time_min: Optional[datetime] = None,
497
+ stop_time_max: Optional[datetime] = None,
498
+ name_pattern: Optional[str] = None,
499
+ metadata_filters: Optional[Dict[str, Any]] = None,
500
+ result_types: Optional[List[str]] = None) -> List[Dict[str, Any]]:
501
+ """
502
+ Convenience function to filter results with specified criteria.
503
+
504
+ This function creates a ResultFilter with the specified criteria and
505
+ applies it to the input results. It provides a simpler interface for
506
+ one-off filtering operations.
507
+
508
+ :param results: List of result dictionaries to filter.
509
+ :param status_codes: List of result status codes to include.
510
+ :param start_time_min: Minimum start time for results.
511
+ :param start_time_max: Maximum start time for results.
512
+ :param stop_time_min: Minimum stop time for results.
513
+ :param stop_time_max: Maximum stop time for results.
514
+ :param name_pattern: Regex pattern to match against result names.
515
+ :param metadata_filters: Dictionary of metadata key-value pairs to match.
516
+ :param result_types: List of result types to include.
517
+
518
+ :returns: List of result dictionaries matching all criteria.
519
+
520
+ Example::
521
+
522
+ # Filter for failed tests
523
+ failed_tests = filter_results(results, status_codes=["FAILED"])
524
+
525
+ # Filter for tests in a time range
526
+ recent_tests = filter_results(
527
+ results,
528
+ start_time_min=datetime(2025, 2, 1),
529
+ start_time_max=datetime(2025, 2, 28)
530
+ )
531
+ """
532
+ criteria = ResultFilterCriteria(
533
+ status_codes=status_codes,
534
+ start_time_min=start_time_min,
535
+ start_time_max=start_time_max,
536
+ stop_time_min=stop_time_min,
537
+ stop_time_max=stop_time_max,
538
+ name_pattern=name_pattern,
539
+ metadata_filters=metadata_filters,
540
+ result_types=result_types
541
+ )
542
+
543
+ result_filter = ResultFilter(criteria)
544
+ return result_filter.filter(results)
545
+
546
+
547
+ def search_results(results: List[Dict[str, Any]], search_text: str,
548
+ case_sensitive: bool = False) -> List[Dict[str, Any]]:
549
+ """
550
+ Convenience function to search for text within results.
551
+
552
+ This function performs full-text search within result names, error messages,
553
+ failure messages, and warning messages.
554
+
555
+ :param results: List of result dictionaries to search.
556
+ :param search_text: Text to search for within result details.
557
+ :param case_sensitive: If True, search is case-sensitive. Default is False.
558
+
559
+ :returns: List of result dictionaries containing the search text.
560
+
561
+ Example::
562
+
563
+ # Search for connection errors
564
+ connection_errors = search_results(results, "connection refused")
565
+
566
+ # Case-sensitive search
567
+ specific_errors = search_results(results, "ValueError", case_sensitive=True)
568
+ """
569
+ result_filter = ResultFilter()
570
+ return result_filter.search(results, search_text, case_sensitive)
@@ -0,0 +1,32 @@
1
+ """
2
+ .. module:: ccai.testbase.results.model
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module for model.
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
+
14
+ from ccai.testbase.results.model.jobinfo import MissingOptionalFieldWarning
15
+ from ccai.testbase.results.model.checkresult import CheckResult
16
+ from ccai.testbase.results.model.streaminginfo import (
17
+ StreamingInfo,
18
+ StreamingProtocol,
19
+ StreamingCallback
20
+ )
21
+ from ccai.testbase.results.model.nestedprogressinfo import NestedProgressInfo
22
+ from ccai.testbase.results.model.progressaggregator import ProgressAggregator
23
+
24
+ __all__ = [
25
+ "CheckResult",
26
+ "MissingOptionalFieldWarning",
27
+ "NestedProgressInfo",
28
+ "ProgressAggregator",
29
+ "StreamingInfo",
30
+ "StreamingProtocol",
31
+ "StreamingCallback"
32
+ ]
@@ -0,0 +1,54 @@
1
+ """
2
+ .. module:: ccai.testbase.results.model.buildinfo
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module for buildinfo.
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 dataclasses import dataclass
18
+
19
+
20
+ @dataclass
21
+ class BuildInfo:
22
+ """
23
+ Information describing a build under test.
24
+
25
+ All fields are required and must be non-empty strings. Validation is
26
+ performed automatically after initialization.
27
+
28
+ :raises ValueError: If any required field is None or an empty string.
29
+ """
30
+
31
+ branch: str # name of a code 'branch' to associate with the results.
32
+ build: str # name of a product 'build' to associate with the results
33
+ flavor: str # label that indicates the flavor of build the automation is running against.
34
+ release: str # name of a release to associate a automation run with.
35
+ url: str # build url
36
+
37
+ def __post_init__(self):
38
+ """
39
+ Validates that all required fields are present and non-empty.
40
+
41
+ This method is called automatically by the dataclass after __init__.
42
+ It ensures that all BuildInfo fields contain valid, non-empty string values.
43
+
44
+ :raises ValueError: If any required field is None or an empty string.
45
+ The error message includes the name of the invalid field.
46
+ """
47
+ required_fields = ['branch', 'build', 'flavor', 'release', 'url']
48
+
49
+ for field_name in required_fields:
50
+ value = getattr(self, field_name)
51
+ if value is None or (isinstance(value, str) and value.strip() == ''):
52
+ raise ValueError(
53
+ f"BuildInfo field '{field_name}' is required and cannot be None or empty."
54
+ )