예제 #1
0
def test_pillow_format(test_images, tmp_path):

    fnamebase = str(tmp_path / "test")

    # Format - Pillow is the default!
    F = imageio.formats["PNG"]
    assert F.name == "PNG-PIL"

    # Reader
    R = F.get_reader(core.Request(test_images / "chelsea.png", "ri"))
    assert len(R) == 1
    assert isinstance(R.get_meta_data(), dict)
    assert isinstance(R.get_meta_data(0), dict)

    with pytest.raises(IndexError):
        R.get_data(2)

    with pytest.raises(IndexError):
        R.get_meta_data(2)

    # Writer
    W = F.get_writer(core.Request(fnamebase + ".png", "wi"))
    W.append_data(im0)
    W.set_meta_data({"foo": 3})
    with pytest.raises(RuntimeError):
        W.append_data(im0)
예제 #2
0
def test_select():

    fname1 = get_remote_file("images/cockatoo.mp4", test_dir)

    F = imageio.formats["avbin"]
    assert F.name == "AVBIN"

    assert F.can_read(core.Request(fname1, "rI"))
    assert not F.can_write(core.Request(fname1, "wI"))
    assert not F.can_read(core.Request(fname1, "ri"))
    assert not F.can_read(core.Request(fname1, "rv"))
예제 #3
0
def test_select():

    fname1 = get_remote_file('images/cockatoo.mp4', test_dir)

    F = imageio.formats['avbin']
    assert F.name == 'AVBIN'

    assert F.can_read(core.Request(fname1, 'rI'))
    assert not F.can_write(core.Request(fname1, 'wI'))
    assert not F.can_read(core.Request(fname1, 'ri'))
    assert not F.can_read(core.Request(fname1, 'rv'))
예제 #4
0
def test_invalid():
    fname1 = get_remote_file('images/stent.swf', test_dir)
    fname2 = fname1[:-4] + '.invalid.swf'
    
    # Empty file
    with open(fname2, 'wb'):
        pass
    assert not imageio.formats.search_read_format(core.Request(fname2, 'rI'))
    raises(IOError, imageio.mimread, fname2, 'swf')
    
    # File with BS data
    with open(fname2, 'wb') as f:
        f.write(b'x'*100)
    assert not imageio.formats.search_read_format(core.Request(fname2, 'rI'))
    raises(IOError, imageio.mimread, fname2, 'swf')
예제 #5
0
파일: test_dicom.py 프로젝트: yyrjl/imageio
def test_read_empty_dir():
    # Create an empty dir
    empty = os.path.join(test_dir, "empty_dir")
    if not os.path.isdir(empty):
        os.mkdir(empty)

    # Test that no format is found, but no error is raised
    request = core.Request(empty, "ri")
    assert imageio.formats.search_read_format(request) is None
예제 #6
0
def test_freeimage_format():

    # Format
    F = imageio.formats['PNG']

    # Reader
    R = F.get_reader(core.Request('chelsea.png', 'ri'))
    assert len(R) == 1
    assert isinstance(R.get_meta_data(), dict)
    assert isinstance(R.get_meta_data(0), dict)
    raises(IndexError, R.get_data, 2)
    raises(IndexError, R.get_meta_data, 2)

    # Writer
    W = F.get_writer(core.Request(fnamebase + '.png', 'wi'))
    W.append_data(im0)
    W.set_meta_data({'foo': 3})
    raises(RuntimeError, W.append_data, im0)
예제 #7
0
def test_invalid(test_images):

    fname1 = test_images / "stent.swf"
    fname2 = fname1.with_suffix(".invalid.swf")

    # Empty file
    with open(fname2, "wb"):
        pass
    assert not imageio.formats.search_read_format(core.Request(fname2, "rI"))
    with pytest.raises(RuntimeError):
        imageio.mimread(fname2, "swf")

    # File with BS data
    with open(fname2, "wb") as f:
        f.write(b"x" * 100)
    assert not imageio.formats.search_read_format(core.Request(fname2, "rI"))
    with pytest.raises(RuntimeError):
        imageio.mimread(fname2, "swf")
예제 #8
0
def test_invalid():

    need_internet()

    fname1 = get_remote_file("images/stent.swf", test_dir)
    fname2 = fname1[:-4] + ".invalid.swf"

    # Empty file
    with open(fname2, "wb"):
        pass
    assert not imageio.formats.search_read_format(core.Request(fname2, "rI"))
    raises(IOError, imageio.mimread, fname2, "swf")

    # File with BS data
    with open(fname2, "wb") as f:
        f.write(b"x" * 100)
    assert not imageio.formats.search_read_format(core.Request(fname2, "rI"))
    raises(IOError, imageio.mimread, fname2, "swf")
