How to use the imageio.testing.need_internet function in imageio

To help you get started, we’ve selected a few imageio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imageio / imageio / tests / test_pillow.py View on Github external
def test_inside_zipfile():
    need_internet()

    fname = os.path.join(test_dir, "pillowtest.zip")
    with ZipFile(fname, "w") as z:
        z.writestr("x.png", open(get_remote_file("images/chelsea.png"), "rb").read())
        z.writestr("x.jpg", open(get_remote_file("images/rommel.jpg"), "rb").read())

    for name in ("x.png", "x.jpg"):
        imageio.imread(fname + "/" + name)
github imageio / imageio / tests / test_dicom.py View on Github external
def _prepare():
    """ Create two dirs, one with one dataset and one with two datasets
    """
    need_internet()

    global _prepared
    if _prepared and os.path.isfile(_prepared[2]):
        return _prepared
    # Prepare sources
    fname1 = get_remote_file("images/dicom_sample1.zip")
    fname2 = get_remote_file("images/dicom_sample2.zip")
    dname1 = os.path.join(test_dir, "dicom_sample1")
    dname2 = os.path.join(test_dir, "dicom_sample2")
    # Extract zipfiles
    z = ZipFile(fname1)
    z.extractall(dname1)
    z.extractall(dname2)
    z = ZipFile(fname2)
    z.extractall(dname2)
    # Get arbitrary file names
github imageio / imageio / tests / test_avbin.py View on Github external
def test_read_format():
    need_internet()

    # Set videofomat
    # Also set skipempty, so we can test mean
    reader = imageio.read(
        get_remote_file("images/cockatoo.mp4"),
        "avbin",
        videoformat="mp4",
        skipempty=True,
    )
    for i in range(10):
        im = reader.get_next_data()
        assert im.shape == (720, 1280, 3)
        assert 100 < mean(im) < 115
github imageio / imageio / tests / test_pillow.py View on Github external
def test_bmp():
    need_internet()
    fname = get_remote_file("images/scribble_P_RGB.bmp", test_dir)

    imageio.imread(fname)
    imageio.imread(fname, pilmode="RGB")
    imageio.imread(fname, pilmode="RGBA")
github imageio / imageio / tests / test_pillow.py View on Github external
def test_png_remote():
    # issue #202
    need_internet()
    im = imageio.imread(
        "https://raw.githubusercontent.com/imageio/"
        + "imageio-binaries/master/images/astronaut.png"
    )
    assert im.shape == (512, 512, 3)
github imageio / imageio / tests / test_freeimage.py View on Github external
def test_jpg_more():
    need_internet()

    # Test broken JPEG
    fname = fnamebase + "_broken.jpg"
    open(fname, "wb").write(b"this is not an image")
    raises(Exception, imageio.imread, fname)
    #
    bb = imageio.imsave(imageio.RETURN_BYTES, get_ref_im(3, 0, 0), "JPEG")
    with open(fname, "wb") as f:
        f.write(bb[:400])
        f.write(b" ")
        f.write(bb[400:])
    raises(Exception, imageio.imread, fname)

    # Test EXIF stuff
    fname = get_remote_file("images/rommel.jpg")
    im = imageio.imread(fname)
github imageio / imageio / tests / test_swf.py View on Github external
def test_reading_saving():

    need_internet()

    fname1 = get_remote_file("images/stent.swf", test_dir)
    fname2 = fname1[:-4] + ".out.swf"
    fname3 = fname1[:-4] + ".compressed.swf"
    fname4 = fname1[:-4] + ".out2.swf"

    # Read
    R = imageio.read(fname1)
    assert len(R) == 10
    assert R.get_meta_data() == {}  # always empty dict
    ims1 = []
    for im in R:
        assert im.shape == (657, 451, 4)
        assert mean(im) > 0
        ims1.append(im)
    # Seek
github imageio / imageio / tests / test_avbin.py View on Github external
def test_reader_more():
    need_internet()

    fname1 = get_remote_file("images/cockatoo.mp4")
    fname3 = fname1[:-4] + ".stub.mp4"

    # Get meta data
    R = imageio.read(fname1, "avbin", loop=True)
    meta = R.get_meta_data()
    assert isinstance(meta, dict)
    assert "fps" in meta
    R.close()

    # Read all frames and test length
    R = imageio.read(get_remote_file("images/realshort.mp4"), "avbin")
    count = 0
    while True:
        try:
github imageio / imageio / tests / test_tifffile.py View on Github external
def test_tifffile_reading_writing():
    """ Test reading and saving tiff """
    
    need_internet()  # We keep a test image in the imageio-binary repo
    
    im2 = np.ones((10, 10, 3), np.uint8) * 2

    filename1 = os.path.join(test_dir, 'test_tiff.tiff')

    # One image
    imageio.imsave(filename1, im2)
    im = imageio.imread(filename1)
    ims = imageio.mimread(filename1)
    assert im.shape == im2.shape
    assert (im == im2).all()
    assert len(ims) == 1
    
    # Multiple images
    imageio.mimsave(filename1, [im2, im2, im2])
    im = imageio.imread(filename1)