def compare_listing_text(listing_a, listing_b): listing_a_path_array = get_array_of_last_multiline_text_parts(listing_a) listing_b_path_array = get_array_of_last_multiline_text_parts(listing_b) # Assertion helper helpers.compare_list_content_ignoring_order(listing_a_path_array, listing_b_path_array)
def test_create_target_when_nonexistent(tmp_path): """Parents exist but target does not""" target_path = tmp_path / "target-dir" handle_destination_directory_creation(target_path) target_path_2 = tmp_path / "target-dir-2" handle_destination_directory_creation(target_path_2, FORCE) dir_listing = os.listdir(tmp_path) expected_listing = ["target-dir", "target-dir-2"] helpers.compare_list_content_ignoring_order(dir_listing, expected_listing)
def assert_archiving_splitting(path, max_size, expected_result): split_archive = split_directory(path, max_size) split_archive_relative_paths = relative_strings_from_archives_list( split_archive, path.parent) split_archive_relative_paths_flat = flatten_nested_list( split_archive_relative_paths) assert len(split_archive_relative_paths_flat) == len(expected_result) assert size_of_all_parts_below_maximum(split_archive, max_size) # Assertion helper compare_list_content_ignoring_order(split_archive_relative_paths_flat, expected_result)
def compare_listing_files(expected_path_list, actual_path_list): expected_union = [] actual_union = [] for path in expected_path_list: with open(path, "r") as listing_file: expected_union += get_array_of_last_multiline_text_parts( listing_file.read()) for path in actual_path_list: with open(path, "r") as listing_file: actual_union += get_array_of_last_multiline_text_parts( listing_file.read()) helpers.compare_list_content_ignoring_order(expected_union, actual_union)
def compare_hash_files(expected_path_list, actual_path_list): expected_hash_list = [] actual_hash_list = [] for path in expected_path_list: with open(path, "r") as hash_file: for line in hash_file: expected_hash_list.append(line.rstrip()) for path in actual_path_list: with open(path, "r") as hash_file: for line in hash_file: actual_hash_list.append(line.rstrip()) helpers.compare_list_content_ignoring_order(expected_hash_list, actual_hash_list)
def assert_successful_archive_creation(destination_path, archive_path, folder_name, split=None, encrypted=None, unencrypted=None): # Specify which files are expected in the listing expected_listing_suffixes = get_required_listing_suffixes( encrypted, unencrypted) # Will return unmodified given list if split is None expected_listing = add_split_prefix_to_file_suffixes( expected_listing_suffixes, split) if split: expected_listing += ['.parts.txt'] # Get all hash filesnames from expected listing hash_filenames = hash_filenames_from_list(expected_listing) dir_listing = os.listdir(destination_path) expected_named_listing = add_prefix_to_list_elements( expected_listing, folder_name) helpers.compare_list_content_ignoring_order(dir_listing, expected_named_listing) listing = SPLIT_CONTENT_LISTING if split else CONTENT_LISTING expected_listing_file_paths = create_full_filename_path( listing, archive_path, folder_name) actual_listing_file_paths = create_full_filename_path( listing, archive_path, folder_name) compare_listing_files(expected_listing_file_paths, actual_listing_file_paths) hash_file_paths = create_full_filename_path(hash_filenames, destination_path, folder_name) assert_hashes_in_file_list_valid(hash_file_paths) suffix = SPLIT_HASH_SUFFIX if split else HASH_SUFFIX expected_hash_file_paths = create_full_filename_path( suffix, archive_path, folder_name) actual_hash_file_paths = create_full_filename_path(suffix, destination_path, folder_name) compare_hash_files(expected_hash_file_paths, actual_hash_file_paths)
def assert_successful_action_to_destination(destination_path, archive_path, folder_name, split=None, encrypted=False): expected_listing_suffixes = [".tar.lz.gpg", ".tar.lz.gpg.md5" ] if encrypted else [".tar.lz"] expected_listing = add_split_prefix_to_file_suffixes( expected_listing_suffixes, split) hash_filenames = hash_filenames_from_list(expected_listing) dir_listing = os.listdir(destination_path) expected_named_listing = add_prefix_to_list_elements( expected_listing, folder_name) helpers.compare_list_content_ignoring_order(dir_listing, expected_named_listing) hash_file_paths = create_full_filename_path(hash_filenames, destination_path, folder_name) assert_hashes_in_file_list_valid(hash_file_paths)
def compare_text_file_ignoring_order(file_a_path, file_b_path): with open(file_a_path, "r") as file1, open(file_b_path, "r") as file2: helpers.compare_list_content_ignoring_order(file1.readlines(), file2.readlines())