예제 #9
0
def test_pillow_format():

    # Format - Pillow is the default!
    F = imageio.formats['PNG']
    assert F.name == 'PNG-PIL'

    # Reader
    R = F.get_reader(core.Request('imageio:chelsea.png', 'ri'))
    assert len(R) == 1
    assert isinstance(R.get_meta_data(), dict)
    assert isinstance(R.get_meta_data(0), dict)
    assert raises(IndexError, R.get_data, 2)
    assert raises(IndexError, R.get_meta_data, 2)

    # Writer
    W = F.get_writer(core.Request(fnamebase + '.png', 'wi'))
    W.append_data(im0)
    W.set_meta_data({'foo': 3})
    assert raises(RuntimeError, W.append_data, im0)
예제 #10
0
def test_pillow_format():

    # Format - Pillow is the default!
    F = imageio.formats["PNG"]
    assert F.name == "PNG-PIL"

    # Reader
    R = F.get_reader(core.Request("imageio:chelsea.png", "ri"))
    assert len(R) == 1
    assert isinstance(R.get_meta_data(), dict)
    assert isinstance(R.get_meta_data(0), dict)
    assert raises(IndexError, R.get_data, 2)
    assert raises(IndexError, R.get_meta_data, 2)

    # Writer
    W = F.get_writer(core.Request(fnamebase + ".png", "wi"))
    W.append_data(im0)
    W.set_meta_data({"foo": 3})
    assert raises(RuntimeError, W.append_data, im0)
예제 #11
0
def test_selection(test_images, tmp_path, examples):

    dname1, dname2, fname1, fname2 = examples

    # Test that DICOM can examine file
    F = imageio.formats.search_read_format(core.Request(fname1, "ri"))
    assert F.name == "DICOM"
    assert isinstance(F, type(imageio.formats["DICOM"]))

    # Test that we cannot save
    request = core.Request(tmp_path / "test.dcm", "wi")
    assert not F.can_write(request)

    # Test fail on wrong file
    fname2 = fname1 + ".fake"
    bb = open(fname1, "rb").read()
    bb = bb[:128] + b"XXXX" + bb[132:]
    open(fname2, "wb").write(bb)
    with pytest.raises(Exception):
        F.get_reader(core.Request(fname2, "ri"))

    # Test special files with other formats
    im = imageio.imread(test_images / "dicom_file01.dcm")
    assert im.shape == (512, 512)
    im = imageio.imread(test_images / "dicom_file03.dcm")
    assert im.shape == (512, 512)
    im = imageio.imread(test_images / "dicom_file04.dcm")
    assert im.shape == (512, 512)

    # Expected fails
    fname = test_images / "dicom_file90.dcm"
    with pytest.raises(RuntimeError):
        imageio.imread(fname)  # 1.2.840.10008.1.2.4.91
    fname = test_images / "dicom_file91.dcm"
    with pytest.raises(RuntimeError):
        imageio.imread(fname)  # not pixel data

    # This one *should* work, but does not, see issue #18
    try:
        imageio.imread(test_images / "dicom_file02.dcm")
    except Exception:
        pass
예제 #12
0
def test_freeimage_format(setup_library, test_images, tmp_path):

    fnamebase = str(tmp_path / "test")

    # Format
    F = imageio.formats["PNG-FI"]
    assert F.name == "PNG-FI"

    # Reader
    R = F.get_reader(core.Request(test_images / "chelsea.png", "ri"))
    assert len(R) == 1
    assert isinstance(R.get_meta_data(), dict)
    assert isinstance(R.get_meta_data(0), dict)
    raises(IndexError, R.get_data, 2)
    raises(IndexError, R.get_meta_data, 2)

    # Writer
    W = F.get_writer(core.Request(fnamebase + ".png", "wi"))
    W.append_data(im0)
    W.set_meta_data({"foo": 3})
    raises(RuntimeError, W.append_data, im0)
예제 #13
0
파일: test_dicom.py 프로젝트: yyrjl/imageio
def test_selection():

    dname1, dname2, fname1, fname2 = _prepare()

    # Test that DICOM can examine file
    F = imageio.formats.search_read_format(core.Request(fname1, "ri"))
    assert F.name == "DICOM"
    assert F is imageio.formats["DICOM"]

    # Test that we cannot save
    request = core.Request(os.path.join(test_dir, "test.dcm"), "wi")
    assert not F.can_write(request)

    # Test fail on wrong file
    fname2 = fname1 + ".fake"
    bb = open(fname1, "rb").read()
    bb = bb[:128] + b"XXXX" + bb[132:]
    open(fname2, "wb").write(bb)
    raises(Exception, F.get_reader, core.Request(fname2, "ri"))

    # Test special files with other formats
    im = imageio.imread(get_remote_file("images/dicom_file01.dcm"))
    assert im.shape == (512, 512)
    im = imageio.imread(get_remote_file("images/dicom_file03.dcm"))
    assert im.shape == (512, 512)
    im = imageio.imread(get_remote_file("images/dicom_file04.dcm"))
    assert im.shape == (512, 512)

    # Expected fails
    fname = get_remote_file("images/dicom_file90.dcm")
    raises(RuntimeError, imageio.imread, fname)  # 1.2.840.10008.1.2.4.91
    fname = get_remote_file("images/dicom_file91.dcm")
    raises(RuntimeError, imageio.imread, fname)  # not pixel data

    # This one *should* work, but does not, see issue #18
    try:
        imageio.imread(get_remote_file("images/dicom_file02.dcm"))
    except Exception:
        pass
