Пример #1
0
def find_orphan_filenames_in_zipfile(filenames_known_about: Set,
                                     zip_file_path: str) -> Set[str]:
    """
    Find a set tof files that are in the zipfile that are not in the set of files already known about.  This set of
    'orphan' files is returned.  If there are no orphan files an empty set is returned

    Parameters
    ----------
    filenames_known_about : Set
        set of file names that are already known about, this set of files will be subtracted from the files in the
        zipfile.
    zip_file_path: str
        path to the zip file that a file list will be extracted from.

    Returns
    -------
    Set
        Set of files that are in the zip file but not in the filenames_known_about set.
    """
    files_in_zip = zip_file_reader.list_files_in_zip_file_from_a_directory(
        zip_file_path, 'assets', ['theme.css'])
    filenames_in_zip_asset_folder = {file.name for file in files_in_zip}
    orphans = filenames_in_zip_asset_folder - filenames_known_about

    return orphans
    def test_list_files_in_zip_file_get_files_bad_zip_file_name(
            self, zip_file_path):
        zip_file = 'hello-dlfjhsafl.zip'

        with pytest.raises(SystemExit):
            set_of_paths = zip_file_reader.list_files_in_zip_file_from_a_directory(
                zip_file,
                'zip_sub_folder/zip_sub_sub_folder/zip_sub_folder',
            )
    def test_list_files_in_zip_file_get_files_from_non_existing_directory(
            self, zip_file_path, caplog):
        zip_file = str(zip_file_path[0])

        expected = set()
        result = zip_file_reader.list_files_in_zip_file_from_a_directory(
            zip_file, 'hello')

        assert result == expected
        assert f'Directory ' in caplog.messages[0]
        assert caplog.records[0].levelname == 'WARNING'
    def test_list_files_in_zip_file_get_files_from_a_directory_ignore_single_file(
            self, zip_file_path):
        root_path = zip_file_path[1]
        zip_file = str(zip_file_path[0])

        expected = {
            str(Path(root_path, 'test.zip', 'zip_sub_folder', 'file2.txt')),
        }
        set_of_paths = zip_file_reader.list_files_in_zip_file_from_a_directory(
            zip_file, 'zip_sub_folder', ['file2b.txt'])
        result = {str(path) for path in set_of_paths}

        assert result == expected
    def test_list_files_in_zip_file_get_root_files_with_ignore_file_list(
            self, zip_file_path):
        root_path = zip_file_path[1]
        zip_file = str(zip_file_path[0])

        expected = {
            str(Path(root_path, 'test.zip', 'file1.txt')),
        }
        set_of_paths = zip_file_reader.list_files_in_zip_file_from_a_directory(
            zip_file, '', ['file1b.txt', 'file1c.txt'])
        result = {str(path) for path in set_of_paths}

        assert result == expected