예제 #1
0
def test_convert_gif(tmpdir, moviename, remove_movie, gif_palette, gifname,
                     gif_framerate):
    m = tmpdir.join(moviename)
    mpath = m.strpath
    g = tmpdir.join(gifname)
    gpath = g.strpath

    da = test_dataarray()
    mov = Movie(da)
    mov.save_frames(tmpdir)

    write_movie(tmpdir, moviename)

    convert_gif(
        mpath,
        gpath=gpath,
        gif_palette=gif_palette,
        remove_movie=remove_movie,
        gif_framerate=gif_framerate,
    )

    if remove_movie:
        assert ~m.exists()
    else:
        assert m.exists()

    assert g.exists()
    fps = 1000 / Image.open(g.strpath).info["duration"]
    assert np.ceil(fps) == gif_framerate
예제 #2
0
def test_write_movie(tmpdir, moviename, remove_frames, framerate,
                     ffmpeg_options):

    frame_pattern = "frame_%05d.png"  # the default
    m = tmpdir.join(moviename)
    da = test_dataarray()
    mov = Movie(da)
    mov.save_frames(tmpdir)
    filenames = [tmpdir.join(frame_pattern % ff) for ff in range(len(da.time))]
    write_movie(
        tmpdir,
        moviename,
        remove_frames=remove_frames,
        framerate=framerate,
        ffmpeg_options=ffmpeg_options,
    )

    if remove_frames:
        assert all([~fn.exists() for fn in filenames])
    else:
        assert all([fn.exists() for fn in filenames])
    assert m.exists()  # could test more stuff here I guess.
    video = cv2.VideoCapture(m.strpath)
    fps = video.get(cv2.CAP_PROP_FPS)
    assert fps == framerate
    total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
    assert total_frames == len(da.time)
예제 #3
0
def test_plotfunc_kwargs(tmpdir):
    """Test if kwargs are properly
    propagated to the  plotfunction"""
    def plotfunc(ds, fig, tt, framedim="time", test1=None, **kwargs):
        if test1 is None:
            raise RuntimeError("test1 cannot be None")

    da = test_dataarray()
    mov = Movie(da, plotfunc=plotfunc, test1=3)
    mov.preview(0)
    mov.save_frames(tmpdir)
예제 #4
0
def test_plotfunc_kwargs_xfail(tmpdir):
    pytest.xfail("if **kwargs is not in the function signature \
        and the input is checked, this should error out.")

    def plotfunc(ds, fig, tt, test1=None):
        if test1 is None:
            raise RuntimeError("test1 cannot be None")

    da = test_dataarray()
    mov = Movie(da, plotfunc=plotfunc, test1=3)
    mov.preview(0)
    mov.save_frames(tmpdir)
예제 #5
0
def test_movie_write_movie(tmpdir, moviename, remove_frames):

    frame_pattern = "frame_%05d.png"  # the default
    m = tmpdir.join(moviename)
    mpath = m.strpath

    da = test_dataarray()
    mov = Movie(da)
    mov.save_frames(tmpdir)
    filenames = [tmpdir.join(frame_pattern % ff) for ff in range(len(da.time))]
    write_movie(tmpdir, moviename, remove_frames=remove_frames)

    if remove_frames:
        assert all([~fn.exists() for fn in filenames])
    else:
        assert all([fn.exists() for fn in filenames])
    assert m.exists()  # could test more stuff here I guess.
예제 #6
0
def test_convert_gif(tmpdir, moviename, remove_movie, gif_palette, gifname):
    m = tmpdir.join(moviename)
    mpath = m.strpath
    g = tmpdir.join(gifname)
    gpath = g.strpath

    da = test_dataarray()
    mov = Movie(da)
    mov.save_frames(tmpdir)

    write_movie(tmpdir, moviename)

    convert_gif(mpath,
                gpath=gpath,
                gif_palette=gif_palette,
                remove_movie=remove_movie)

    if remove_movie:
        assert ~m.exists()
    else:
        assert m.exists()

    assert g.exists()
예제 #7
0
def test_movie_save_frames(tmpdir, frame_pattern):
    da = test_dataarray()
    mov = Movie(da, frame_pattern=frame_pattern)
    mov.save_frames(tmpdir)
    filenames = [tmpdir.join(frame_pattern % ff) for ff in range(len(da.time))]
    assert all([fn.exists() for fn in filenames])