tardisbase.testing.regression_comparison.file_manager module

class tardisbase.testing.regression_comparison.file_manager.FileManager(repo_path=None)[source]

Bases: object

A class for managing temporary directories and file operations for regression data comparisons.

This class provides a interface for creating and managing temporary directories, handling file copying operations, and maintaining consistent path management across the comparison workflow.

Parameters:

repo_path (str or Path, optional) – Path to the repository containing regression data, by default None. If None, uses the path specified in CONFIG[‘compare_path’].

copy_file(source, destination)[source]

Copy a file to the temporary directory with metadata preservation.

This method copies a file from the source location to a destination within the temporary directory, preserving file metadata including timestamps and permissions.

Parameters:
  • source (str or Path) – Path to the source file to be copied.

  • destination (str) – Relative path for the destination file within the temporary directory. The file will be copied to temp_dir/destination.

Notes

Uses shutil.copy2() to preserve file metadata including access and modification times. The destination path is automatically resolved relative to the temporary directory using get_temp_path().

get_temp_path(filename)[source]

Get the full path to a file or directory within the temporary directory.

Parameters:

filename (str) – Name of the file or subdirectory within the temporary directory.

Returns:

Full path to the specified file or directory within temp_dir.

Return type:

str

Notes

This method assumes that setup() has been called and temp_dir is available.

setup()[source]

Create a temporary directory for file operations.

This method creates a new temporary directory using the configured prefix and stores its path for use in subsequent operations. The directory name includes a prefix specified in CONFIG[‘temp_dir_prefix’].

Notes

The temporary directory path is stored in self.temp_dir and can be accessed using get_temp_path() for subdirectory operations. The directory should be cleaned up using teardown() when no longer needed.

Prints the path of the created temporary directory for logging purposes.

teardown()[source]

Remove the temporary directory and clean up resources.

This method safely removes the temporary directory and all its contents, resetting the temp_dir attribute to None. It includes safety checks to ensure the directory exists before attempting removal.

Notes

This method should be called after completing all file operations to ensure proper cleanup of temporary resources. It safely handles cases where the temporary directory doesn’t exist or has already been removed.

Prints confirmation of directory removal for logging purposes.

class tardisbase.testing.regression_comparison.file_manager.FileSetup(file_manager, ref1_hash, ref2_hash)[source]

Bases: object

A class for setting up reference files from git commits for comparison.

This class handles the extraction and setup of reference data from specific git commits or the current repository state, organizing them into separate directories for comparison operations.

Parameters:
  • file_manager (FileManager) – An instance of FileManager that provides temporary directory management.

  • ref1_hash (str or None) – Git commit hash for the first reference dataset. If None, the current repository state will be used.

  • ref2_hash (str or None) – Git commit hash for the second reference dataset. If None, the current repository state will be used.

setup()[source]

Set up reference directories with data from specified git commits.

This method creates separate directories (ref1, ref2) within the temporary directory and populates them with data from the specified git commits. If a commit hash is None, the current repository state is used instead.

Notes

The method creates two reference directories: - ref1: Contains data from ref1_hash commit (or current state if None) - ref2: Contains data from ref2_hash commit (or current state if None)

For git commits, uses ‘git archive’ to extract files efficiently. For current state, copies all files from the repository directory.