72 lines
No EOL
2.2 KiB
Python
72 lines
No EOL
2.2 KiB
Python
"""
|
|
Helper functions for QC checks.
|
|
"""
|
|
from typing import Dict, Any, List, Optional, Set, Tuple
|
|
|
|
def record_skipped_type(
|
|
skipped_types: Dict[str, Set[Tuple[str, Optional[str]]]],
|
|
check_name: str,
|
|
viewtype: str,
|
|
imagetype: Optional[str]
|
|
) -> None:
|
|
"""
|
|
Record a skipped viewtype/imagetype combination.
|
|
|
|
Args:
|
|
skipped_types: Dictionary to record skipped types in
|
|
check_name: Name of the check (e.g., 'image_format_check')
|
|
viewtype: The viewtype value that was skipped
|
|
imagetype: The imagetype value that was skipped (or None)
|
|
"""
|
|
if check_name not in skipped_types:
|
|
skipped_types[check_name] = set()
|
|
|
|
# Store the combination as a tuple
|
|
skipped_types[check_name].add((viewtype, imagetype))
|
|
|
|
def get_skipped_types_info(skipped_types: Dict[str, Set[Tuple[str, Optional[str]]]]) -> List[Dict[str, Any]]:
|
|
"""
|
|
Convert the skipped types dictionary to a format suitable for reporting.
|
|
|
|
Args:
|
|
skipped_types: Dictionary with recorded skipped types
|
|
|
|
Returns:
|
|
List of dictionaries with skipped type information
|
|
"""
|
|
result = []
|
|
|
|
for check_name, type_combinations in skipped_types.items():
|
|
for viewtype, imagetype in type_combinations:
|
|
result.append({
|
|
"check": check_name,
|
|
"viewtype": viewtype,
|
|
"imagetype": imagetype if imagetype is not None else "None"
|
|
})
|
|
|
|
return result
|
|
|
|
def prepare_skipped_result(
|
|
skipped_types: Dict[str, Set[Tuple[str, Optional[str]]]],
|
|
check_name: str
|
|
) -> Dict[str, Any]:
|
|
"""
|
|
Prepare a result dictionary for a check that encountered unknown types
|
|
but otherwise passed.
|
|
|
|
Args:
|
|
skipped_types: Dictionary with recorded skipped types
|
|
check_name: Name of the check
|
|
|
|
Returns:
|
|
Result dictionary with status "skipped_types" and skipped type details
|
|
"""
|
|
skipped_info = get_skipped_types_info({check_name: skipped_types[check_name]})
|
|
|
|
return {
|
|
"status": "passed",
|
|
"details": {
|
|
"message": f"Check passed, but {len(skipped_types[check_name])} unknown viewtype/imagetype combinations were skipped.",
|
|
"skipped_types": skipped_info
|
|
}
|
|
} |