def test_cv_input_iter(movie):
    mock_cb = mock.MagicMock()
    istream = fs.CvInputStream(movie, process_frame_cb=mock_cb)
    count = 0
    for x in istream:
        count += 1
    assert count == DEFAULT_CV_FRAMES
    assert mock_cb.call_count == DEFAULT_CV_FRAMES
    mock_cb.reset_mock()
    for x in istream[5:10]:
        pass
    for i, x in enumerate(range(5, 10)):
        assert(np.all(np.abs(image(value=x) -
                             mock_cb.mock_calls[i][1][0][:, :, 0]) < 2))
    mock_cb.reset_mock()
    for x in istream[2:18:2]:
        pass
    for i, x in enumerate(range(2, 18, 2)):
        assert(np.all(np.abs(image(value=x) -
                             mock_cb.mock_calls[i][1][0][:, :, 0]) < 2))
    mock_cb.reset_mock()
    for x in istream[18:2:-2]:
        pass
    for i, x in enumerate(range(18, 2, -2)):
        assert(np.all(np.abs(image(value=x) -
                             mock_cb.mock_calls[i][1][0][:, :, 0]) < 2))
def test_cv_input_open(movie):
    istream = fs.CvInputStream(movie)
    istream.open()
    with pytest.raises(IOError):
        istream.open()
    istream._error()
    assert(istream.cap is None)
def test_cv_output_write(outfile):
    ostream = fs.CvOutputStream(outfile, (200, 200), is_color=False,
                                fourcc=FOURCC)
    ostream.write(image())
    ostream.write(image())
    ostream.close()
    check = fs.CvInputStream(outfile)
    assert(check.num_frames == 2)
def test_cv_input_ioerrors(movie):
    istream = fs.CvInputStream(movie)
    with pytest.raises(IOError):
        istream._seek_frame(10)
    with pytest.raises(IOError):
        istream._get_frame(10)
def test_cv_input_close(movie):
    istream = fs.CvInputStream(movie)
    istream.close()
def test_cv_input_frame_shape(movie):
    istream = fs.CvInputStream(movie)
    assert(istream.frame_shape == (200, 200))
    assert(istream.frame_shape == (200, 200))  # using cached value
def test_cv_input_num_frames(movie):
    istream = fs.CvInputStream(movie)
    assert(istream.num_frames == DEFAULT_CV_FRAMES)
    assert(istream.num_frames == DEFAULT_CV_FRAMES)  # using cached value