RUFAS.e2e_test_results_handler module#
- class RUFAS.e2e_test_results_handler.ResultPathType(domain, expected_results_path, actual_results_path, tolerance)#
Bases:
tuple
- _asdict()#
Return a new dict which maps field names to their values.
- _field_defaults = {}#
- _fields = ('domain', 'expected_results_path', 'actual_results_path', 'tolerance')#
- classmethod _make(iterable)#
Make a new ResultPathType object from a sequence or iterable
- _replace(**kwds)#
Return a new ResultPathType object replacing specified fields with new values
- actual_results_path#
Alias for field number 2
- domain#
Alias for field number 0
- expected_results_path#
Alias for field number 1
- tolerance#
Alias for field number 3
- class RUFAS.e2e_test_results_handler.E2ETestResultsHandler#
Bases:
object
Handles generating and comparing actual and expected results for end-to-end testing of various RuFaS modules.
- static compare_actual_and_expected_test_results(json_output_path: Path, convert_variable_table_path: str | None) None #
Orchestrates the comparison between the expected and actual end-to-end testing results.
Parameters#
- json_output_pathPath
Path to which JSON outputs are written to.
- convert_variable_table_pathstr | None
String path to the csv look up table to convert the variable names in the expected results to match the variable names in the actual results.
- static _convert_expected_result_variable_names(expected_results: dict[str, Any], conversion_csv_path: Path) dict[str, Any] #
Convert variable names in the expected_results dictionary using a CSV-based conversion table.
Parameters#
- expected_resultsdict[str, Any]
A dictionary where the keys represent the original variable names and the values are the associated data.
- conversion_csv_pathPath
The file path to the conversion CSV containing the mapping of original variable names to new variable names.
Returns#
- dict[str, Any]
A dictionary with updated keys based on the conversion mappings from the CSV. If a key in expected_results is not found in the mapping, it is preserved in the returned dictionary.
Raises#
- KeyError
Raised if the conversion table CSV does not contain both ‘Original’ and ‘New’ columns.
- ValueError
Raised if the conversion table CSV contains duplicate mappings for original variable names.
Notes#
Reads a CSV file containing mappings of original variable names to new variable names and applies these mappings to the keys in the given dictionary expected_results. The conversion table must contain two columns: ‘Original’ and ‘New’. Ensures no duplicate mappings exist in the CSV and raises appropriate errors otherwise. Returns a dictionary with updated keys while preserving their associated values.
- static _find_duplicate_mappings(mapping: DataFrame, group_column_name: str, list_column_name: str) dict[str, list[str]] #
Identifies entries in a DataFrame where a single key maps to multiple values.
Parameters#
- mappingpd.DataFrame
The DataFrame containing the mapping data. Must include the specified columns.
- group_column_namestr
The column to be analyzed for duplicate mappings.
- list_column_namestr
The column containing values that are mapped from ‘group_column_name’.
Returns#
- dict[str, list[str]]
A dictionary where each key is a duplicated entry from ‘group_column_name’, and each value is a list of corresponding mapped values from ‘list_column_name’.
Notes#
This method examines a DataFrame containing mappings between two columns and finds instances where a value in the ‘group_column_name’ column is associated with more than one unique value in the ‘list_column_name’ column.
- The result is a dictionary where:
Keys are the duplicated values from ‘group_column_name’.
Values are lists of corresponding values from ‘list_column_name’.
- static _duplicate_mappings_exist(mapping: DataFrame) bool #
Checks for duplicate mappings in the provided DataFrame and logs errors if any duplicates are found. This ensures that no original variable name maps to multiple new variable names, and no new variable name is mapped from multiple original variable names.
Parameters#
- mappingpd.DataFrame
A DataFrame containing the mappings between “Original” and “New” variable names.
Returns#
- bool
If any duplicate mappings are found, returns True. Otherwise, returns False.
- static _get_test_result_paths() list[ResultPathType] #
Retrieves the paths to test results and associated information from the InputManager.
- static is_significant(changes: dict[str, float | str], tolerance: float) bool #
Determines if a numerical change is significant based if the change between the “old_value” and “new_value” exceeds the specified tolerance.
Parameters#
- changesdict[str, float | str]
A dictionary representing changes with “old_value” and “new_value”.
- tolerancefloat
The threshold for considering a difference as significant.
Returns#
- bool
True if the change is both numerical and significant, False otherwise.
Notes#
The comparison is based on the absolute difference between the “old_value” and “new_value”, relative to the “old_value”. If the “old_value” is zero, a fallback reference value of 1 is used to ensure the tolerance comparison remains meaningful.
- static filter_nested(values_changed: dict[str, dict[str, float | str]], tolerance: float) None #
Recursively filters out insignificant numerical changes from a nested structure.
Parameters#
- values_changeddict[str, dict[str, float | str]]
The values_changed section of a DeepDiff result.
- tolerancefloat
The threshold for considering a difference as significant.
Notes#
This method modifies values_changed in place.
- static filter_insignificant_changes(diff_result: dict[str, dict[str, dict[str, float | str]]], tolerance: float) dict[str, dict[str, dict[str, float | str]]] #
Removes insignificant changes from a DeepDiff values_changed section.
Parameters#
- diff_resultdict[str, dict[str, dict[str, float | str]]]
The DeepDiff result to filter.
- tolerancefloat
The threshold for considering a difference as significant.
Returns#
- dict[str, dict[str, dict[str, float | str]]]
The filtered DeepDiff result.
- static update_expected_test_results(output_dir: Path) None #
Compares the actual end-to-end testing results for various RuFaS domains and updates the expected results in the appropriate domain filter file if differences are found.
Parameters#
- output_dirstr
The directory to which the actual results are written to.
- static _get_matching_path(dir_path: Path, path_set: ResultPathType) Path | None #
Returns the path that matches the path_set actual results path.
Parameters#
- dir_pathPath
The path to the directory.
- path_setResultPathType
ResultPathType object containing the domain, expected results path, actual results path, and tolerance.
Returns#
- Path
The matching path.