Esempio n. 1
0
def test_check_compressed_and_extract_with_deep_folder_structure(
    tmpdir, file_name
):

    file = RESOURCE_PATH / file_name
    tmp_file = shutil.copy(str(file), str(tmpdir))
    tmp_file = Path(tmp_file)
    assert tmpdir.listdir() == [tmp_file]

    tmpdir_path = Path(tmpdir)
    check_compressed_and_extract(tmp_file, tmpdir_path)
    expected = [
        os.path.join(
            tmpdir_path,
            # 15 folders deep, each folder (except the last) 255 characters long, repeated numbers 0-9.
            # single png at the deepest folder
            f"{('1234567890'*26)[:-5]}/" * 14 + f"{('1234567890'*24)}/t.png",
        ),
    ]
    actual = []
    for root, _, files in os.walk(tmpdir_path):
        for file in files:
            actual.append(os.path.join(root, file))
    actual = sorted(actual)
    assert actual == expected
Esempio n. 2
0
def test_check_compressed_and_extract_with_symlink(tmpdir, file_name):

    file = RESOURCE_PATH / file_name
    tmp_file = shutil.copy(str(file), str(tmpdir))
    tmp_file = Path(tmp_file)
    assert tmpdir.listdir() == [tmp_file]

    tmpdir_path = Path(tmpdir)
    with pytest.raises(ValidationError):
        check_compressed_and_extract(tmp_file, tmpdir_path)
Esempio n. 3
0
def test_check_compressed_and_extract_same_name(tmpdir, file_name,
                                                double_zipped):
    file = RESOURCE_PATH / file_name
    tmp_file = shutil.copy(str(file), str(tmpdir))
    tmp_file = Path(tmp_file)
    assert tmpdir.listdir() == [tmp_file]
    tmpdir_path = Path(tmpdir)
    check_compressed_and_extract(src_path=tmp_file, checked_paths=set())
    expected = sorted(
        os.path.join(
            tmpdir_path,
            file_name,
            f"{x}.zip" if double_zipped else f"{x}/1",
            "test_grayscale.png",
        ) for x in range(1, 11))
    actual = []
    for root, _, files in os.walk(tmpdir_path):
        for file in files:
            actual.append(os.path.join(root, file))
    actual = sorted(actual)
    assert actual == expected
Esempio n. 4
0
def test_check_compressed_and_extract_same_name(tmpdir, file_name):
    file = RESOURCE_PATH / file_name
    tmp_file = shutil.copy(str(file), str(tmpdir))
    tmp_file = Path(tmp_file)
    assert tmpdir.listdir() == [tmp_file]
    file_basename, _ = os.path.splitext(file_name)
    tmpdir_path = Path(tmpdir)
    check_compressed_and_extract(tmp_file, tmpdir_path)
    expected = sorted(
        [
            os.path.join(
                tmpdir_path, file_basename, str(x), "1", "test_grayscale.png",
            )
            for x in range(1, 11)
        ]
    )
    actual = []
    for root, _, files in os.walk(tmpdir_path):
        for file in files:
            actual.append(os.path.join(root, file))
    actual = sorted(actual)
    assert actual == expected
Esempio n. 5
0
def test_check_compressed_and_extract(tmpdir):
    file_name = "test.zip"
    file = RESOURCE_PATH / file_name
    tmp_file = shutil.copy(str(file), str(tmpdir))
    tmp_file = Path(tmp_file)
    assert tmpdir.listdir() == [tmp_file]

    tmpdir_path = Path(tmpdir)
    check_compressed_and_extract(src_path=tmp_file, checked_paths=set())

    expected = [
        os.path.join(tmpdir_path, file_name, "file-0.txt"),
        os.path.join(tmpdir_path, file_name, "folder-1/file-1.txt"),
        os.path.join(tmpdir_path, file_name, "folder-1/folder-2/file-2.txt"),
        os.path.join(tmpdir_path, file_name,
                     "folder-1/folder-2/folder-3.zip/file-3.txt"),
    ]
    actual = []
    for root, _, files in os.walk(tmpdir_path):
        for file in files:
            actual.append(os.path.join(root, file))
    actual = sorted(actual)
    assert actual == expected