def test_frame_input_close(): with mock.patch.object(fs.logging, "debug") as mock_debug: istream = fs.FrameInputStream("test_path") istream.close() istream = fs.FrameInputStream("test_path", num_frames=10) istream.close() assert(mock_debug.call_count == 2)
def test_frame_input_context_manager(): with mock.patch.object(fs.traceback, "print_tb") as mock_tb: with pytest.raises(OSError): with fs.FrameInputStream("test_path") as istream: assert(istream.movie_path == "test_path") raise OSError() mock_tb.assert_called_once() with fs.FrameInputStream("test_path") as istream: istream._num_frames = 10 istream.frames_read = 10
def test_frame_input_slice(start, stop, step): mock_cb = mock.MagicMock() istream = fs.FrameInputStream("test_path", num_frames=DEFAULT_FRAMES, process_frame_cb=mock_cb) with mock.patch.object(istream, "_get_frame", new=lambda a: a): count = 0 for x in istream: count += 1 assert count == DEFAULT_FRAMES assert mock_cb.call_count == DEFAULT_FRAMES with mock.patch.object(istream, "_seek_frame", new=lambda b: b): mock_cb.reset_mock() x = istream[5] mock_cb.assert_called_once_with(5) mock_cb.reset_mock() x = istream[-20] mock_cb.assert_called_once_with(DEFAULT_FRAMES-20) with mock.patch.object(istream, "_seek_frame", new=lambda b: b): mock_cb.reset_mock() for x in istream[start:stop:step]: pass rstop = stop if stop is not None else DEFAULT_FRAMES rstart = start if start is not None else 0 rstep = step if step is not None else 1 expected = [mock.call(x) for x in range(rstart, rstop, rstep)] mock_cb.assert_has_calls(expected)
def test_frame_input_slice_errors(): mock_cb = mock.MagicMock() istream = fs.FrameInputStream("test_path", num_frames=DEFAULT_FRAMES, process_frame_cb=mock_cb) with pytest.raises(NotImplementedError): istream._get_frame(20) with pytest.raises(NotImplementedError): istream._seek_frame(20) with pytest.raises(ValueError): for x in istream[6:10:0]: pass with pytest.raises(KeyError): istream["invalid"] with pytest.raises(IndexError): istream[DEFAULT_FRAMES] with pytest.raises(IndexError): istream[-DEFAULT_FRAMES-1]
def test_frame_input_init(): istream = fs.FrameInputStream("test_path") assert(istream.movie_path == "test_path") assert(istream.num_frames == 0) with pytest.raises(NotImplementedError): istream.frame_shape