Пример #1
0
def test_download_file_md5_mismatch(tmpdir, test_image_url):
    with pytest.raises(RuntimeError):
        misc.download_file(
            test_image_url,
            path.join(tmpdir, path.basename(test_image_url)),
            md5="invalidmd5",
        )
Пример #2
0
    def test_response_code(self, mocker, test_image_url, code, reason):
        side_effect = HTTPError(test_image_url, code, reason, {}, None)
        mocker.patch(make_mock_target("misc", "urlopen"),
                     side_effect=side_effect)

        with pytest.raises(RuntimeError):
            misc.download_file(test_image_url)
Пример #3
0
def test_download_file(tmpdir, test_image_url, test_image):
    file = path.join(tmpdir, path.basename(test_image_url))
    misc.download_file(test_image_url,
                       file,
                       md5="a858d33c424eaac1322cf3cab6d3d568")

    actual = read_image(file)
    desired = test_image
    ptu.assert_allclose(actual, desired)
Пример #4
0
    def download():
        nonlocal extension
        nonlocal plot_gallery

        # version and release are available as soon as the project config is loaded
        version = globals()["version"]
        release = globals()["release"]

        base = "https://download.pystiche.org/galleries/"
        is_dev = version != release
        file = "master.zip" if is_dev else f"v{version}.zip"

        url = urljoin(base, file)
        print(f"Downloading pre-built galleries from {url}")
        download_file(url, file)

        with contextlib.suppress(FileNotFoundError):
            shutil.rmtree(path.join(HERE, "galleries"))
        shutil.unpack_archive(file, extract_dir=".")
        os.remove(file)

        extension = "sphinx_gallery.load_style"
        plot_gallery = False
Пример #5
0
}

# -- sphinx-gallery configuration ------------------------------------------------------

plot_gallery = get_bool_env_var("PYSTICHE_PLOT_GALLERY",
                                default=True) and not run_by_ci
download_gallery = get_bool_env_var("PYSTICHE_DOWNLOAD_GALLERY") or run_by_ci

if download_gallery:
    base = "https://download.pystiche.org/galleries/"
    is_dev = version != release
    file = "master.zip" if is_dev else f"v{version}.zip"

    url = urljoin(base, file)
    print(f"Downloading pre-built galleries from {url}")
    download_file(url, file)

    try:
        shutil.rmtree("galleries")
    except FileNotFoundError:
        pass
    shutil.unpack_archive(file, extract_dir=".")
    os.remove(file)

    extensions.remove("sphinx_gallery.gen_gallery")
    extensions.append("sphinx_gallery.load_style")
    plot_gallery = False

if plot_gallery and not torch.cuda.is_available():
    msg = ("The galleries will be built, but CUDA is not available. "
           "This will take a long time.")
Пример #6
0
 def _download(file: str) -> None:
     os.makedirs(path.dirname(file), exist_ok=True)
     download_file(self.url, file=file, md5=self.md5)
Пример #7
0
def test_download_file_user_agent(tmpdir, test_image_url, test_image):
    file = path.join(tmpdir, path.basename(test_image_url))
    with pytest.warns(UserWarning):
        misc.download_file(test_image_url, file, user_agent="user_agent")