def test_extract_archive_bad_tarfile_path_dir():
    with pytest.raises(exc.ImporterError,
                       match='Errno 2] No such file or directory'):
        collection._extract_archive(
            tarfile_path='dir-does-not-exist/file.tar.gz',
            extract_dir='/',
        )
def test_extract_archive_bad_tarfile_path_name(mock__import_collection):
    with pytest.raises(exc.ImporterError,
                       match='Cannot open: No such file or directory'):
        collection._extract_archive(
            tarfile_path='file-does-not-exist.tar.gz',
            extract_dir='/',
        )
def test_extract_archive(tmp_collection_root):
    tar_path = os.path.join(tmp_collection_root, 'test_archive.tar.gz')
    extract_path = os.path.join(tmp_collection_root, 'extract')
    os.makedirs(extract_path)

    with tarfile.open(tar_path, 'w') as tar:
        galaxy_yml_path = os.path.join(tmp_collection_root, 'galaxy.yml')
        with open(galaxy_yml_path, 'w'):
            pass
        tar.add(galaxy_yml_path, arcname='galaxy.yml')

    assert not os.path.isfile(os.path.join(extract_path, 'galaxy.yml'))
    collection._extract_archive(
        tarfile_path=tar_path,
        extract_dir=extract_path,
    )
    assert os.path.isfile(os.path.join(extract_path, 'galaxy.yml'))
def test_extract_archive(tmp_collection_root):
    tar_path = os.path.join(tmp_collection_root, "test_archive.tar.gz")
    extract_path = os.path.join(tmp_collection_root, "extract")
    os.makedirs(extract_path)

    with tarfile.open(tar_path, "w") as tar:
        galaxy_yml_path = os.path.join(tmp_collection_root, "galaxy.yml")
        with open(galaxy_yml_path, "w"):
            pass
        tar.add(galaxy_yml_path, arcname="galaxy.yml")

    assert not os.path.isfile(os.path.join(extract_path, "galaxy.yml"))
    collection._extract_archive(
        tarfile_path=tar_path,
        extract_dir=extract_path,
    )
    assert os.path.isfile(os.path.join(extract_path, "galaxy.yml"))