예제 #14
0
def test_select():

    F = imageio.formats['bsdf']
    assert F.name == 'BSDF'

    need_internet()

    fname1 = get_remote_file('images/chelsea.bsdf', test_dir)

    assert F.can_read(core.Request(fname1, 'rI'))
    assert F.can_write(core.Request(fname1, 'wI'))
    assert F.can_read(core.Request(fname1, 'ri'))
    assert F.can_read(core.Request(fname1, 'rv'))

    assert imageio.formats['.bsdf'] is F
    assert imageio.formats.search_write_format(core.Request(fname1, 'wi')) is F
    assert imageio.formats.search_read_format(core.Request(fname1, 'ri')) is F
    assert imageio.formats.search_write_format(core.Request(fname1, 'wI')) is F
    assert imageio.formats.search_read_format(core.Request(fname1, 'rI')) is F
예제 #15
0
def test_select():

    F = imageio.formats["bsdf"]
    assert F.name == "BSDF"

    need_internet()

    fname1 = get_remote_file("images/chelsea.bsdf", test_dir)

    assert F.can_read(core.Request(fname1, "rI"))
    assert F.can_write(core.Request(fname1, "wI"))
    assert F.can_read(core.Request(fname1, "ri"))
    assert F.can_read(core.Request(fname1, "rv"))

    assert imageio.formats[".bsdf"] is F
    assert imageio.formats.search_write_format(core.Request(fname1, "wi")) is F
    assert imageio.formats.search_read_format(core.Request(fname1, "ri")) is F
    assert imageio.formats.search_write_format(core.Request(fname1, "wI")) is F
    assert imageio.formats.search_read_format(core.Request(fname1, "rI")) is F
예제 #16
0
def test_select(test_images):

    F = imageio.formats["BSDF"]
    assert F.name == "BSDF"

    fname1 = test_images / "chelsea.bsdf"

    assert F.can_read(core.Request(fname1, "rI"))
    assert F.can_write(core.Request(fname1, "wI"))
    assert F.can_read(core.Request(fname1, "ri"))
    assert F.can_read(core.Request(fname1, "rv"))

    assert type(imageio.formats[".bsdf"]) is type(F)
    assert type(imageio.formats.search_write_format(core.Request(
        fname1, "wi"))) is type(F)
    assert type(imageio.formats.search_read_format(core.Request(
        fname1, "ri"))) is type(F)
    assert type(imageio.formats.search_write_format(core.Request(
        fname1, "wI"))) is type(F)
    assert type(imageio.formats.search_read_format(core.Request(
        fname1, "rI"))) is type(F)
예제 #17
0
def test_select():

    fname1 = get_remote_file('images/cockatoo.mp4', test_dir)

    F = imageio.formats['ffmpeg']
    assert F.name == 'FFMPEG'

    assert F.can_read(core.Request(fname1, 'rI'))
    assert F.can_write(core.Request(fname1, 'wI'))
    assert not F.can_read(core.Request(fname1, 'ri'))
    assert not F.can_read(core.Request(fname1, 'rv'))

    # ffmpeg is default
    assert imageio.formats['.mp4'] is F
    assert imageio.formats.search_write_format(core.Request(fname1, 'wI')) is F
    assert imageio.formats.search_read_format(core.Request(fname1, 'rI')) is F
예제 #18
0
def test_select():

    fname1 = get_remote_file("images/cockatoo.mp4", test_dir)

    F = imageio.formats["ffmpeg"]
    assert F.name == "FFMPEG"

    assert F.can_read(core.Request(fname1, "rI"))
    assert F.can_write(core.Request(fname1, "wI"))
    assert not F.can_read(core.Request(fname1, "ri"))
    assert not F.can_read(core.Request(fname1, "rv"))

    # ffmpeg is default
    assert imageio.formats[".mp4"] is F
    assert imageio.formats.search_write_format(core.Request(fname1, "wI")) is F
    assert imageio.formats.search_read_format(core.Request(fname1, "rI")) is F
예제 #19
0
def test_select(test_images):

    fname1 = test_images / "cockatoo.mp4"

    F = imageio.formats["ffmpeg"]
    assert F.name == "FFMPEG"

    assert F.can_read(core.Request(fname1, "rI"))
    assert F.can_write(core.Request(fname1, "wI"))
    assert not F.can_read(core.Request(fname1, "ri"))
    assert not F.can_read(core.Request(fname1, "rv"))

    # ffmpeg is default
    assert type(imageio.formats[".mp4"]) is type(F)
    assert type(imageio.formats.search_write_format(core.Request(
        fname1, "wI"))) is type(F)
    assert type(imageio.formats.search_read_format(core.Request(
        fname1, "rI"))) is type(F)
예제 #20
0
def test_read_empty_dir(tmp_path):
    # Test that no format is found, but no error is raised
    request = core.Request(tmp_path, "ri")
    assert imageio.formats.search_read_format(request) is None