Ejemplo n.º 1
0
def test_extract_wav(mocked_subprocess: MagicMock,
                     download_pipeline: DownloadPipeline) -> None:
    """Test wav extraction in a subprocess."""
    path = Path("test.mp4")
    args = [
        "ffmpeg", "-i", "test.mp4", "-f", "wav", "-ar", "16000", "-ac", "1",
        "test.wav"
    ]
    download_pipeline.extract_wav(path)
    mocked_subprocess.assert_called_once_with(args,
                                              capture_output=True,
                                              check=True,
                                              text=True)
Ejemplo n.º 2
0
def test_downloads_form_path(
    mock_downloads_path: MagicMock,
    download_pipeline: DownloadPipeline,
) -> None:
    """Check path forming separately."""
    assert str(download_pipeline.form_path(0, 0,
                                           "test")) == "tests/testing.test"
    assert len(download_pipeline.errors) == 0
    mock_downloads_path.assert_called_once()

    assert download_pipeline.form_path(0, 0, "test") is None
    assert download_pipeline.errors[
        0] == "File tests/testing.test exists, will not overwrite."
    assert mock_downloads_path.call_count == 2
Ejemplo n.º 3
0
def test_download_video(
    mocked_get: MagicMock,
    mocked_atomic_write: MagicMock,
    mocked_copyfileobj: MagicMock,
    mocked_extract_wav: MagicMock,
    download_pipeline: DownloadPipeline,
) -> None:
    """Test single video download."""
    path = Path("test_path")
    url = "https://eduskunta.videosync.fi/api/v1/events/abc012345/video/download"
    download_pipeline.download_video(path, **{"index": "abc012345"})
    mocked_get.assert_called_once_with(url, stream=True)
    mocked_atomic_write.assert_called_once_with(path, mode="wb")
    mocked_copyfileobj.assert_called_once()
    mocked_extract_wav.assert_called_once_with(path)
Ejemplo n.º 4
0
def test_download_video_exception(
    mocked_get: MagicMock,
    mocked_atomic_write: MagicMock,
    mocked_extract_wav: MagicMock,
    mock_shutil_error: MagicMock,
    download_pipeline: DownloadPipeline,
) -> None:
    """Test error capture in video download."""
    path = Path("test_path")
    url = "https://eduskunta.videosync.fi/api/v1/events/abc012345/video/download"
    download_pipeline.download_video(path, **{"index": "abc012345"})
    mocked_get.assert_called_once_with(url, stream=True)
    mocked_atomic_write.assert_called_once_with(path, mode="wb")
    mock_shutil_error.assert_called_once()
    mocked_extract_wav.assert_not_called()
    assert download_pipeline.errors[
        0] == f"Video download failed for test_path from {url}."
Ejemplo n.º 5
0
def test_extract_wav_errors(mocked_cleanup: MagicMock,
                            mock_subprocess_run: MagicMock,
                            download_pipeline: DownloadPipeline) -> None:
    """Test subprocess errors in extracting wavs."""
    path = Path("test.mp4")
    args = [
        "ffmpeg", "-i", "test.mp4", "-f", "wav", "-ar", "16000", "-ac", "1",
        "test.wav"
    ]
    download_pipeline.extract_wav(path)
    mock_subprocess_run.assert_called_once_with(args,
                                                capture_output=True,
                                                check=True,
                                                text=True)
    mocked_cleanup.assert_called_once_with(
        "ffmpeg returned non-zero exit status 1. Stderr:\n failed",
        [Path("test.wav"), path])
    download_pipeline.extract_wav(path)
    mock_subprocess_run.assert_called_with(args,
                                           capture_output=True,
                                           check=True,
                                           text=True)
    mocked_cleanup.assert_called_with("Caught keyboard interrupt.",
                                      [Path("test.wav"), path])
Ejemplo n.º 6
0
def test_cleanup_subprocess(mocked_unlink: MagicMock,
                            download_pipeline: DownloadPipeline) -> None:
    """Test clean up after a subprocess error."""
    download_pipeline.cleanup_subprocess("failed", [Path("one"), Path("two")])
    mocked_unlink.assert_called_with(missing_ok=True)
    assert mocked_unlink.call_count == 2
Ejemplo n.º 7
0
def download_pipeline(logger: Logger) -> DownloadPipeline:
    """Initialize DownloadPipeline with logger."""
    pipeline = DownloadPipeline(logger)
    return pipeline